|
1 | 1 | import {DOMSerializer} from 'prosemirror-model';
|
2 |
| -import {EditorState, Plugin, PluginKey} from 'prosemirror-state'; |
3 |
| -import {Decoration, DecorationSet, EditorView} from 'prosemirror-view'; |
| 2 | +import {type EditorState, Plugin, PluginKey, TextSelection} from 'prosemirror-state'; |
| 3 | +import {Decoration, DecorationSet, type EditorView} from 'prosemirror-view'; |
4 | 4 |
|
5 | 5 | import {isNodeSelection} from '../../../utils/selection';
|
6 | 6 | import {pType} from '../../base/BaseSchema';
|
@@ -32,6 +32,21 @@ export const gapCursor = () =>
|
32 | 32 | };
|
33 | 33 | },
|
34 | 34 | props: {
|
| 35 | + handleKeyPress(view) { |
| 36 | + const { |
| 37 | + state, |
| 38 | + state: {selection: sel}, |
| 39 | + } = view; |
| 40 | + if (isGapCursorSelection(sel)) { |
| 41 | + // Replace GapCursorSelection with empty textblock before run all other handlers. |
| 42 | + // This should be done before all inputRules and other handlers, that handle text input. |
| 43 | + // Thus, entering text into a native textblock and into a "virtual" one – GapCursor – will be the same. |
| 44 | + const tr = state.tr.replaceSelectionWith(pType(state.schema).create()); |
| 45 | + tr.setSelection(TextSelection.create(tr.doc, sel.pos + 1)); |
| 46 | + view.dispatch(tr.scrollIntoView()); |
| 47 | + } |
| 48 | + return false; |
| 49 | + }, |
35 | 50 | decorations: ({doc, selection}: EditorState) => {
|
36 | 51 | if (isGapCursorSelection(selection)) {
|
37 | 52 | const position = selection.head;
|
|
0 commit comments