From 17a52683e9dd6b0f0addf2107e4cafed7c67bb98 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 3 Mar 2023 13:31:15 +0100 Subject: [PATCH] Fix so that C-a (select all) in empty blocks doesn't select the whole buffer on first press --- src/editor/block/commands.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/editor/block/commands.js b/src/editor/block/commands.js index 28d116b..394227d 100644 --- a/src/editor/block/commands.js +++ b/src/editor/block/commands.js @@ -56,6 +56,19 @@ export const selectAll = ({ state, dispatch }) => { const range = state.selection.asSingle().ranges[0] const block = getActiveNoteBlock(state) + // handle empty blocks separately + if (block.content.from === block.content.to) { + // check if C-a has already been pressed + if (range.from === block.content.from-1 && range.to === block.content.to) { + return defaultSelectAll({state, dispatch}) + } + dispatch(state.update({ + selection: {anchor: block.content.from-1, head: block.content.to}, + userEvent: "select" + })) + return true + } + // check if all the text of the note is already selected, in which case we want to select all the text of the whole document if (range.from === block.content.from && range.to === block.content.to) { return defaultSelectAll({state, dispatch})