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: https://github.com/siyuan-note/siyuan/issues/8554 12
Vanessa3f48221576bf
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex c68bdec5b8..048b3024ec 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -34,7 +34,7 @@ import {updateTransaction} from "../wysiwyg/transaction";import {removeBlock} from "../wysiwyg/remove";-import {focusBlock, focusByRange, getEditorRange} from "../util/selection";+import {focusBlock, focusByRange, getEditorRange, selectBlocksByRange} from "../util/selection";import {hideElements} from "../ui/hideElements";import {highlightRender} from "../render/highlightRender";import {blockRender} from "../render/blockRender";@@ -1293,12 +1293,26 @@ export class Gutter {if (!nodeElement) {return;}+ const editableElement = getContenteditableElement(nodeElement);+ const range = protyle.toolbar.range;+ if (range && protyle.wysiwyg.element.contains(range.startContainer) &&+ protyle.wysiwyg.element.contains(range.endContainer) &&+ hasClosestBlock(range.startContainer) !== hasClosestBlock(range.endContainer)) {+ hideElements(["select"], protyle);+ if (range.intersectsNode(hasClosestBlock(editableElement) || nodeElement)) {+ selectBlocksByRange(protyle, range);+ } else {+ range.collapse(false);+ }+ focusByRange(range);+ }const embedContext = getEmbedChildOperationContext(nodeElement);const selectsElement = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");if (!embedContext && selectsElement.length > 1) {window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_BLOCK_MULTI);const match = Array.from(selectsElement).find(item => {- if (id === item.getAttribute("data-node-id")) {+ if (id === item.getAttribute("data-node-id") ||+ editableElement && item.contains(editableElement)) {return true;}});diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.tsindex ada27c2f91..2cbb22c388 100644--- a/app/src/protyle/util/selection.ts+++ b/app/src/protyle/util/selection.ts@@ -2,6 +2,7 @@ import {getContenteditableElement,getNextBlock,getPreviousBlock,+ getTopAloneElement,hasPreviousSibling,isContainerBlock,isEndOfBlock,@@ -127,6 +128,22 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)countBlockWord(ids, protyle.block.rootID);};+export const selectBlocksByRange = (protyle: IProtyle, range: Range) => {+ const selectElements: HTMLElement[] = [];+ protyle.wysiwyg.element.querySelectorAll("[data-node-id]").forEach((item: HTMLElement) => {+ if (!item.querySelector("[data-node-id]") && range.intersectsNode(item)) {+ const embedElement = isInEmbedBlock(item);+ const selectElement = getTopAloneElement(embedElement || item) as HTMLElement;+ if (!selectElements.includes(selectElement)) {+ selectElements.push(selectElement);+ selectElement.classList.add("protyle-wysiwyg--select");+ }+ }+ });+ range.collapse(false);+ countBlockWord(selectElements.map(item => item.getAttribute("data-node-id")), protyle.block.rootID);+};+// https://github.com/siyuan-note/siyuan/issues/8196export const getRangeByPoint = (x: number, y: number) => {const range = document.caretRangeFromPoint(x, y);