Skip to content

Commit 1d1807c

Browse files
committed
fix: change list logic
1 parent 6558f04 commit 1d1807c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

custom/MarkdownEditor.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,20 @@ const applyFormat = (type: string) => {
569569
const handleBlockFormat = (formatType: string) => {
570570
const prefixMap: Record<string, string> = { h2: '## ', h3: '### ', ul: '* ' };
571571
const edits: monaco.editor.IIdentifiedSingleEditOperation[] = [];
572-
let olCounter = 1;
573572
574573
for (let i = selection.startLineNumber; i <= selection.endLineNumber; i++) {
575574
const line = model!.getLineContent(i);
576-
const targetPrefix = formatType === 'ol' ? `${olCounter++}. ` : prefixMap[formatType];
575+
const targetPrefix = formatType === 'ol' ? `${i - selection.startLineNumber + 1}. ` : prefixMap[formatType];
577576
const match = line.match(/^(#{1,6}\s+|[*+-]\s+|\d+[.)]\s+)/);
578577
579578
if (match) {
580579
const existing = match[0];
581-
const newText = (existing === targetPrefix) ? '' : targetPrefix;
582-
edits.push({ range: new monaco.Range(i, 1, i, existing.length), text: newText, forceMoveMarkers: true });
580+
if (existing.trim() === targetPrefix.trim()) {
581+
edits.push({ range: new monaco.Range(i, 1, i, existing.length + 1), text: '', forceMoveMarkers: true
582+
});
583+
} else {
584+
edits.push({ range: new monaco.Range(i, 1, i, existing.length + 1), text: targetPrefix, forceMoveMarkers: true });
585+
}
583586
} else {
584587
edits.push({ range: new monaco.Range(i, 1, i, 1), text: targetPrefix, forceMoveMarkers: true });
585588
}

0 commit comments

Comments
 (0)