Skip to content

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

:iphone: https://github.com/siyuan-note/siyuan/issues/17454

Vanessabf47790a5fb6
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index efb55041bb..02613902b4 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -7,7 +7,7 @@ import {
} from "../../protyle/util/hasClosest";
import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
import {Constants} from "../../constants";
-import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
+import {focusBlock, focusByRange, getSelectionPosition} from "../../protyle/util/selection";
import {getCurrentEditor} from "../editor";
import {fontEvent, getFontNodeElements} from "../../protyle/toolbar/Font";
import {hideElements} from "../../protyle/ui/hideElements";
@@ -15,6 +15,7 @@ import {softEnter} from "../../protyle/wysiwyg/enter";
import {isInAndroid, isInEdge, isInHarmony} from "../../protyle/util/compatibility";
import {tabCodeBlock} from "../../protyle/wysiwyg/codeBlock";
import {callMobileAppShowKeyboard, canInput, keyboardLockUntil} from "./mobileAppUtil";
+import {isNotEditBlock} from "../../protyle/wysiwyg/getBlock";
let renderKeyboardToolbarTimeout: number;
let showUtil = false;
@@ -440,13 +441,24 @@ export const showKeyboardToolbar = () => {
setTimeout(() => {
const contentElement = hasClosestByClassName(range.startContainer, "protyle-content", true);
if (contentElement) {
- const contentTop = contentElement.getBoundingClientRect().top;
- const cursorTop = getSelectionPosition(contentElement).top;
- if (cursorTop < window.innerHeight - 42 && cursorTop > contentTop) {
+ let cursorTop = getSelectionPosition(contentElement).top;
+ if (cursorTop < 0 && window.siyuan.mobile.touchRange) {
+ const rangeBlockElement = hasClosestBlock(window.siyuan.mobile.touchRange.startContainer);
+ if (rangeBlockElement) {
+ if (isNotEditBlock(rangeBlockElement)) {
+ focusBlock(rangeBlockElement);
+ } else {
+ focusByRange(window.siyuan.mobile.touchRange);
+ }
+ cursorTop = getSelectionPosition(contentElement, window.siyuan.mobile.touchRange).top;
+ }
+ }
+ if (cursorTop < window.innerHeight - 42 && cursorTop > contentElement.getBoundingClientRect().top) {
return;
}
contentElement.scroll({
- top: contentElement.scrollTop + cursorTop - window.innerHeight + 42 + 26,
+ top: cursorTop < 0 ? contentElement.scrollTop + window.innerHeight - 42 :
+ contentElement.scrollTop + cursorTop - window.innerHeight + 42 + 26,
left: contentElement.scrollLeft,
behavior: "smooth"
});
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index d45e1588d2..c97d981c9d 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -10,6 +10,8 @@ import {activeBlur} from "./keyboardToolbar";
import {isIPhone} from "../../protyle/util/compatibility";
import {App} from "../../index";
import {globalTouchEnd, globalTouchStart} from "../../boot/globalEvent/touch";
+import {getRangeByPoint} from "../../protyle/util/selection";
+import {getCurrentEditor} from "../editor";
let clientX: number;
let clientY: number;
@@ -164,6 +166,15 @@ export const handleTouchStart = (event: TouchEvent) => {
if (globalTouchStart(event)) {
return;
}
+
+ if (getSelection().rangeCount > 0 && hasClosestBlock(event.target as Element)) {
+ const editor = getCurrentEditor();
+ if (editor && !editor.protyle.disabled && event.touches[0].clientY > window.innerHeight / 2 &&
+ document.querySelector("#keyboardToolbar").classList.contains("fn__none")) {
+ window.siyuan.mobile.touchRange = getRangeByPoint(event.touches[0].clientX, event.touches[0].clientY);
+ }
+ }
+
firstDirection = null;
xDiff = undefined;
yDiff = undefined;
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 730b838142..db12254152 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -299,7 +299,7 @@ interface Window {
reconnectWebSocket(): void;
- showKeyboardToolbar(height: number): void;
+ showKeyboardToolbar(): void;
processIOSPurchaseResponse(code: number): void;
@@ -512,6 +512,7 @@ interface ISiyuan {
emojis?: IEmoji[],
backStack?: IBackStack[],
mobile?: {
+ touchRange?: Range
size: {
isLandscape?: boolean,
landscape?: {