Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/14789

Vanessa70ab49f7aa8c
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index 5424d0d102..26b97672a0 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -473,6 +473,16 @@ export const activeBlur = () => {
export const initKeyboardToolbar = () => {
let preventRender = false;
document.addEventListener("selectionchange", () => {
+ if (isInAndroid()) {
+ const range = document.getSelection().getRangeAt(0);
+ const editor = getCurrentEditor();
+ if (range.toString() && editor.protyle.wysiwyg.element.contains(range.startContainer) &&
+ range.getBoundingClientRect().top < editor.protyle.contentElement.getBoundingClientRect().top) {
+ window.siyuan.mobile.androidLastRange = range.cloneRange();
+ } else {
+ window.siyuan.mobile.androidLastRange = null;
+ }
+ }
if (!preventRender) {
renderKeyboardToolbar();
}
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index bf227e1750..92b6585250 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -2,9 +2,11 @@ import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName,}
import {closeModel, closePanel} from "./closePanel";
import {popMenu} from "../menu";
import {activeBlur} from "./keyboardToolbar";
-import {isIPhone} from "../../protyle/util/compatibility";
+import {isInAndroid, isIPhone} from "../../protyle/util/compatibility";
import {App} from "../../index";
import {globalTouchEnd, globalTouchStart} from "../../boot/globalEvent/touch";
+import {focusByRange} from "../../protyle/util/selection";
+import {getCurrentEditor} from "../editor";
let clientX: number;
let clientY: number;
@@ -27,6 +29,15 @@ const popSide = (render = true) => {
};
export const handleTouchEnd = (event: TouchEvent, app: App) => {
+ if (isInAndroid() && window.siyuan.mobile.androidLastRange && getSelection().rangeCount>0) {
+ const range = getSelection().getRangeAt(0);
+ if (range.toString() && range.startContainer === window.siyuan.mobile.androidLastRange.startContainer) {
+ range.setStart(window.siyuan.mobile.androidLastRange.startContainer, window.siyuan.mobile.androidLastRange.startOffset);
+ focusByRange(range);
+ const editor = getCurrentEditor();
+ editor.protyle.toolbar.range = range;
+ }
+ }
if (isIPhone() && globalTouchEnd(event, yDiff, time, app)) {
event.stopImmediatePropagation();
event.preventDefault();
diff --git a/app/src/protyle/scroll/event.ts b/app/src/protyle/scroll/event.ts
index 4113cd54b5..00bf1f7d8f 100644
--- a/app/src/protyle/scroll/event.ts
+++ b/app/src/protyle/scroll/event.ts
@@ -59,6 +59,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
protyle.scroll.updateIndex(protyle, blockElement.getAttribute("data-node-id"));
}, Constants.TIMEOUT_LOAD);
}
+
if (protyle.wysiwyg.element.getAttribute("data-top") || protyle.block.showAll ||
(protyle.scroll && protyle.scroll.element.classList.contains("fn__none")) || !protyle.scroll ||
protyle.scroll.lastScrollTop === element.scrollTop || protyle.scroll.lastScrollTop === -1 ||
@@ -66,6 +67,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
!protyle.wysiwyg.element.firstElementChild) {
return;
}
+
if (protyle.scroll.lastScrollTop - element.scrollTop > 0) {
// up
if (element.scrollTop < element.clientHeight &&
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index e7616d376a..31890436e4 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -436,6 +436,7 @@ interface ISiyuan {
emojis?: IEmoji[],
backStack?: IBackStack[],
mobile?: {
+ androidLastRange?: Range,
editor?: import("../protyle").Protyle
popEditor?: import("../protyle").Protyle
docks?: {