diff --git a/code/client/src/domain/editor/fugue/Fugue.ts b/code/client/src/domain/editor/fugue/Fugue.ts index 0657ae9b..bddb1be6 100644 --- a/code/client/src/domain/editor/fugue/Fugue.ts +++ b/code/client/src/domain/editor/fugue/Fugue.ts @@ -118,7 +118,7 @@ export class Fugue { */ deleteLocal(selection: Selection): DeleteOperation[] { const nodes = Array.from(this.traverseBySelection(selection)); - const cursor = selection.start; + const cursor = {...selection.start} return nodes.map(node => { if (node.value === '\n') { cursor.line++; diff --git a/code/client/src/domain/editor/slate/operations/input.ts b/code/client/src/domain/editor/slate/operations/input.ts index bff1eb9f..4b650b60 100644 --- a/code/client/src/domain/editor/slate/operations/input.ts +++ b/code/client/src/domain/editor/slate/operations/input.ts @@ -1,7 +1,7 @@ import { Editor } from 'slate'; import { ReactEditor } from 'slate-react'; import CustomEditor from '@domain/editor/slate/CustomEditor'; -import { isEqual } from 'lodash'; +import {isEqual, min} from 'lodash'; import { getKeyFromInputEvent } from '@domain/editor/slate/utils/domEvents'; import { getSelection, isSelected } from '@domain/editor/slate/utils/selection'; import { Cursor, emptyCursor } from '@domain/editor/cursor'; @@ -20,9 +20,13 @@ export default (editor: Editor, connector: InputConnector, onFormat: (mark: Inli if (!key) return; const selection = getSelection(editor); - const cursor = selection.start; + console.log("Selection: ", selection) + const cursor = min([{...selection.start}, {...selection.end}]) as Cursor; // always use the start of the selection + console.log("Initial Cursor: ", cursor); // if there is a selection, delete the selected text if (isSelected(editor)) connector.deleteSelection(selection); + console.log("Selection after deletion: ", getSelection(editor)); + console.log("Cursor after deletion: ", cursor); switch (key) { case 'Enter': onEnter(cursor); @@ -77,6 +81,7 @@ export default (editor: Editor, connector: InputConnector, onFormat: (mark: Inli */ function onKey(key: string, cursor: Cursor) { const styles = CustomEditor.getMarks(editor) as InlineStyle[]; + console.log("Cursor: ", cursor) connector.insertCharacter(key, cursor, styles); } diff --git a/code/client/src/ui/pages/document/components/editor/Editor.tsx b/code/client/src/ui/pages/document/components/editor/Editor.tsx index 5aee4608..d81dea41 100644 --- a/code/client/src/ui/pages/document/components/editor/Editor.tsx +++ b/code/client/src/ui/pages/document/components/editor/Editor.tsx @@ -46,6 +46,7 @@ function Editor({ title, connectors, fugue }: EditorProps) { const syncEditor = useCallback( (slate?: Descendant[]) => { + console.log("Syncing editor...") const newSlate = slate || toSlate(fugue); updateEditor(newSlate); },