1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/editor/CodeMirror/editorCommands/insertLineAfter.ts

24 lines
751 B
TypeScript

import { insertNewlineAndIndent } from '@codemirror/commands';
import { insertNewlineContinueMarkup } from '@codemirror/lang-markdown';
import { EditorSelection, SelectionRange } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
const insertLineAfter = (view: EditorView) => {
const state = view.state;
view.dispatch(state.changeByRange((sel: SelectionRange) => {
const line = state.doc.lineAt(sel.anchor);
return {
range: EditorSelection.cursor(line.to),
};
}));
// insertNewlineContinueMarkup does nothing if not in markdown -- we thus
// need a fallback case
const addedNewLine = insertNewlineContinueMarkup(view);
if (!addedNewLine) {
insertNewlineAndIndent(view);
}
};
export default insertLineAfter;