Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions system/libs/figa-ui/src/lib/code/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { basicSetup } from 'codemirror';
import { EditorView, keymap } from '@codemirror/view';
import { EditorState, type Extension } from '@codemirror/state';
import {
EditorState,
type Extension,
EditorSelection,
} from '@codemirror/state';
import type { SetupConfig } from './defs';
import { indentWithTab } from '@codemirror/commands';
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
Expand Down Expand Up @@ -37,7 +41,6 @@ const createBasicExtensions = ({
),
];
const extensions: Extension[] = [];

extensions.push(themeSetup);
extensions.push(keymap.of([indentWithTab]));

Expand All @@ -54,6 +57,26 @@ const createBasicExtensions = ({

extensions.push(setup);

const handlePasteExtension = EditorView.domEventHandlers({
paste: (_, view) => {
// setTimeout allows the paste to complete before we get the cursor position
setTimeout(() => {
const { state } = view;
const cursorPosition = state.selection.main.head;
view.dispatch({
// Insert a newline at the cursor position
changes: { from: cursorPosition, insert: '\n' },
// Move the cursor to the next line
selection: EditorSelection.cursor(cursorPosition + 1),
// Scroll the editor to the cursor position
scrollIntoView: true,
});
}, 0);
},
});

extensions.push(handlePasteExtension);

return extensions;
};

Expand Down