Skip to content

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

:bug: Keep mobile appearance panel open when hiding the keyboard

Daniel77738f992610
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index 2cbdf1fc39..c62a1cd11c 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -932,7 +932,7 @@ const renderKeyboardToolbar = () => {
if (!selection || selection.rangeCount === 0) {
return;
}
- if (!showUtil) {
+ if (!showUtil && keyboardPanelTop === undefined) {
hideKeyboardToolbarUtil();
}
showKeyboardToolbarElement();
@@ -1067,7 +1067,7 @@ const showKeyboardToolbarElement = () => {
if (pendingFocus && getCurrentEditor()?.protyle === pendingFocus.protyle && !pendingFocus.protyle.disabled) {
restoreEditorFocusRange(pendingFocus.protyle.wysiwyg.element, pendingFocus.range);
}
- if (!showUtil) {
+ if (!showUtil && keyboardPanelTop === undefined) {
hideKeyboardToolbarUtil();
}
const selection = getSelection();
@@ -1215,7 +1215,8 @@ export const hideKeyboardToolbar = () => {
}
clearTimeout(scrollSelectionIntoViewTimeout);
clearRenderGutterAfterScroll?.();
- if (showUtil) {
+ // 键盘退场时保留已展开的移动端菜单,菜单由用户操作或编辑器切换关闭。
+ if (showUtil || keyboardPanelTop !== undefined) {
return;
}
pendingKeyboardFocus = undefined;
@@ -1260,11 +1261,15 @@ export const hideKeyboardToolbarByApp = (preserveSelection = false) => {
return KeyboardHideResult.Cleanup;
}
hideElements(["util"], editor.protyle);
- const range = selection?.rangeCount > 0 && !selection.isCollapsed ? selection.getRangeAt(0) : undefined;
- const hasVisibleEditorSelection = !!range && hasVisibleSelectionText(stripSemanticMarkersFromRangeText(range)) &&
+ const range = selection?.rangeCount > 0 ? selection.getRangeAt(0) : undefined;
+ const hasEditorRange = !!range &&
editor.protyle.wysiwyg.element.contains(range.startContainer) &&
editor.protyle.wysiwyg.element.contains(range.endContainer);
- const result = getKeyboardHideResult(preserveSelection, tableCellSelectionRestored, hasVisibleEditorSelection);
+ const hasVisibleEditorSelection = hasEditorRange && !range.collapsed &&
+ hasVisibleSelectionText(stripSemanticMarkersFromRangeText(range));
+ // 菜单仍需使用当前选区,通知原生端保留 WebView 焦点和选区。
+ const result = getKeyboardHideResult(preserveSelection, tableCellSelectionRestored,
+ hasVisibleEditorSelection, keyboardPanelTop !== undefined && hasEditorRange);
if (result === KeyboardHideResult.PreserveSelection || !hasVisibleEditorSelection) {
return result;
}
diff --git a/app/src/mobile/util/touchSelection.test.ts b/app/src/mobile/util/touchSelection.test.ts
index 5ff7e9b234..7b422b21d0 100644
--- a/app/src/mobile/util/touchSelection.test.ts
+++ b/app/src/mobile/util/touchSelection.test.ts
@@ -48,6 +48,11 @@ describe("mobile touch selection", () => {
assert.equal(getKeyboardHideResult(false, false, true), KeyboardHideResult.Cleanup);
});
+ it("preserves editor selection and caret while a keyboard panel is open", () => {
+ assert.equal(getKeyboardHideResult(false, false, true, true), KeyboardHideResult.PreserveSelection);
+ assert.equal(getKeyboardHideResult(false, false, false, true), KeyboardHideResult.PreserveSelection);
+ });
+
it("restores table cell selection before considering ordinary text selection", () => {
assert.equal(getKeyboardHideResult(true, true, true), KeyboardHideResult.RestoreTableCellSelection);
assert.equal(getKeyboardHideResult(true, true, false), KeyboardHideResult.RestoreTableCellSelection);
diff --git a/app/src/mobile/util/touchSelection.ts b/app/src/mobile/util/touchSelection.ts
index 148a080ebd..eedad94675 100644
--- a/app/src/mobile/util/touchSelection.ts
+++ b/app/src/mobile/util/touchSelection.ts
@@ -25,11 +25,12 @@ export const getKeyboardHideResult = (
preserveSelection: boolean,
tableCellSelectionRestored: boolean,
hasVisibleEditorSelection: boolean,
+ hasActiveEditorPanel = false,
) => {
if (preserveSelection && tableCellSelectionRestored) {
return KeyboardHideResult.RestoreTableCellSelection;
}
- if (preserveSelection && hasVisibleEditorSelection) {
+ if (hasActiveEditorPanel || (preserveSelection && hasVisibleEditorSelection)) {
return KeyboardHideResult.PreserveSelection;
}
return KeyboardHideResult.Cleanup;