Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
WIP on slate down arrow handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed May 21, 2020
1 parent 32ef70b commit d6c35fe
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/TextBlock/TextBlockEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { Range } from 'slate';
import { Range, Editor } from 'slate';
import SlateEditor from './../editor';
import { getDOMSelectionInfo } from './../editor/utils';
import { plaintext_serialize } from './../editor/render';
Expand All @@ -14,6 +14,7 @@ const TextBlockEdit = (props) => {
block,
onChangeBlock,
onFocusPreviousBlock,
onFocusNextBlock,
blockNode,
} = props;

Expand All @@ -35,7 +36,23 @@ const TextBlockEdit = (props) => {
},

ArrowDown: ({ editor, event, selection }) => {
event.stopPropagation();
const end = Editor.end(editor, editor.children);
console.log('end', end);

// daca suntem pe ultimul block
// daca suntem pe ultimul copil din block
// daca suntem la capatul selectiei din acel block
if (Range.isCollapsed(editor.selection)) {
const anchor = editor.selection?.anchor || {};
const { path } = anchor;
console.log('path', anchor);

if (!path || path[0] === 0) {
if (anchor.offset === 0) {
onFocusNextBlock(block, blockNode.current);
}
}
}
},

Backspace: ({ editor, event, selection, onDeleteBlock, id, data }) => {
Expand All @@ -60,7 +77,7 @@ const TextBlockEdit = (props) => {

...settings.slate?.keyDownHandlers,
};
}, [block, blockNode, onFocusPreviousBlock]);
}, [block, blockNode, onFocusPreviousBlock, onFocusNextBlock]);

return (
<>
Expand Down

0 comments on commit d6c35fe

Please sign in to comment.