Skip to content

Commit

Permalink
Fixed selection
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhermeF03 committed Jun 8, 2024
1 parent fc5d4d4 commit b2f25e5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion code/client/src/domain/editor/slate/utils/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function pointToCursor(editor: Editor, point: Point): Cursor {

export const cursorToPoint = (editor : Editor, cursor: Cursor): Point => {
const { line, column } = cursor;
const path = [line];
const path = [];
let offset = column;

const nodes = Array.from(Node.children(editor, [line]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Editor({ title, fugue, communication }: SlateEditorProps) {
const fugueOperations = getFugueOperations(fugue);
const { cursors } = useCursors(communication);
const { renderElement, renderLeaf } = useRenderers(editor, fugue, communication);
//const decorate = useDecorate(editor, cursors);
const decorate = useDecorate(editor, cursors);

const updateEditor = useCallback(
(newValue: Descendant[]) => {
Expand Down Expand Up @@ -94,7 +94,7 @@ function Editor({ title, fugue, communication }: SlateEditorProps) {
spellCheck={false}
renderElement={renderElement}
renderLeaf={renderLeaf}
//decorate={decorate}
decorate={decorate}
onDragStart={e => e.preventDefault()}
onDOMBeforeInput={onInput}
onCut={onCut}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FugueDomainOperations } from '@domain/editor/fugue/operations/fugue/typ
import {Editor, Transforms, Location} from 'slate';
import { Cursor } from '@domain/editor/cursor';
import {cursorToPoint, getSelection} from "@domain/editor/slate/utils/selection";
import {isEqual} from "lodash";


/**
Expand Down Expand Up @@ -34,10 +35,11 @@ function useEvents(
// Update the cursor position
const delta = ['insert', 'revive'].includes(op.type) ? 1 : -1;

selectionEnd.column += delta;
if(delta > 0) { // If we are deleting, we want to anchor the start of the selection
// Move start and end cursor if the selection is collapsed or inserting or reviving
if(delta > 0 || isEqual(selectionStart, selectionEnd)) {
selectionStart.column += delta;
}
selectionEnd.column += delta;
}

const newSelection : Location = {
Expand Down

0 comments on commit b2f25e5

Please sign in to comment.