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?)*)?$