From ffd8987bb5932f4ca2d535d36caaa6dc89a24b75 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Thu, 5 Jun 2025 16:54:01 +0200 Subject: [PATCH 1/3] feat(table): enable Ctrl+Shift+Up/Down to reorder rows from cell keydown handler --- src/ts/component/block/table.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ts/component/block/table.tsx b/src/ts/component/block/table.tsx index d9fc9d5ae1..2c7062cb62 100644 --- a/src/ts/component/block/table.tsx +++ b/src/ts/component/block/table.tsx @@ -786,6 +786,26 @@ const BlockTable = observer(class BlockTable extends React.Component { + e.preventDefault(); + + const dir = pressed.match('Up') ? -1 : 1; + const { rows } = this.getData(); + const idx = rows.findIndex(row => row.id === rowId); + const nextIdx = idx + dir; + + if (idx === -1 || nextIdx < 0 || nextIdx >= rows.length) return; + + const nextRow = rows[nextIdx]; + if (nextRow && !nextRow.content.isHeader) { + const position = dir < 0 ? I.BlockPosition.Top : I.BlockPosition.Bottom; + this.onSortEndRow(rowId, nextRow.id, position); + } + + ret = true; + }); + keyboard.shortcut('shift+space', e, () => { e.preventDefault(); @@ -796,7 +816,7 @@ const BlockTable = observer(class BlockTable extends React.Component Date: Thu, 5 Jun 2025 17:25:09 +0200 Subject: [PATCH 2/3] JS-4328: fix --- src/json/shortcut.ts | 4 ++-- src/ts/component/block/table.tsx | 12 +++++++----- src/ts/component/editor/page.tsx | 18 ++++++++++-------- src/ts/component/vault/index.tsx | 4 ++-- src/ts/lib/keyboard.ts | 6 +++++- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/json/shortcut.ts b/src/json/shortcut.ts index 834c158ca6..a4372b901c 100644 --- a/src/json/shortcut.ts +++ b/src/json/shortcut.ts @@ -119,8 +119,8 @@ const getSections = () => { { name: translate('popupShortcutNavigationPage5'), keys: [ cmdKey, 'arrowright' ] }, { name: translate('popupShortcutNavigationPage6'), keys: [ cmdKey, 'arrowup' ] }, { name: translate('popupShortcutNavigationPage7'), keys: [ cmdKey, 'arrowdown' ] }, - { id: 'moveSelectionUp', name: translate('popupShortcutNavigationPage8'), keys: [ cmdKey, 'shift', 'arrowup' ] }, - { id: 'moveSelectionDown', name: translate('popupShortcutNavigationPage11'), keys: [ cmdKey, 'shift', 'arrowdown' ] }, + { id: 'moveSelectionUp', name: translate('popupShortcutNavigationPage8') + ' / ' + translate('blockTableShortcutRowMoveUp'), keys: [ cmdKey, 'shift', 'arrowup' ], description: translate('blockTableShortcutRowMoveUpDesc') }, + { id: 'moveSelectionDown', name: translate('popupShortcutNavigationPage11') + ' / ' + translate('blockTableShortcutRowMoveDown'), keys: [ cmdKey, 'shift', 'arrowdown' ], description: translate('blockTableShortcutRowMoveDownDesc') }, { name: translate('popupShortcutNavigationPage10'), keys: [ cmdKey, 'enter' ] }, { id: 'turnBlock0', name: translate('popupShortcutEditorTurn0'), keys: [ cmdKey, '0' ], noEdit: true }, diff --git a/src/ts/component/block/table.tsx b/src/ts/component/block/table.tsx index 2c7062cb62..9b982b3bd1 100644 --- a/src/ts/component/block/table.tsx +++ b/src/ts/component/block/table.tsx @@ -790,18 +790,20 @@ const BlockTable = observer(class BlockTable extends React.Component { e.preventDefault(); - const dir = pressed.match('Up') ? -1 : 1; + const dir = pressed == 'moveSelectionUp' ? -1 : 1; + const position = dir < 0 ? I.BlockPosition.Top : I.BlockPosition.Bottom; const { rows } = this.getData(); const idx = rows.findIndex(row => row.id === rowId); const nextIdx = idx + dir; - if (idx === -1 || nextIdx < 0 || nextIdx >= rows.length) return; + if ((idx < 0) || (nextIdx < 0) || (nextIdx >= rows.length)) { + return; + }; const nextRow = rows[nextIdx]; if (nextRow && !nextRow.content.isHeader) { - const position = dir < 0 ? I.BlockPosition.Top : I.BlockPosition.Bottom; this.onSortEndRow(rowId, nextRow.id, position); - } + }; ret = true; }); @@ -1193,7 +1195,7 @@ const BlockTable = observer(class BlockTable extends React.Component { - const isShift = pressed.match('shift') ? true : false; - if (isInsideTable) { this.onArrowHorizontal(e, text, pressed, { from: length, to: length }, length, props); } else { - this.onTabBlock(e, range, isShift); + this.onTabBlock(e, range, pressed == 'outdent'); }; }); @@ -1059,7 +1057,7 @@ const EditorPage = observer(class EditorPage extends React.Component ( !it.isIcon() && @@ -1618,9 +1616,13 @@ const EditorPage = observer(class EditorPage extends React.Component((props, ref) => { pressed.current.add(key); }; - keyboard.shortcut('nextSpace, prevSpace', e, pressed => { + keyboard.shortcut('prevSpace, nextSpace', e, pressed => { checkKeyUp.current = true; - onArrow(pressed.match('shift') ? -1 : 1); + onArrow(pressed == 'prevSpace' ? -1 : 1); if (sidebar.isAnimating) { return; diff --git a/src/ts/lib/keyboard.ts b/src/ts/lib/keyboard.ts index 7fd8512bdd..ea1a60c7ef 100644 --- a/src/ts/lib/keyboard.ts +++ b/src/ts/lib/keyboard.ts @@ -1633,6 +1633,10 @@ class Keyboard { keys = item.split('+'); }; + if (!keys.length) { + continue; + }; + keys.sort(); for (const k of keys) { @@ -1647,7 +1651,7 @@ class Keyboard { const check = U.Common.arrayUnique(pressed).sort().join('+'); if (check == keys.join('+')) { - res = check; + res = item; }; }; From 0c43490a9202509dfd47cb059e1e1a2e6a61df24 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Thu, 5 Jun 2025 17:27:25 +0200 Subject: [PATCH 3/3] code review --- src/json/shortcut.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/json/shortcut.ts b/src/json/shortcut.ts index a4372b901c..834c158ca6 100644 --- a/src/json/shortcut.ts +++ b/src/json/shortcut.ts @@ -119,8 +119,8 @@ const getSections = () => { { name: translate('popupShortcutNavigationPage5'), keys: [ cmdKey, 'arrowright' ] }, { name: translate('popupShortcutNavigationPage6'), keys: [ cmdKey, 'arrowup' ] }, { name: translate('popupShortcutNavigationPage7'), keys: [ cmdKey, 'arrowdown' ] }, - { id: 'moveSelectionUp', name: translate('popupShortcutNavigationPage8') + ' / ' + translate('blockTableShortcutRowMoveUp'), keys: [ cmdKey, 'shift', 'arrowup' ], description: translate('blockTableShortcutRowMoveUpDesc') }, - { id: 'moveSelectionDown', name: translate('popupShortcutNavigationPage11') + ' / ' + translate('blockTableShortcutRowMoveDown'), keys: [ cmdKey, 'shift', 'arrowdown' ], description: translate('blockTableShortcutRowMoveDownDesc') }, + { id: 'moveSelectionUp', name: translate('popupShortcutNavigationPage8'), keys: [ cmdKey, 'shift', 'arrowup' ] }, + { id: 'moveSelectionDown', name: translate('popupShortcutNavigationPage11'), keys: [ cmdKey, 'shift', 'arrowdown' ] }, { name: translate('popupShortcutNavigationPage10'), keys: [ cmdKey, 'enter' ] }, { id: 'turnBlock0', name: translate('popupShortcutEditorTurn0'), keys: [ cmdKey, '0' ], noEdit: true },