From 179d8067685bca50e4421697c3c35b5d21f1e5e6 Mon Sep 17 00:00:00 2001 From: ufec Date: Mon, 4 Sep 2023 19:33:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(fireShortcutKey):=20=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Cherry.js | 4 ++-- src/utils/regexp.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cherry.js b/src/Cherry.js index c8c97ba2..0a27c525 100644 --- a/src/Cherry.js +++ b/src/Cherry.js @@ -607,9 +607,9 @@ export default class Cherry extends CherryStatic { const lineContent = this.editor.editor.getLine(cursor.line); // shift + tab 已经被绑定为缩进,所以这里不做处理 if (!evt.shiftKey && evt.key === 'Tab' && LIST_CONTENT.test(lineContent)) { - evt.preventDefault(); // 每按一次Tab,如果当前光标在行首或者行尾,就在行首加一个\t - if (cursor.ch === 0 || cursor.ch === lineContent.length) { + if (cursor.ch === 0 || cursor.ch === lineContent.length || cursor.ch === lineContent.length + 1) { + evt.preventDefault(); this.editor.editor.setSelection({ line: cursor.line, ch: 0 }, { line: cursor.line, ch: lineContent.length }); this.editor.editor.replaceSelection(`\t${lineContent}`, 'around'); const newCursor = this.editor.editor.getCursor(); diff --git a/src/utils/regexp.js b/src/utils/regexp.js index 21f3b8b5..d6ebdc00 100644 --- a/src/utils/regexp.js +++ b/src/utils/regexp.js @@ -112,7 +112,7 @@ export const URL_NO_SLASH = new RegExp(`^${URL_INLINE_NO_SLASH.source}$`); export const URL = new RegExp(`^${URL_INLINE.source}$`); // 正则结果[全部, 判定符之前的空格或者tab, 判定符, checkbox内容(没有就是undefined), 列表内容] -export const LIST_CONTENT = /([ \t]*)([*+-][ ](\[[ x]\])?|[a-z0-9I一二三四五六七八九十零]+\.)([^\r\n]+)/; +export const LIST_CONTENT = /([ \t]*)([*+-][ ](\[[ x]\])?|[a-z0-9I一二三四五六七八九十零]+\.)([^\r\n]*)/; export function getTableRule(merge = false) { // ^(\|[^\n]+\|\r?\n)((?:\|:?[-]+:?)+\|)(\n(?:\|[^\n]+\|\r?\n?)*)?$