1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-07 21:47:02 +09:00

Merge pull request #1455 from anyproto/fix/table-row-keyboard-reorder

Feature/JS-4328: Table row keyboard reorder
This commit is contained in:
Razor 2025-06-05 17:27:53 +02:00 committed by GitHub
commit b76ee29719
Signed by: github
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 13 deletions

View file

@ -786,6 +786,28 @@ const BlockTable = observer(class BlockTable extends React.Component<I.BlockComp
let ret = false;
// Handle row reordering with Ctrl+Shift+Up/Down
keyboard.shortcut('moveSelectionUp, moveSelectionDown', e, (pressed: string) => {
e.preventDefault();
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 < 0) || (nextIdx < 0) || (nextIdx >= rows.length)) {
return;
};
const nextRow = rows[nextIdx];
if (nextRow && !nextRow.content.isHeader) {
this.onSortEndRow(rowId, nextRow.id, position);
};
ret = true;
});
keyboard.shortcut('shift+space', e, () => {
e.preventDefault();
@ -796,7 +818,7 @@ const BlockTable = observer(class BlockTable extends React.Component<I.BlockComp
if (!ret) {
onKeyDown(e, text, marks, range, props);
this.framesUpdate();
};
}
};
onCellKeyUp (e: any, rowId: string, columnId: string, id: string, text: string, marks: I.Mark[], range: I.TextRange, props: any) {
@ -1173,7 +1195,7 @@ const BlockTable = observer(class BlockTable extends React.Component<I.BlockComp
const { rootId } = this.props;
C.BlockTableColumnMove(this.props.rootId, id, targetId, position);
C.BlockTableColumnMove(rootId, id, targetId, position);
$('body').removeClass('grab');
keyboard.disableSelection(false);

View file

@ -1009,12 +1009,10 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
// Tab, indent block
keyboard.shortcut('indent, outdent', e, (pressed: string) => {
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<Props, Stat
return;
};
const shift = pressed.match('shift');
const shift = pressed == 'outdent';
const first = S.Block.getLeaf(rootId, ids[0]);
if (!first) {
return;
@ -1096,7 +1094,7 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
const { rootId, isPopup } = this.props;
const selection = S.Common.getRef('selectionProvider');
const dir = pressed.match(Key.up) ? -1 : 1;
const dir = pressed == 'moveSelectionUp' ? -1 : 1;
const ids = selection?.get(I.SelectType.Block, false) || [];
if (!ids.length) {
@ -1167,7 +1165,7 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
return;
};
const dir = pressed.match(Key.up) ? -1 : 1;
const dir = pressed == 'moveSelectionUp' ? -1 : 1;
let next = S.Block.getNextBlock(rootId, block.id, dir, it => (
!it.isIcon() &&
@ -1618,9 +1616,13 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
const { rootId } = this.props;
const { isInsideTable } = props;
const block = S.Block.getLeaf(rootId, focused);
const withTab = pressed.match(Key.tab);
const withTab = [ 'indent', 'outdent' ].includes(pressed);
const isRtl = U.Common.checkRtl(text);
const dir = (pressed.match([ Key.left, Key.shift ].join('|')) ? -1 : 1) * (isRtl ? -1 : 1);
let dir = (pressed == 'outdent') || (pressed == Key.left) ? -1 : 1;
if (isRtl) {
dir = -dir;
};
if (!block) {
return;

View file

@ -80,9 +80,9 @@ const Vault = observer(forwardRef<VaultRefProps>((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;

View file

@ -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;
};
};