diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts index 5424d0d10..26b97672a 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 bf227e175..92b658525 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 4113cd54b..00bf1f7d8 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 e7616d376..31890436e 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?: {