Skip to content

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

:bug: Restore mobile keyboard after inserting a block https://github.com/siyuan-note/siyuan/issues/19834

Daniele4868c28d0f5
diff --git a/app/src/block/insertEmptyBlock.test.ts b/app/src/block/insertEmptyBlock.test.ts
index c63d414d47..72dbdc8dc9 100644
--- a/app/src/block/insertEmptyBlock.test.ts
+++ b/app/src/block/insertEmptyBlock.test.ts
@@ -96,6 +96,8 @@ for (const position of ["beforebegin", "afterend"]) {
const exports: {insertEmptyBlock?: (...args: unknown[]) => Promise<void>} = {};
let operations: Array<{id: string; previousID?: string; nextID?: string}>;
let inverse: Array<{action: string; id: string; context: object}>;
+ let focusedRange: typeof range;
+ let keyboardRequests = 0;
runInNewContext(compiled, {
exports,
clearBlockSelectionMode,
@@ -109,8 +111,18 @@ for (const position of ["beforebegin", "afterend"]) {
operations = forward;
inverse = backward;
},
- focusByWbr: () => range.startContainer = inserted,
+ focusByWbr: () => {
+ range.startContainer = inserted;
+ return range;
+ },
scrollCenter: () => {},
+ isMobile: () => true,
+ restoreEditorFocusRange: (element: TestElement, restoredRange: typeof range) => {
+ assert.equal(element, editor);
+ focusedRange = restoredRange;
+ return true;
+ },
+ callMobileAppShowKeyboard: () => keyboardRequests++,
});
await exports.insertEmptyBlock(protyle, position,
@@ -121,6 +133,8 @@ for (const position of ["beforebegin", "afterend"]) {
assert.equal(first.getAttribute("select-start"), null);
assert.equal(last.getAttribute("select-end"), null);
assert.equal(range.startContainer, inserted);
+ assert.equal(focusedRange, range);
+ assert.equal(keyboardRequests, 1);
const anchor = targetKind === "multiple" && position === "afterend" ? last : first;
assert.equal(editor.children.indexOf(inserted), editor.children.indexOf(anchor) +
(position === "afterend" ? 1 : -1));
diff --git a/app/src/block/util.ts b/app/src/block/util.ts
index 8d1cfb4be4..8d67b5cb50 100644
--- a/app/src/block/util.ts
+++ b/app/src/block/util.ts
@@ -25,6 +25,9 @@ import {
import {shouldFocusJumpTarget, shouldFocusParentDocumentTitle} from "./jumpToParent";
import {getHorizontalSuperBlockChild} from "./superBlock";
import {normalizeHTMLAssetIFrameBlockDOM} from "../asset/html";
+import {isMobile} from "../util/functions";
+import {restoreEditorFocusRange} from "../protyle/util/editorFocus";
+import {callMobileAppShowKeyboard} from "../mobile/util/mobileAppUtil";
export const getCancelSBOperations = async (nodeElement: Element, options: {
notebookID?: string,
@@ -426,8 +429,11 @@ export const insertEmptyBlock = async (protyle: IProtyle, position: InsertPositi
}
transaction(protyle, doOperations, undoOperations);
}
- focusByWbr(protyle.wysiwyg.element, range);
+ const insertedRange = focusByWbr(protyle.wysiwyg.element, range);
scrollCenter(protyle);
+ if (isMobile() && insertedRange && restoreEditorFocusRange(protyle.wysiwyg.element, insertedRange)) {
+ callMobileAppShowKeyboard();
+ }
};
export const insertEmptySuperBlockColumn = (protyle: IProtyle, position: "left" | "right", target?: Element) => {