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

Commit

Permalink
Up arrow key focuses the previous block
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed May 20, 2020
1 parent 7090139 commit 6053f45
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/TextBlock/TextBlockEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useMemo } from 'react';
import { Range } from 'slate';
import SlateEditor from './../editor';
import { getDOMSelectionInfo } from './../editor/utils';
import { plaintext_serialize } from './../editor/render';
Expand All @@ -7,12 +8,32 @@ import { SidebarPortal } from '@plone/volto/components';
import ShortcutListing from './ShortcutListing';

const TextBlockEdit = (props) => {
const { data, selected, block, onChangeBlock } = props;
const {
data,
selected,
block,
onChangeBlock,
onFocusPreviousBlock,
blockNode,
} = props;

const { value } = data;

const keyDownHandlers = useMemo(() => {
return {
ArrowUp: ({ editor, event, selection }) => {
// works with both list and normal blocks
if (Range.isCollapsed(editor.selection)) {
if (
!editor.selection.anchor.path ||
editor.selection.anchor.path[0] === 0
) {
if (editor.selection.anchor.offset === 0) {
onFocusPreviousBlock(block, blockNode.current);
}
}
}

event.stopPropagation();
},

Expand Down

0 comments on commit 6053f45

Please sign in to comment.