Skip to content

Commit 9303ab1

Browse files
committed
fix: add logic for list
1 parent 7282a7b commit 9303ab1

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

custom/MarkdownEditor.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,24 @@ onMounted(async () => {
653653
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyU, () => {
654654
toggleWrapSmart(editor!, '<u>', '</u>');
655655
});
656+
editor.addCommand(monaco.KeyCode.Enter, () => {
657+
const pos = editor!.getPosition()!;
658+
const line = model!.getLineContent(pos.lineNumber);
659+
const match = line.match(/^(\s*)([*+-]|\d+\.)\s+/);
660+
661+
if (match) {
662+
if (line.trim() === match[2].trim()) {
663+
const range = new monaco.Range(pos.lineNumber, 1, pos.lineNumber, line.length + 1);
664+
editor!.executeEdits('exit-list', [{ range, text: '', forceMoveMarkers: true }]);
665+
} else {
666+
const isNum = match[2].includes('.');
667+
const next = isNum ? `${parseInt(match[2]) + 1}. ` : `${match[2]} `;
668+
editor!.trigger('keyboard', 'type', { text: `\n${match[1]}${next}` });
669+
}
670+
} else {
671+
editor!.trigger('keyboard', 'type', { text: '\n' });
672+
}
673+
}, 'editorTextFocus');
656674
657675
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK, () => {
658676
const selection = editor!.getSelection();

0 commit comments

Comments
 (0)