feat(editor): New Code editor based on the TypeScript language service (#12285)

This commit is contained in:
Elias Meire
2025-01-08 11:28:56 +01:00
committed by GitHub
parent ac497c8a67
commit 52ae02abaa
58 changed files with 2861 additions and 758 deletions

View File

@@ -0,0 +1,52 @@
import { EditorSelection } from '@codemirror/state';
import type { Command } from '@codemirror/view';
const createAddCursor =
(direction: 'up' | 'down'): Command =>
(view) => {
const forward = direction === 'down';
let selection = view.state.selection;
for (const r of selection.ranges) {
selection = selection.addRange(view.moveVertically(r, forward));
}
view.dispatch({ selection });
return true;
};
export const addCursorUp = createAddCursor('up');
export const addCursorDown = createAddCursor('down');
export const addCursorAtEachSelectionLine: Command = (view) => {
let selection: EditorSelection | null = null;
for (const r of view.state.selection.ranges) {
if (r.empty) {
continue;
}
for (let pos = r.from; pos <= r.to; ) {
const line = view.state.doc.lineAt(pos);
const anchor = Math.min(line.to, r.to);
if (selection) {
selection = selection.addRange(EditorSelection.range(anchor, anchor));
} else {
selection = EditorSelection.single(anchor);
}
pos = line.to + 1;
}
}
if (!selection) {
return false;
}
view.dispatch({ selection });
return true;
};