Skip to content

Commit

Permalink
fix: nestedLexicalEditor focus and update from within TableCell (#529)
Browse files Browse the repository at this point in the history
* Register focus command for NestedLexicalEditor

* Reduce priority of blur command on table cell

* Raise focus command priority to match TableEditor

---------

Co-authored-by: Marc L <marcleq5@gmail.com>
  • Loading branch information
mlequime and Marc L authored Jul 24, 2024
1 parent d5ee5e2 commit f0c8135
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/plugins/core/NestedLexicalEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
$getNodeByKey,
$getRoot,
BLUR_COMMAND,
FOCUS_COMMAND,
COMMAND_PRIORITY_CRITICAL,
COMMAND_PRIORITY_EDITOR,
COMMAND_PRIORITY_HIGH,
Expand All @@ -12,7 +13,8 @@ import {
KEY_BACKSPACE_COMMAND,
LexicalEditor,
SELECTION_CHANGE_COMMAND,
createEditor
createEditor,
COMMAND_PRIORITY_LOW
} from 'lexical'
import * as Mdast from 'mdast'
import { Node } from 'unist'
Expand Down Expand Up @@ -260,6 +262,14 @@ export const NestedLexicalEditor = function <T extends Mdast.RootContent>(props:
})
}
return mergeRegister(
editor.registerCommand(
FOCUS_COMMAND,
() => {
setEditorInFocus({ editorType: 'lexical', rootNode: lexicalNode })
return false
},
COMMAND_PRIORITY_LOW
),
editor.registerCommand(
BLUR_COMMAND,
(payload) => {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/table/TableEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
$getRoot,
BLUR_COMMAND,
COMMAND_PRIORITY_CRITICAL,
COMMAND_PRIORITY_EDITOR,
COMMAND_PRIORITY_LOW,
FOCUS_COMMAND,
KEY_ENTER_COMMAND,
Expand Down Expand Up @@ -443,7 +444,7 @@ const CellEditor: React.FC<CellProps> = ({ focus, setActiveCell, parentEditor, l
saveAndFocus(null)
return true
},
COMMAND_PRIORITY_CRITICAL
COMMAND_PRIORITY_EDITOR
),

editor.registerCommand(
Expand Down

0 comments on commit f0c8135

Please sign in to comment.