An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve HarmonyOS text selection menu behavior https://github.com/siyuan-note/siyuan/issues/18389
Daniel17b590cb246f
diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.tsindex 7fc7dd658a..d55a1cad7a 100644--- a/app/src/boot/globalEvent/event.ts+++ b/app/src/boot/globalEvent/event.ts@@ -14,10 +14,12 @@ import {cancelManualTouch, initTouchDragBridge, isLastPointerMouse} from "../../import {isWindow} from "../../util/functions";import {getDockByType} from "../../layout/tabUtil";import {fetchPost} from "../../util/fetch";+import {initHarmonyTextSelectionMenu} from "../../util/harmonyTextSelectionMenu";const KANBAN_GROUP_DRAG_TYPE = `${Constants.SIYUAN_DROP_GUTTER}NodeAttributeView${Constants.ZWSP}Group${Constants.ZWSP}`.toLowerCase();export const initWindowEvent = (app: App) => {+ initHarmonyTextSelectionMenu();let lastEncryptedNotebookTouch = 0;const touchEncryptedNotebooks = () => {if (window.siyuan.isPublish) {diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.tsindex 54b57d4380..421edd142b 100644--- a/app/src/mobile/index.ts+++ b/app/src/mobile/index.ts@@ -49,6 +49,7 @@ import {hideAllElements} from "../protyle/ui/hideElements";import {initTouchDragBridge} from "../util/touchDragBridge";import {appearanceConfigApi} from "../config/tabs/appearanceRuntime";import {openByMobile} from "../editor/openLink";+import {initHarmonyTextSelectionMenu} from "../util/harmonyTextSelectionMenu";class App {public plugins: import("../plugin").Plugin[] = [];@@ -60,6 +61,7 @@ class App {}registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);addBaseURL();+ initHarmonyTextSelectionMenu();this.appId = Constants.SIYUAN_APPID;const mainWs = new Model({app: this});diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.tsindex 6eef45c0af..01e205bef0 100644--- a/app/src/protyle/toolbar/index.ts+++ b/app/src/protyle/toolbar/index.ts@@ -1971,7 +1971,7 @@ export class Toolbar {this.subElement.classList.remove("fn__none");this.element.classList.add("fn__none");const rangePosition = getSelectionPosition(nodeElement, range);- setPosition(this.subElement, rangePosition.left, rangePosition.top - 48, this.LINE_HEIGHT);+ setPosition(this.subElement, rangePosition.left, rangePosition.top - this.subElement.clientHeight - 8, this.LINE_HEIGHT);}public isMultiSelectMode() {diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 2dd6866503..667b9c0e7a 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -325,6 +325,7 @@ interface Window {getScreenWidthPx(): numberexit(): voidsetWebViewFocusable(enable: boolean): void+ setNativeTextSelectionMenuDisabled(disabled: boolean): voidsendNotification(channel: string, title: string, body: string, delayInSeconds: number): numbercancelNotification(id: number): void};diff --git a/app/src/util/harmonyTextSelectionMenu.ts b/app/src/util/harmonyTextSelectionMenu.tsnew file mode 100644index 0000000000..a17a0f1796--- /dev/null+++ b/app/src/util/harmonyTextSelectionMenu.ts@@ -0,0 +1,45 @@+const INPUT_SELECTOR = "input, textarea, select, .b3-text-field";++export const initHarmonyTextSelectionMenu = () => {+ if (!window.JSHarmony?.setNativeTextSelectionMenuDisabled) {+ return;+ }++ let disabled: boolean | undefined;+ const update = (target: EventTarget | Node | null) => {+ let element: Element | null;+ if (target instanceof Element) {+ element = target;+ } else if (target instanceof Node) {+ element = target.parentElement;+ } else {+ element = null;+ }+ const nextDisabled = Boolean(element?.closest(".protyle-wysiwyg") && !element.closest(INPUT_SELECTOR));+ if (disabled === nextDisabled) {+ return;+ }+ disabled = nextDisabled;+ window.JSHarmony.setNativeTextSelectionMenuDisabled(nextDisabled);+ };++ document.addEventListener("pointerdown", (event) => {+ update(event.target);+ }, true);+ document.addEventListener("touchstart", (event) => {+ update(event.target);+ }, {capture: true, passive: true});+ document.addEventListener("focusin", (event) => {+ update(event.target);+ }, true);+ document.addEventListener("selectionchange", () => {+ const activeElement = document.activeElement;+ if (activeElement?.closest(INPUT_SELECTOR)) {+ update(activeElement);+ return;+ }+ const selection = window.getSelection();+ update(selection?.rangeCount ? selection.anchorNode : activeElement);+ });+ update(document.activeElement);+};