Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve table cell select-all during keyboard resize https://github.com/siyuan-note/siyuan/issues/18842

Danield6b5c84350cf
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index b440490aed..d947c03e14 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -14,7 +14,7 @@ import {hideElements} from "../../protyle/ui/hideElements";
import {softEnter} from "../../protyle/wysiwyg/enter";
import {isInAndroid, isInEdge, isInHarmony, isInMobileApp} from "../../protyle/util/compatibility";
import {tabCodeBlock} from "../../protyle/wysiwyg/codeBlock";
-import {callMobileAppShowKeyboard, canInput, keyboardLockUntil} from "./mobileAppUtil";
+import {armKeyboardLock, callMobileAppShowKeyboard, canInput, keyboardLockUntil} from "./mobileAppUtil";
import {isNotEditBlock} from "../../protyle/wysiwyg/getBlock";
import {getMirror, getUndoRootID, hasUndoStateMirror, initMirror} from "../../protyle/undo/globalUndo";
import {getMobilePluginToolbarItems} from "./pluginToolbar";
@@ -23,6 +23,7 @@ import {
hasFixedSelectionEndpointChanged,
hasVisibleSelectionText,
isTableCellSelectAll,
+ shouldHideKeyboardAfterResize,
shouldPreserveTableCellSelectAll,
type TSelectionEndpoint,
} from "./touchSelection";
@@ -124,16 +125,20 @@ const rememberAndroidTableCellSelectAll = () => {
};
};
+const hasRecentAndroidTableCellSelectAll = (pendingSelection = pendingAndroidTableCellSelectAll) =>
+ !!pendingSelection && shouldPreserveTableCellSelectAll(pendingSelection.expiresAt, Date.now()) &&
+ pendingSelection.cell.isConnected && pendingSelection.editableElement.isConnected &&
+ pendingSelection.range.startContainer.isConnected && pendingSelection.range.endContainer.isConnected;
+
const restoreRecentAndroidTableCellSelectAll = () => {
const pendingSelection = pendingAndroidTableCellSelectAll;
pendingAndroidTableCellSelectAll = undefined;
- if (!pendingSelection || !shouldPreserveTableCellSelectAll(pendingSelection.expiresAt, Date.now()) ||
- !pendingSelection.cell.isConnected || !pendingSelection.editableElement.isConnected ||
- !pendingSelection.range.startContainer.isConnected || !pendingSelection.range.endContainer.isConnected) {
+ if (!pendingSelection || !hasRecentAndroidTableCellSelectAll(pendingSelection)) {
return false;
}
restoringAndroidTableCellSelectAll = true;
try {
+ armKeyboardLock();
pendingSelection.editableElement.focus({preventScroll: true});
const selection = getSelection();
selection.removeAllRanges();
@@ -988,7 +993,7 @@ export const initKeyboardToolbar = () => {
const isInputFocused = document.activeElement && (
["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) ||
(document.activeElement as HTMLElement).isContentEditable);
- if (!isInputFocused) {
+ if (shouldHideKeyboardAfterResize(isInputFocused, hasRecentAndroidTableCellSelectAll())) {
activeBlur();
}
} else if (!preventRender) {
@@ -1011,7 +1016,7 @@ export const initKeyboardToolbar = () => {
const isInputFocused = document.activeElement && (
["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) ||
(document.activeElement as HTMLElement).isContentEditable);
- if (!isInputFocused) {
+ if (shouldHideKeyboardAfterResize(isInputFocused, hasRecentAndroidTableCellSelectAll())) {
activeBlur();
}
} else if (!preventRender) {
diff --git a/app/src/mobile/util/touchSelection.test.ts b/app/src/mobile/util/touchSelection.test.ts
index fd8a8a334f..7eda7ee3c6 100644
--- a/app/src/mobile/util/touchSelection.test.ts
+++ b/app/src/mobile/util/touchSelection.test.ts
@@ -5,6 +5,7 @@ import {
hasFixedSelectionEndpointChanged,
hasVisibleSelectionText,
isTableCellSelectAll,
+ shouldHideKeyboardAfterResize,
shouldRestoreLongPressSelection,
shouldPreserveTableCellSelectAll,
} from "./touchSelection";
@@ -32,6 +33,12 @@ describe("mobile touch selection", () => {
assert.equal(shouldPreserveTableCellSelectAll(1500, 1501), false);
});
+ it("does not enqueue another keyboard hide while preserving table cell select all", () => {
+ assert.equal(shouldHideKeyboardAfterResize(false, true), false);
+ assert.equal(shouldHideKeyboardAfterResize(true, false), false);
+ assert.equal(shouldHideKeyboardAfterResize(false, false), true);
+ });
+
it("restores invisible cross-block selections involving the long-pressed block", () => {
assert.equal(shouldRestoreLongPressSelection(false, "\u200b\n", "current", "next", "current"), true);
assert.equal(shouldRestoreLongPressSelection(false, "\u200b\n", "current", "next", "next"), true);
diff --git a/app/src/mobile/util/touchSelection.ts b/app/src/mobile/util/touchSelection.ts
index 56902f7d5a..54c1dba614 100644
--- a/app/src/mobile/util/touchSelection.ts
+++ b/app/src/mobile/util/touchSelection.ts
@@ -11,6 +11,9 @@ export const isTableCellSelectAll = (selectionText: string, cellText: string) =>
export const shouldPreserveTableCellSelectAll = (expiresAt: number, now: number) => expiresAt >= now;
+export const shouldHideKeyboardAfterResize = (isInputFocused: boolean, preserveTableCellSelectAll: boolean) =>
+ !isInputFocused && !preserveTableCellSelectAll;
+
export const getMovingSelectionEndpoint = (
movingEndpoint: TSelectionEndpoint | undefined,
anchorChanged: boolean,