Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Dec 2, 2024
1 parent 362f909 commit 1cb77e8
Showing 1 changed file with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,27 @@ export class PostingMarkdownEditorComponent implements OnInit, ControlValueAcces

const editor = this.markdownEditor.monacoEditor;
if (editor) {
if (editor) {
editor.onDidChangeModelContent((event: { changes: string | any[] }) => {
const position = editor.getPosition();
if (!position) {
return;
}

const model = editor.getModel();
if (!model) {
return;
}

const lineContent = model.getLineContent(position.lineNumber).trimStart();
const hasPrefix = lineContent.startsWith('- ') || /^\s*1\. /.test(lineContent);
if (hasPrefix && event.changes.length === 1 && (event.changes[0].text.startsWith('- ') || event.changes[0].text.startsWith('1. '))) {
return;
}

if (hasPrefix) {
this.handleKeyDown(model, position.lineNumber);
}
});
}
editor.onDidChangeModelContent((event: { changes: string | any[] }) => {
const position = editor.getPosition();
if (!position) {
return;
}

const model = editor.getModel();
if (!model) {
return;
}

const lineContent = model.getLineContent(position.lineNumber).trimStart();
const hasPrefix = lineContent.startsWith('- ') || /^\s*1\. /.test(lineContent);
if (hasPrefix && event.changes.length === 1 && (event.changes[0].text.startsWith('- ') || event.changes[0].text.startsWith('1. '))) {
return;
}

if (hasPrefix) {
this.handleKeyDown(model, position.lineNumber);
}
});
}
}

Expand Down

0 comments on commit 1cb77e8

Please sign in to comment.