Skip to content

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

:zap: Reduce export renderer dependencies https://github.com/siyuan-note/siyuan/issues/20219

Daniel41f78a8f2ee7
diff --git a/app/src/ai/actions.ts b/app/src/ai/actions.ts
index 47c3e31225..d7fa41c02f 100644
--- a/app/src/ai/actions.ts
+++ b/app/src/ai/actions.ts
@@ -1,5 +1,5 @@
import {fetchPost} from "../util/fetch";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {Dialog} from "../dialog";
import {isMobile} from "../util/functions";
import {Constants} from "../constants";
diff --git a/app/src/ai/editor.ts b/app/src/ai/editor.ts
index d337c7e9ad..d44f47bba2 100644
--- a/app/src/ai/editor.ts
+++ b/app/src/ai/editor.ts
@@ -2,10 +2,9 @@ import {fetchAIEditorSSE, IAIEditorMessage, TAIEditorSSEEvent} from "./editorSSE
import {genUUID} from "../util/genID";
import {
focusByOffset,
- getBlockRanges,
- getSelectionOffset,
- setLastNodeRange
+ getBlockRanges
} from "../protyle/util/selection";
+import {getSelectionOffset, setLastNodeRange} from "../protyle/util/selectionOffsets";
import {getContenteditableElement} from "../protyle/wysiwyg/getBlock";
import {hasClosestByAttribute, hasClosestByTag, isInEmbedBlock} from "../protyle/util/hasClosest";
import {insertHTML} from "../protyle/util/insertHTML";
diff --git a/app/src/asset/anno.ts b/app/src/asset/anno.ts
index d7421e5632..327efa24eb 100644
--- a/app/src/asset/anno.ts
+++ b/app/src/asset/anno.ts
@@ -3,7 +3,7 @@ import {setPosition} from "../util/setPosition";
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
import {readText, setStorageVal, writeText} from "../protyle/util/compatibility";
import {getAllModels} from "../layout/getAll";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {Constants} from "../constants";
import {Dialog} from "../dialog";
import {showMessage} from "../dialog/message";
diff --git a/app/src/block/util.ts b/app/src/block/util.ts
index 8d67b5cb50..3816acea8e 100644
--- a/app/src/block/util.ts
+++ b/app/src/block/util.ts
@@ -1,4 +1,5 @@
-import {focusByRange, focusByWbr, getEditorRange, getUndoFocusContext} from "../protyle/util/selection";
+import {focusByWbr, getEditorRange, getUndoFocusContext} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {hasClosestBlock, hasClosestByClassName, isInEmbedBlock} from "../protyle/util/hasClosest";
import {
getContenteditableElement,
diff --git a/app/src/boot/globalEvent/command/panel.ts b/app/src/boot/globalEvent/command/panel.ts
index 4c44fb46ea..5fef5dae60 100644
--- a/app/src/boot/globalEvent/command/panel.ts
+++ b/app/src/boot/globalEvent/command/panel.ts
@@ -6,7 +6,7 @@ import {setStorageVal, updateHotkeyTip} from "../../../protyle/util/compatibilit
import {isMobile} from "../../../util/functions";
import {Constants} from "../../../constants";
import {hasClosestByClassName} from "../../../protyle/util/hasClosest";
-import {focusByRange} from "../../../protyle/util/selection";
+import {focusByRange} from "../../../protyle/util/selectionOffsets";
import {matchHotKey} from "../../../protyle/util/hotKey";
import {captureCommandContext} from "../../../command/context";
import {ensureCommandSystem, executeCommandById} from "../../../command/executor";
diff --git a/app/src/boot/globalEvent/command/protyle.ts b/app/src/boot/globalEvent/command/protyle.ts
index ba944856ef..c7381f4fa1 100644
--- a/app/src/boot/globalEvent/command/protyle.ts
+++ b/app/src/boot/globalEvent/command/protyle.ts
@@ -8,7 +8,7 @@ import {checkFold} from "../../../util/noRelyPCFunction";
import {updateReadonly} from "../../../protyle/breadcrumb/action";
import {Constants} from "../../../constants";
import {fetchPost} from "../../../util/fetch";
-import {getSelectionOffset} from "../../../protyle/util/selection";
+import {getSelectionOffset} from "../../../protyle/util/selectionOffsets";
export const onlyProtyleCommand = (options: {
command: string,
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index 409d8c67ee..3ea804d5a9 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -35,7 +35,8 @@ import {openFileById} from "../../editor/util";
import {getAllDocks, getAllEditor, getAllModels, getAllTabs} from "../../layout/getAll";
import {getDockHotkey, getDockKeymap} from "../../layout/dock/hotkey";
import {getKeymapBindings} from "../../util/keymapBindings";
-import {focusBlock, focusByRange, getBlockElementsByRange, selectBlocksByRange} from "../../protyle/util/selection";
+import {focusBlock, getBlockElementsByRange, selectBlocksByRange} from "../../protyle/util/selection";
+import {focusByRange} from "../../protyle/util/selectionOffsets";
import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
import {bindMenuKeydown} from "../../menus/Menu";
import {Dialog} from "../../dialog";
diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts
index dd85a240a1..df3ced2ced 100644
--- a/app/src/card/openCard.ts
+++ b/app/src/card/openCard.ts
@@ -22,7 +22,7 @@ import {getDisplayName, movePathTo} from "../util/pathName";
import type {App} from "../index";
import {resize} from "../protyle/util/resize";
import {setStorageVal} from "../protyle/util/compatibility";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {updateCardHV} from "./util";
import {showMessage} from "../dialog/message";
import {Menu} from "../plugin/Menu";
diff --git a/app/src/command/contextCommands.ts b/app/src/command/contextCommands.ts
index c6b3175441..da5b4ad882 100644
--- a/app/src/command/contextCommands.ts
+++ b/app/src/command/contextCommands.ts
@@ -4,7 +4,8 @@ import {getCommandRegistry} from "./service";
import {getEnglishCommandLabel} from "./english";
import {getCommandBlocks, getCommandDocument, hasCommandEditorTarget} from "./contextTargets";
import {isInEmbedBlock} from "../protyle/util/hasClosest";
-import {focusByRange, getEditorRange} from "../protyle/util/selection";
+import {getEditorRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {getNextBlockSibling} from "../protyle/wysiwyg/getBlock";
import {turnsIntoGroupsTransaction, turnsIntoTransaction, turnsOneInto} from "../protyle/wysiwyg/transaction";
import {turnParagraphIntoCode} from "../protyle/wysiwyg/turnIntoCode";
diff --git a/app/src/command/insertCommands.test.ts b/app/src/command/insertCommands.test.ts
index 611d459e7b..e50d781252 100644
--- a/app/src/command/insertCommands.test.ts
+++ b/app/src/command/insertCommands.test.ts
@@ -37,7 +37,7 @@ test("insert commands search and execute existing insertion actions at the saved
{id: "template", value: "template-value"}, {id: "ref", value: "(("},
]},
"../protyle/toolbar/inlineStyle": {isBuiltinInlineStyleVisible: () => true},
- "../protyle/util/selection": {focusByRange: (range: unknown) => focused.push(range)},
+ "../protyle/util/selectionOffsets": {focusByRange: (range: unknown) => focused.push(range)},
"../protyle/util/compatibility": {isDisabledFeature: () => false, isInAndroid: () => false},
"../util/hostCapabilities": {getHostCapabilities: () => ({widgets: true, remoteKernel: false})},
"../mobile/util/mobileAppUtil": {callMobileAppShowKeyboard: () => keyboards++},
diff --git a/app/src/command/insertCommands.ts b/app/src/command/insertCommands.ts
index 5b1a3567d8..d8d5c1e272 100644
--- a/app/src/command/insertCommands.ts
+++ b/app/src/command/insertCommands.ts
@@ -3,7 +3,7 @@ import {getEnglishCommandLabel} from "./english";
import type {ICommandContextSnapshot, ICommandDefinition, TCommandKeymapPath} from "./types";
import {getBuiltinSlashMenuItems} from "../protyle/hint/extend";
import {isBuiltinInlineStyleVisible, type TBuiltinInlineStyleID} from "../protyle/toolbar/inlineStyle";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {isDisabledFeature, isInAndroid} from "../protyle/util/compatibility";
import {getHostCapabilities} from "../util/hostCapabilities";
/// #if MOBILE
diff --git a/app/src/config/index.ts b/app/src/config/index.ts
index 229201dffd..c28f81b2b1 100644
--- a/app/src/config/index.ts
+++ b/app/src/config/index.ts
@@ -5,7 +5,7 @@ import {initSettingSearch, switchSettingTab} from "./search/dialog";
import {bindSettingSaveDelegation} from "./setting/save";
import {Dialog} from "../dialog";
import {Constants} from "../constants";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {initSettingDrag} from "./setting/drag";
/// #endif
import {unmountBazaarTab, withMountedBazaar} from "./bazaarTab";
diff --git a/app/src/editor/rename.ts b/app/src/editor/rename.ts
index adf58a6fea..1a143f4419 100644
--- a/app/src/editor/rename.ts
+++ b/app/src/editor/rename.ts
@@ -1,6 +1,6 @@
import {showMessage} from "../dialog/message";
import {openInputDialog} from "../dialog/inputDialog";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {hasClosestBlock} from "../protyle/util/hasClosest";
import {removeEmbed} from "../protyle/wysiwyg/removeEmbed";
import {getAssetName, getDisplayName, pathPosix, setNotebookName} from "../util/pathName";
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index dcab7f4d39..b861c2f503 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -11,7 +11,8 @@ import {getAssetExtension, getDisplayName, getDocDisplayName, isEncryptedBox, us
import {Constants} from "../constants";
import {Files} from "../layout/dock/Files";
import {fetchPost, fetchSyncPost} from "../util/fetch";
-import {focusBlock, focusByOffset, focusByRange} from "../protyle/util/selection";
+import {focusBlock, focusByOffset} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {onGet} from "../protyle/util/onGet";
/// #if !BROWSER
import {ipcRenderer} from "electron";
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index 31c87657a6..da09861e66 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -41,7 +41,8 @@ import {MenuItem} from "../menus/Menu";
import {escapeHtml} from "../util/escape";
import {getFrontend} from "../util/functions";
import {hideAllElements} from "../protyle/ui/hideElements";
-import {focusByOffset, getSelectionOffset} from "../protyle/util/selection";
+import {focusByOffset} from "../protyle/util/selection";
+import {getSelectionOffset} from "../protyle/util/selectionOffsets";
import {Custom} from "./dock/Custom";
import type {App} from "../index";
import {getFileTreeIconHTML} from "../emoji/fileTreeIcon";
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index 5bfe243517..d57a5dfe58 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -14,7 +14,7 @@ import {getAllEditor, getAllModels, getAllTabs, getAllWnds} from "./getAll";
import {Asset} from "../asset";
import {Search} from "../search";
import {Dock} from "./dock";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {hideElements} from "../protyle/ui/hideElements";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts
index 4953d52673..edcad82aa7 100644
--- a/app/src/menus/commonMenuItem.ts
+++ b/app/src/menus/commonMenuItem.ts
@@ -21,7 +21,8 @@ import {loadTemplateDirectories, openTemplateManager} from "../template/manager"
import {Dialog} from "../dialog";
import {openInputDialog} from "../dialog/inputDialog";
import {bindAliasInput} from "./aliasInput";
-import {focusBlock, focusByRange, getEditorRange} from "../protyle/util/selection";
+import {focusBlock, getEditorRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
/// #if !MOBILE
import {openAsset, openAssetInBackground, openBy} from "../editor/util";
/// #endif
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 703a5ae43c..fdf6b1a277 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -10,7 +10,8 @@ import {
} from "../protyle/util/hasClosest";
import {MenuItem} from "./Menu";
import {getTableCellVerticalAlignmentMenus, setTableCellStyle} from "../protyle/util/tableControl";
-import {focusBlock, focusByOffset, focusByRange, focusByWbr, getEditorRange, selectAll,} from "../protyle/util/selection";
+import {focusBlock, focusByOffset, focusByWbr, getEditorRange, selectAll} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {getViewFoldOccurrenceID, hasViewFoldContext, setViewFoldTransient} from "../protyle/util/viewFold";
import {
deleteColumn,
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index b6b1f74039..a47db76a55 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -8,7 +8,8 @@ import {
import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
import {Constants} from "../../constants";
import {getSuperBlockCommand} from "../../block/superBlock";
-import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
+import {getSelectionPosition} from "../../protyle/util/selection";
+import {focusByRange} from "../../protyle/util/selectionOffsets";
import {getCurrentEditor as getDocumentEditor} from "../editor";
import {getMobileToolbarPaddingElement, getMobileToolbarProtyle, getMobileToolbarUndo} from "../../protyle/lite/mobileToolbar";
import {LocalUndo} from "../../protyle/undo";
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index e6cf4e5a9d..fbdbff7e12 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -14,7 +14,8 @@ import {hasClosestBlock, hasTopClosestByClassName} from "../util/hasClosest";
import {needSubscribe} from "../../util/needSubscribe";
import {isMobile} from "../../util/functions";
import {zoomOut} from "../../menus/protyle";
-import {focusByRange, getEditorRange} from "../util/selection";
+import {getEditorRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
/// #if !MOBILE
import {openFileById} from "../../editor/util";
import {saveLayout} from "../../layout/util";
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 1a17f74428..68d0fb46a3 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -38,7 +38,8 @@ import {
} from "../wysiwyg/transaction";
import {isEmptyParagraph} from "../wysiwyg/emptyTextBlock";
import {removeBlockPreservingSelectionMode} from "../wysiwyg/remove";
-import {focusBlock, focusByRange, getBlockElementsByRange, getEditorRange, selectBlocksByRange} from "../util/selection";
+import {focusBlock, getBlockElementsByRange, getEditorRange, selectBlocksByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {getHeadingConversionElements} from "../wysiwyg/headingConversion";
import {hideElements} from "../ui/hideElements";
import {markGutterForFoldRestore} from "../ui/gutterVisibility";
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index 4f6858f1e2..9e545b8c2e 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -2,10 +2,9 @@ import {escapeHtmlTextAndAttr} from "../../util/escape";
import type {BlockQueryRequestInput} from "../../types/api";
import {
focusByOffset,
- focusByRange,
getEditorRange,
- getSelectionOffset,
} from "../util/selection";
+import {focusByRange, getSelectionOffset} from "../util/selectionOffsets";
import {fetchPost} from "../../util/fetch";
import {replaceFileName, validateName} from "../../editor/rename";
import {MenuItem} from "../../menus/Menu";
diff --git a/app/src/protyle/hint/dailyNoteSelection.test.ts b/app/src/protyle/hint/dailyNoteSelection.test.ts
index e3a279f1a9..6cac173b7a 100644
--- a/app/src/protyle/hint/dailyNoteSelection.test.ts
+++ b/app/src/protyle/hint/dailyNoteSelection.test.ts
@@ -37,13 +37,15 @@ test("daily note insertion survives caret movement and repaint without overwriti
},
"../util/selection": {
getUndoFocusContext: (_editor: unknown, range: unknown) => ({id: range === caret ? "caret" : "original"}),
- focusByRange: (range: typeof original) => { active = range; restoredCurrent = range.toString() === ""; },
restoreFocusContext: (_protyle: unknown, context: {id: string}) => {
if (scenario === "deleted") { return false; }
active = context.id === "caret" ? caret : {available: true, toString: () => originalText, cloneRange() { return {...this}; }};
return true;
},
},
+ "../util/selectionOffsets": {
+ focusByRange: (range: typeof original) => { active = range; restoredCurrent = range.toString() === ""; },
+ },
};
const exported = {};
runInNewContext(code, {exports: exported, require: (path: string) => mocks[path],
diff --git a/app/src/protyle/hint/dailyNoteSelection.ts b/app/src/protyle/hint/dailyNoteSelection.ts
index 8b45d30e45..e85f08a851 100644
--- a/app/src/protyle/hint/dailyNoteSelection.ts
+++ b/app/src/protyle/hint/dailyNoteSelection.ts
@@ -1,7 +1,8 @@
import {Constants} from "../../constants";
import {getBlockRefAnchorText} from "../../util/newFile";
import {isRangeInEditor, isSameRange} from "../../util/newFileSelection";
-import {focusByRange, getUndoFocusContext, restoreFocusContext} from "../util/selection";
+import {getUndoFocusContext, restoreFocusContext} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {stripSemanticMarkersFromRangeText} from "../util/inlineElementMarker";
const getInputText = (range: Range) => stripSemanticMarkersFromRangeText(range).split(Constants.ZWSP).join("");
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index 90a7ec0703..01edc7d431 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -9,7 +9,8 @@ import {blockRender} from "../render/blockRender";
import {Constants} from "../../constants";
import {processRender} from "../util/processCode";
import {highlightRender} from "../render/highlightRender";
-import {focusBlock, focusByRange, getEditorRange} from "../util/selection";
+import {focusBlock, getEditorRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
import {
getContenteditableElement,
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index 4d3d1d20d6..c78e58bcf8 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -12,13 +12,12 @@ import {
} from "../util/hasClosest";
import {
focusBlock,
- focusByRange,
focusByWbr,
getEditorRange,
- getSelectionOffset,
getSelectionPosition,
getUndoFocusContext,
} from "../util/selection";
+import {focusByRange, getSelectionOffset} from "../util/selectionOffsets";
import {genHintItemHTML, hintEmbed, hintRef, hintSlash, hintTag} from "./extend";
import {createDailyNoteReference} from "./dailyNote";
import {captureDailyNoteSelection, insertDailyNoteReference} from "./dailyNoteSelection";
diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.ts
index b657b57238..34a496d373 100644
--- a/app/src/protyle/preview/index.ts
+++ b/app/src/protyle/preview/index.ts
@@ -1,5 +1,5 @@
import {isOnlyMeta, writeText} from "../util/compatibility";
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {openLink} from "../../editor/openLink";
import {showMessage} from "../../dialog/message";
import {previewDocImage} from "./image";
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 53097a836e..dcfa587077 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -33,7 +33,8 @@ import {
import {emitOpenMenu} from "../../../plugin/EventBus";
import {openMenuPanel} from "./openMenuPanel";
import {hintRef} from "../../hint/extend";
-import {focusBlock, focusByRange} from "../../util/selection";
+import {focusBlock} from "../../util/selection";
+import {focusByRange} from "../../util/selectionOffsets";
import {showMessage} from "../../../dialog/message";
import {previewAttrViewImages} from "../../preview/image";
import {unicode2Emoji} from "../../../emoji";
diff --git a/app/src/protyle/render/av/addToDatabase.ts b/app/src/protyle/render/av/addToDatabase.ts
index 1a9ba79d77..77e145fed5 100644
--- a/app/src/protyle/render/av/addToDatabase.ts
+++ b/app/src/protyle/render/av/addToDatabase.ts
@@ -1,6 +1,6 @@
import {openSearchAV} from "./relation";
import {transaction} from "../../wysiwyg/transaction";
-import {focusByRange} from "../../util/selection";
+import {focusByRange} from "../../util/selectionOffsets";
import {hasClosestBlock} from "../../util/hasClosest";
import * as dayjs from "dayjs";
import {getAVFilteredTipContext} from "./filteredTip";
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index b5eb2b9fa3..fbc3605926 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -7,7 +7,8 @@ import {updateAttrViewCellAnimation} from "./action";
import {isNotCtrl} from "../../util/compatibility";
import {isDynamicRef, objEquals} from "../../../util/functions";
import {fetchPost, fetchSyncPost} from "../../../util/fetch";
-import {focusBlock, focusByRange} from "../../util/selection";
+import {focusBlock} from "../../util/selection";
+import {focusByRange} from "../../util/selectionOffsets";
import * as dayjs from "dayjs";
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
import {getColIconByType, getColId} from "./col";
diff --git a/app/src/protyle/render/av/focus.ts b/app/src/protyle/render/av/focus.ts
index afb0d6f97d..616117061d 100644
--- a/app/src/protyle/render/av/focus.ts
+++ b/app/src/protyle/render/av/focus.ts
@@ -1,7 +1,8 @@
import {isTableLikeView} from "./viewType";
import {addDragFill, cellScrollIntoView} from "./cell";
import {clearSelect} from "../../util/clear";
-import {focusBlock, focusByRange} from "../../util/selection";
+import {focusBlock} from "../../util/selection";
+import {focusByRange} from "../../util/selectionOffsets";
import {getFirstBlock, getLastBlock, getNextBlock, getPreviousBlock} from "../../wysiwyg/getBlock";
import {scrollCenter} from "../../../util/highlightById";
import {focusEditableAtGoalX, TVerticalDirection} from "../../wysiwyg/verticalCaret";
diff --git a/app/src/protyle/render/av/view.ts b/app/src/protyle/render/av/view.ts
index e9ab9c873b..69c39f202c 100644
--- a/app/src/protyle/render/av/view.ts
+++ b/app/src/protyle/render/av/view.ts
@@ -3,7 +3,8 @@ import {Menu} from "../../../plugin/Menu";
import {unicode2Emoji} from "../../../emoji";
import {transaction} from "../../wysiwyg/transaction";
import {openMenuPanel} from "./openMenuPanel";
-import {focusBlock, focusByRange, getEditorRange} from "../../util/selection";
+import {focusBlock, getEditorRange} from "../../util/selection";
+import {focusByRange} from "../../util/selectionOffsets";
import {upDownHint} from "../../../util/upDownHint";
import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
import {hasClosestByClassName} from "../../util/hasClosest";
diff --git a/app/src/protyle/render/highlightRender.ts b/app/src/protyle/render/highlightRender.ts
index 35aaafd078..62ec8923fa 100644
--- a/app/src/protyle/render/highlightRender.ts
+++ b/app/src/protyle/render/highlightRender.ts
@@ -1,10 +1,19 @@
import {addScript} from "../util/addScript";
import {Constants} from "../../constants";
-import {focusByOffset, getSelectionOffset} from "../util/selection";
+import {createRangeByOffsets, focusByRange, getSelectionOffset} from "../util/selectionOffsets";
+import {getContenteditableElement} from "../wysiwyg/getBlock";
import {setCodeTheme} from "./util";
import {escapeHtml} from "../../util/escape";
import {isFoldedRenderContent} from "./foldedContent";
+const focusCodeByOffset = (element: Element, start: number, end: number) => {
+ const range = createRangeByOffsets(getContenteditableElement(element) || element, start, end);
+ if (range) {
+ focusByRange(range);
+ }
+ return range;
+};
+
export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN, zoom = 1) => {
let codeElements: NodeListOf<Element> | Element[];
let isPreview = false;
@@ -121,9 +130,9 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN, z
ignoreIllegals: true
}).value;
if (wbrElement && getSelection().rangeCount > 0) {
- focusByOffset(block, startIndex, startIndex);
+ focusCodeByOffset(block, startIndex, startIndex);
} else if (codeSelection) {
- const range = focusByOffset(editable, codeSelection.start, codeSelection.end);
+ const range = focusCodeByOffset(editable, codeSelection.start, codeSelection.end);
if (backward && range) {
selection.setBaseAndExtent(range.endContainer, range.endOffset, range.startContainer, range.startOffset);
}
diff --git a/app/src/protyle/render/speechRender.ts b/app/src/protyle/render/speechRender.ts
index 79b72cff74..1ba24b9e6f 100644
--- a/app/src/protyle/render/speechRender.ts
+++ b/app/src/protyle/render/speechRender.ts
@@ -1,4 +1,4 @@
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
declare global {
interface Window {
diff --git a/app/src/protyle/render/tableCellInput.test.ts b/app/src/protyle/render/tableCellInput.test.ts
index 8b3805fd4f..d34caad372 100644
--- a/app/src/protyle/render/tableCellInput.test.ts
+++ b/app/src/protyle/render/tableCellInput.test.ts
@@ -522,10 +522,10 @@ test("table cell editors wait for outer input and table menu Enter is consumed",
const compile = (source: string) => transpileModule(source.replace(/^import [\s\S]*?;\r?\n/gm, "")
.replace(/^export (?:type )?\{[\s\S]*?\}(?: from "[^"]+")?;\r?\n/gm, "")
.replace(/^export /gm, ""), {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
- const selection = createSourceFile("selection.ts", read("../util/selection.ts"), ScriptTarget.Latest, true);
+ const selection = createSourceFile("selection.ts", read("../util/selection.ts") + "\n" + read("../util/selectionOffsets.ts"), ScriptTarget.Latest, true);
const selectionSource = selection.statements.filter(statement => isVariableStatement(statement) &&
statement.declarationList.declarations.some(declaration =>
- ["focusByWbr", "focusByOffset", "getSelectionOffset", "selectIsEditor", "searchNode", "setLastNodeRange"]
+ ["focusByWbr", "focusByOffset", "getSelectionOffset", "selectIsEditor", "searchNode", "setLastNodeRange", "getDOMOffset", "createRangeByOffsets"]
.includes(declaration.name.getText(selection))))
.map(statement => statement.getText(selection)).join("\n");
const source = ["../util/longTextWrap.ts", "../util/inlineElementBoundary.ts", "../toolbar/fontFamilyCore.ts",
diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.ts
index c43bee4eb3..e74f280db4 100644
--- a/app/src/protyle/render/tableCellRichEditor.ts
+++ b/app/src/protyle/render/tableCellRichEditor.ts
@@ -14,7 +14,8 @@ import {imgMenu} from "../../menus/protyle";
import {renderTableCellRichElements} from "./tableCellRich";
import {getTableBlockHTML, getTableCellInlineHTML, getTableCellRichBlockDOM, renderTableCellRich, serializeTableCellRich, setTableCellRich, TABLE_CELL_INLINE_ATTRIBUTE, updateTableCellEditingValue} from "../util/tableCellRich";
import {TABLE_CELL_RICH_ATTRIBUTE} from "../util/tableCellRichValue";
-import {focusByOffset, focusByRange, getSelectionOffset, getUndoFocusContext} from "../util/selection";
+import {focusByOffset, getUndoFocusContext} from "../util/selection";
+import {focusByRange, getSelectionOffset} from "../util/selectionOffsets";
import {getAdjacentRichTableCell, isTableCellCaretAtBoundary} from "../util/tableCellRichNavigation";
import {focusEditableAtGoalX, getCaretGoalX} from "../wysiwyg/verticalCaret";
import {fixTable} from "../util/table";
diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.ts
index c652b2bdca..d71b254327 100644
--- a/app/src/protyle/scroll/saveScroll.ts
+++ b/app/src/protyle/scroll/saveScroll.ts
@@ -1,6 +1,6 @@
import type {FileTreeGetDocRequestInput} from "../../types/api";
import {hasClosestBlock} from "../util/hasClosest";
-import {getSelectionOffset} from "../util/selection";
+import {getSelectionOffset} from "../util/selectionOffsets";
import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {Constants} from "../../constants";
diff --git a/app/src/protyle/toolbar/BlockType.test.ts b/app/src/protyle/toolbar/BlockType.test.ts
index 264c090965..9a5582f157 100644
--- a/app/src/protyle/toolbar/BlockType.test.ts
+++ b/app/src/protyle/toolbar/BlockType.test.ts
@@ -82,7 +82,7 @@ const setup = (mobile = false) => {
turnsIntoTransaction: (options: Record<string, unknown>) => transactions.push(options),
turnsIntoOneTransaction: (options: Record<string, unknown>) => transactions.push(options),
},
- "../util/selection": {focusByRange: () => state.restored++},
+ "../util/selectionOffsets": {focusByRange: () => state.restored++},
"./subElementLifecycle": {closeSubElement: (): void => undefined},
"../../util/escape": {escapeHtml: (value: string) => value},
"../../util/functions": {isMobile: () => state.mobile},
diff --git a/app/src/protyle/toolbar/BlockType.ts b/app/src/protyle/toolbar/BlockType.ts
index 5ddf9222fa..5e89778948 100644
--- a/app/src/protyle/toolbar/BlockType.ts
+++ b/app/src/protyle/toolbar/BlockType.ts
@@ -11,7 +11,7 @@ import {
} from "./blockTypeCore";
import {getEmbedGutterOperationContext} from "../wysiwyg/getBlock";
import {turnsIntoOneTransaction, turnsIntoTransaction} from "../wysiwyg/transaction";
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {closeSubElement} from "./subElementLifecycle";
import {escapeHtml} from "../../util/escape";
import {isMobile} from "../../util/functions";
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index b0f42d0403..d0d69ae497 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -1,6 +1,6 @@
import {setStorageVal, updateHotkeyTip} from "../util/compatibility";
import {ToolbarItem} from "./ToolbarItem";
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {Constants} from "../../constants";
import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";
import {updateBatchTransaction} from "../wysiwyg/transaction";
diff --git a/app/src/protyle/toolbar/InlineMemo.ts b/app/src/protyle/toolbar/InlineMemo.ts
index e8a838f299..4100743f9d 100644
--- a/app/src/protyle/toolbar/InlineMemo.ts
+++ b/app/src/protyle/toolbar/InlineMemo.ts
@@ -4,7 +4,7 @@ import {stripSemanticMarkersFromRangeText} from "../util/inlineElementMarker";
import {Constants} from "../../constants";
import {getFirstSelectedInlineMemoContent, isExactInlineMemoSelection} from "./inlineMemoSelection";
import {getContenteditableElement} from "../wysiwyg/getBlock";
-import {getSelectionOffset} from "../util/selection";
+import {getSelectionOffset} from "../util/selectionOffsets";
export class InlineMemo extends ToolbarItem {
public element: HTMLElement;
diff --git a/app/src/protyle/toolbar/fontControls.ts b/app/src/protyle/toolbar/fontControls.ts
index 4faf6d4787..10292c241f 100644
--- a/app/src/protyle/toolbar/fontControls.ts
+++ b/app/src/protyle/toolbar/fontControls.ts
@@ -2,7 +2,8 @@ import {Menu} from "../../plugin/Menu";
import {ToolbarItem} from "./ToolbarItem";
import {convertFontSize, fontEvent, getFontNodeElements, getFontSizeInfo} from "./Font";
import {getInlineFontFamilyLabel, getFontFamilyState, getInlineFontFamilyValue, openFontFamilyMenu} from "./fontFamilyMenu";
-import {focusByRange, getBlockRanges} from "../util/selection";
+import {getBlockRanges} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {escapeAttr} from "../../util/escape";
import {isMixedFontSize, normalizeFontSizeInput} from "./fontSizeCore";
import {closeSubElement} from "./subElementLifecycle";
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 6fa1acb56e..9fcc592a61 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -15,17 +15,16 @@ import {ToolbarItem} from "./ToolbarItem";
import {
fixTableRange,
focusBlock,
- focusByRange,
focusByOffset,
focusByWbr,
getBlockRanges,
getEditorRange,
- getSelectionOffset,
getSelectionPosition,
getUndoFocusContext,
IBlockRange,
selectAll
} from "../util/selection";
+import {focusByRange, getSelectionOffset} from "../util/selectionOffsets";
import {
hasClosestBlock,
hasClosestByAttribute,
diff --git a/app/src/protyle/toolbar/util.ts b/app/src/protyle/toolbar/util.ts
index cfcfb1c892..dea1faa348 100644
--- a/app/src/protyle/toolbar/util.ts
+++ b/app/src/protyle/toolbar/util.ts
@@ -1,7 +1,8 @@
import {fetchSyncPost} from "../../util/fetch";
import {markToolbarHotkey} from "./hotkey";
import {Constants} from "../../constants";
-import {focusByRange, focusByWbr} from "../util/selection";
+import {focusByWbr} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {isDisabledFeature, writeText} from "../util/compatibility";
import {isArrayEqual} from "../../util/functions";
import {hasSameTextStyle} from "./Font";
diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts
index 62e932319f..803bb88754 100644
--- a/app/src/protyle/ui/initUI.ts
+++ b/app/src/protyle/ui/initUI.ts
@@ -7,7 +7,7 @@ import {Constants} from "../../constants";
import {getContenteditableElement, getEmbedGutterOperationContext, getLastBlock} from "../wysiwyg/getBlock";
import {genEmptyElement, genHeadingElement} from "../../block/util";
import {transaction} from "../wysiwyg/transaction";
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
/// #if !MOBILE
import {moveResize} from "../../dialog/moveResize";
/// #endif
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 87d70cf4c0..daee6422c4 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -1,5 +1,5 @@
import {fetchWithAppId} from "../../util/fetchWithAppId";
-import {focusByRange} from "./selection";
+import {focusByRange} from "./selectionOffsets";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {Constants} from "../../constants";
/// #if !BROWSER
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index f59aa75047..aea8d38503 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -1,6 +1,7 @@
import type {FileTreeGetDocRequestInput} from "../../types/api";
import {cleanupDragIndicators, createListDragTarget} from "./listDragTarget";
-import {focusBlock, focusByRange, getRangeByPoint} from "./selection";
+import {focusBlock, getRangeByPoint} from "./selection";
+import {focusByRange} from "./selectionOffsets";
import {
getContenteditableElement,
getNextBlockSibling,
diff --git a/app/src/protyle/util/inlineElementBoundary.dom.test.ts b/app/src/protyle/util/inlineElementBoundary.dom.test.ts
index 68cd29b177..56c43668bb 100644
--- a/app/src/protyle/util/inlineElementBoundary.dom.test.ts
+++ b/app/src/protyle/util/inlineElementBoundary.dom.test.ts
@@ -190,7 +190,8 @@ test("input and line breaks preserve semantic inline boundary ownership", {
"util/inlineElementMarker"].map(name => [name, compile(read(name))]));
const args = [sources, extract("wysiwyg/enter", ["enter", "softEnter", "listEnter", "removeEmptyNode"]) +
extract("wysiwyg/list", ["genListItemElement"]),
- extract("util/selection", ["getSelectionOffset", "focusByWbr"]),
+ (extract("util/selectionOffsets", ["getSelectionOffset"]) +
+ extract("util/selection", ["focusByWbr"])),
extract("wysiwyg/getBlock", ["hasPreviousSibling", "hasNextSibling"])];
const source = `const __name = value => value; (${browserCases.toString()})(${args.map(value => JSON.stringify(value)).join(",")})`;
const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-inline-boundary-test-"));
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts
index 41cd06cfe7..74dd093da7 100644
--- a/app/src/protyle/util/insertHTML.ts
+++ b/app/src/protyle/util/insertHTML.ts
@@ -19,14 +19,12 @@ import {
import {
fixTableRange,
focusBlock,
- focusByRange,
focusByWbr,
getBlockRanges,
getEditorRange,
- getSelectionOffset,
getUndoFocusContext,
- setLastNodeRange,
} from "./selection";
+import {focusByRange, getSelectionOffset, setLastNodeRange} from "./selectionOffsets";
import {Constants} from "../../constants";
import {highlightRender} from "../render/highlightRender";
import {scrollCenter} from "../../util/highlightById";
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index 8a16529617..ba90d691ab 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -17,7 +17,8 @@ import {
import {processPasteCode, processRender} from "./processCode";
import {getLocalFiles, getTextSiyuanFromTextHTML, isInHarmony, readClipboard, readText} from "./compatibility";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
-import {focusByOffset, getEditorRange, getSelectionOffset, getUndoFocusContext} from "./selection";
+import {focusByOffset, getEditorRange, getUndoFocusContext} from "./selection";
+import {getSelectionOffset} from "./selectionOffsets";
import {blockRender} from "../render/blockRender";
import {highlightRender} from "../render/highlightRender";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 7145058953..392c571634 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -1,5 +1,4 @@
-import {revealTabsForTarget} from "../render/tabsRender";
-import {getTextWithLegacyInlineBoundary} from "./inlineElementBoundary";
+import {createRangeByOffsets, focusByRange, getSelectionOffset, setLastNodeRange} from "./selectionOffsets";
import {isHiddenTabContent} from "../render/tabsVisibility";
import {
getContenteditableElement,
@@ -24,27 +23,10 @@ import {genRenderFrame} from "../render/util";
import {Constants} from "../../constants";
import {getUndoFocusElement} from "./selectionFocus";
import {getBlockRangeSelectElements as getBlockRangeSelectElementsByDOM} from "./blockRangeSelect";
-import {
- getMarkerAwareTextLength,
- getSemanticMarkerPrefixLengthForNode,
- stripSemanticMarkersFromRangeText
-} from "./inlineElementMarker";
+import {getSemanticMarkerPrefixLengthForNode} from "./inlineElementMarker";
import {getSelectAllBlockAction, setBlockSelectionModeElement} from "../wysiwyg/blockSelection";
import {restoreListMindmapFocus} from "../render/listMindmap/render";
-const selectIsEditor = (editor: Element, range?: Range) => {
- if (!range) {
- if (getSelection().rangeCount === 0) {
- return false;
- } else {
- range = getSelection().getRangeAt(0);
- }
- }
- const container = range.commonAncestorContainer;
-
- return editor.isEqualNode(container) || editor.contains(container);
-};
-
// table 选中处理
export const fixTableRange = (range: Range) => {
const tableElement = hasClosestByAttribute(range.startContainer, "data-type", "NodeTable");
@@ -495,40 +477,6 @@ export const getSelectionPosition = (nodeElement: Element, range?: Range, useDir
};
};
-export const getSelectionOffset = (selectElement: Node, editorElement?: Element, range?: Range, ignoreZWSP = false) => {
- const position = {
- end: 0,
- start: 0,
- };
-
- if (!range) {
- if (getSelection().rangeCount === 0) {
- return position;
- }
- range = window.getSelection().getRangeAt(0);
- }
-
- if (editorElement && !selectIsEditor(editorElement, range)) {
- return position;
- }
- const preSelectionRange = range.cloneRange();
- if (selectElement.childNodes[0] && selectElement.childNodes[0].childNodes[0]) {
- preSelectionRange.setStart(selectElement.childNodes[0].childNodes[0], 0);
- } else {
- preSelectionRange.selectNodeContents(selectElement);
- }
- preSelectionRange.setEnd(range.startContainer, range.startOffset);
- const getRangeTextLength = (textRange: Range) => ignoreZWSP ?
- stripSemanticMarkersFromRangeText(textRange).split(Constants.ZWSP).join("").length :
- textRange.toString().length;
- // 需加上表格内软换行 br 的长度
- position.start = getRangeTextLength(preSelectionRange) +
- preSelectionRange.cloneContents().querySelectorAll("br, .emoji").length;
- position.end = position.start + getRangeTextLength(range) +
- range.cloneContents().querySelectorAll("br, .emoji").length;
- return position;
-};
-
export interface IBlockRange {
blockElement: HTMLElement;
editableElement: Element;
@@ -819,76 +767,6 @@ export const restoreUndoFocus = (protyle: IProtyle, operations: IOperation[]) =>
return operation ? restoreFocusContext(protyle, operation.context) : false;
};
-const searchNode = (
- container: Node,
- startNode: Node,
- predicate: (node: Node) => boolean,
- excludeSibling?: boolean,
-) => {
- if (!startNode) {
- return false;
- }
-
- if (predicate(startNode as Text)) {
- return true;
- }
-
- for (let i = 0, len = startNode.childNodes.length; i < len; i++) {
- if (searchNode(startNode, startNode.childNodes[i], predicate, true)) {
- return true;
- }
- }
-
- if (!excludeSibling) {
- let parentNode = startNode;
- while (parentNode && parentNode !== container) {
- let nextSibling = parentNode.nextSibling;
- while (nextSibling) {
- if (searchNode(container, nextSibling, predicate, true)) {
- return true;
- }
- nextSibling = nextSibling.nextSibling;
- }
- parentNode = parentNode.parentNode;
- }
- }
-
- return false;
-};
-
-export const setLastNodeRange = (editElement: Element, range: Range, setStart = true) => {
- if (!editElement) {
- return range;
- }
- let lastNode = editElement.lastChild as Element;
- while (lastNode && lastNode.nodeType !== 3) {
- // https://github.com/siyuan-note/siyuan/issues/12792
- if (!lastNode.lastChild) {
- break;
- }
- // 最后一个为多种行内元素嵌套
- lastNode = lastNode.lastChild as Element;
- }
- // https://github.com/siyuan-note/siyuan/issues/12753
- if (!lastNode) {
- lastNode = editElement;
- }
- if (setStart) {
- if (lastNode.nodeType !== 3 && (lastNode.classList.contains("render-node") || lastNode.tagName === "BR") && lastNode.innerHTML === "") {
- range.setStartAfter(lastNode);
- } else {
- range.setStart(lastNode, lastNode.textContent.length);
- }
- } else {
- if (lastNode.nodeType !== 3 && (lastNode.classList.contains("render-node") || lastNode.tagName === "BR") && lastNode.innerHTML === "") {
- range.setEndAfter(lastNode);
- } else {
- range.setEnd(lastNode, lastNode.textContent.length);
- }
- }
- return range;
-};
-
export const setFirstNodeRange = (editElement: Element, range: Range) => {
if (!editElement) {
return range;
@@ -913,25 +791,6 @@ export const setFirstNodeRange = (editElement: Element, range: Range) => {
return range;
};
-const getDOMOffset = (textNode: Text, offset: number, skipZWSP: boolean) => {
- const text = getTextWithLegacyInlineBoundary(textNode);
- const semanticPrefixLength = getSemanticMarkerPrefixLengthForNode(textNode);
- let domOffset = 0;
- let textOffset = 0;
- while (domOffset < text.length && textOffset < offset) {
- if (text[domOffset] !== Constants.ZWSP && domOffset >= semanticPrefixLength) {
- textOffset++;
- }
- domOffset++;
- }
- if (skipZWSP) {
- while (text[domOffset] === Constants.ZWSP || domOffset < semanticPrefixLength) {
- domOffset++;
- }
- }
- return domOffset;
-};
-
export const focusByOffset = (container: Element, start: number, end: number, isFocus = true, ignoreZWSP = false) => {
if (!container) {
return false;
@@ -943,91 +802,8 @@ export const focusByOffset = (container: Element, start: number, end: number, is
} else if (isFocus && (isNotEditBlock(container) || container.classList.contains("av"))) {
return focusBlock(container);
}
- const isSame = start === end;
- let startNode: Node;
- searchNode(container, container.firstChild, node => {
- if (node.nodeType === Node.TEXT_NODE) {
- const textNode = node as Text;
- const dataLength = ignoreZWSP ? getMarkerAwareTextLength(textNode, true) : textNode.data.length;
- if (start <= dataLength) {
- startNode = node;
- return true;
- }
- start -= dataLength;
- end -= dataLength;
- return false;
- } else if (node.nodeType === Node.ELEMENT_NODE &&
- ((node as Element).tagName === "BR" || (node as Element).classList.contains("emoji"))) {
- if (start <= 1) {
- startNode = node;
- return true;
- }
- start -= 1;
- end -= 1;
- return false;
- }
- });
-
- let endNode;
- if (startNode) {
- if (isSame) {
- endNode = startNode;
- } else {
- searchNode(container, startNode, node => {
- if (node.nodeType === Node.TEXT_NODE) {
- const textNode = node as Text;
- const dataLength = ignoreZWSP ? getMarkerAwareTextLength(textNode, true) : textNode.data.length;
- if (end <= dataLength) {
- endNode = node;
- return true;
- }
- end -= dataLength;
- return false;
- } else if (node.nodeType === Node.ELEMENT_NODE &&
- ((node as Element).tagName === "BR" || (node as Element).classList.contains("emoji"))) {
- if (end <= 1) {
- endNode = node;
- return true;
- }
- end -= 1;
- return false;
- }
- });
- }
- }
-
- const range = document.createRange();
- if (startNode) {
- if (startNode.nodeType === Node.TEXT_NODE) {
- range.setStart(startNode, ignoreZWSP ? getDOMOffset(startNode as Text, start, true) : start);
- } else {
- range.setStartAfter(startNode);
- }
- } else {
- if (start === 0) {
- range.setStart(container, 0);
- } else {
- setLastNodeRange(getContenteditableElement(container as Element), range);
- }
- }
- if (isSame) {
- range.collapse(true);
- } else {
- if (endNode) {
- if (endNode.nodeType === Node.TEXT_NODE) {
- range.setEnd(endNode, ignoreZWSP ? getDOMOffset(endNode as Text, end, false) : end);
- } else {
- range.setEndAfter(endNode);
- }
- } else {
- if (end === 0) {
- range.setEnd(container, 0);
- } else {
- setLastNodeRange(getContenteditableElement(container as Element), range, false);
- }
- }
- }
- if (isFocus) {
+ const range = createRangeByOffsets(container, start, end, ignoreZWSP, getContenteditableElement(container) || null);
+ if (isFocus && range) {
focusByRange(range);
}
return range;
@@ -1128,29 +904,6 @@ export const focusByWbr = (element: Element, range: Range, preserveWbr = false)
return range;
};
-export const focusByRange = (range: Range) => {
- if (!range) {
- return;
- }
-
- const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement;
- if (startNode && startNode.nodeType !== 3 && ["INPUT", "TEXTAREA"].includes(startNode.tagName)) {
- startNode.focus();
- return;
- }
- const target = range.startContainer.nodeType === Node.ELEMENT_NODE ? range.startContainer as Element : range.startContainer.parentElement;
- if (target) {
- const tabTitle = target.closest(".tab-item-title");
- if (tabTitle) {
- tabTitle.closest<HTMLElement>(".tab-item").dataset.tabsEditing = "true";
- }
- revealTabsForTarget(target);
- }
- const selection = window.getSelection();
- selection.removeAllRanges();
- selection.addRange(range);
-};
-
export const focusBlock = (element: Element, parentElement?: HTMLElement, toStart = true,
focusAVTitle = false): false | Range => {
if (!element) {
diff --git a/app/src/protyle/util/selectionOffsets.ts b/app/src/protyle/util/selectionOffsets.ts
new file mode 100644
index 0000000000..d800106f68
--- /dev/null
+++ b/app/src/protyle/util/selectionOffsets.ts
@@ -0,0 +1,256 @@
+import {Constants} from "../../constants";
+import {revealTabsForTarget} from "../render/tabsRender";
+import {getTextWithLegacyInlineBoundary} from "./inlineElementBoundary";
+import {getMarkerAwareTextLength, getSemanticMarkerPrefixLengthForNode, stripSemanticMarkersFromRangeText} from "./inlineElementMarker";
+
+const selectIsEditor = (editor: Element, range?: Range) => {
+ if (!range) {
+ if (getSelection().rangeCount === 0) {
+ return false;
+ } else {
+ range = getSelection().getRangeAt(0);
+ }
+ }
+ const container = range.commonAncestorContainer;
+
+ return editor.isEqualNode(container) || editor.contains(container);
+};
+
+export const getSelectionOffset = (selectElement: Node, editorElement?: Element, range?: Range, ignoreZWSP = false) => {
+ const position = {
+ end: 0,
+ start: 0,
+ };
+
+ if (!range) {
+ if (getSelection().rangeCount === 0) {
+ return position;
+ }
+ range = window.getSelection().getRangeAt(0);
+ }
+
+ if (editorElement && !selectIsEditor(editorElement, range)) {
+ return position;
+ }
+ const preSelectionRange = range.cloneRange();
+ if (selectElement.childNodes[0] && selectElement.childNodes[0].childNodes[0]) {
+ preSelectionRange.setStart(selectElement.childNodes[0].childNodes[0], 0);
+ } else {
+ preSelectionRange.selectNodeContents(selectElement);
+ }
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+ const getRangeTextLength = (textRange: Range) => ignoreZWSP ?
+ stripSemanticMarkersFromRangeText(textRange).split(Constants.ZWSP).join("").length :
+ textRange.toString().length;
+ // 需加上表格内软换行 br 的长度
+ position.start = getRangeTextLength(preSelectionRange) +
+ preSelectionRange.cloneContents().querySelectorAll("br, .emoji").length;
+ position.end = position.start + getRangeTextLength(range) +
+ range.cloneContents().querySelectorAll("br, .emoji").length;
+ return position;
+};
+
+const searchNode = (
+ container: Node,
+ startNode: Node,
+ predicate: (node: Node) => boolean,
+ excludeSibling?: boolean,
+) => {
+ if (!startNode) {
+ return false;
+ }
+
+ if (predicate(startNode as Text)) {
+ return true;
+ }
+
+ for (let i = 0, len = startNode.childNodes.length; i < len; i++) {
+ if (searchNode(startNode, startNode.childNodes[i], predicate, true)) {
+ return true;
+ }
+ }
+
+ if (!excludeSibling) {
+ let parentNode = startNode;
+ while (parentNode && parentNode !== container) {
+ let nextSibling = parentNode.nextSibling;
+ while (nextSibling) {
+ if (searchNode(container, nextSibling, predicate, true)) {
+ return true;
+ }
+ nextSibling = nextSibling.nextSibling;
+ }
+ parentNode = parentNode.parentNode;
+ }
+ }
+
+ return false;
+};
+
+export const setLastNodeRange = (editElement: Element, range: Range, setStart = true) => {
+ if (!editElement) {
+ return range;
+ }
+ let lastNode = editElement.lastChild as Element;
+ while (lastNode && lastNode.nodeType !== 3) {
+ // https://github.com/siyuan-note/siyuan/issues/12792
+ if (!lastNode.lastChild) {
+ break;
+ }
+ // 最后一个为多种行内元素嵌套
+ lastNode = lastNode.lastChild as Element;
+ }
+ // https://github.com/siyuan-note/siyuan/issues/12753
+ if (!lastNode) {
+ lastNode = editElement;
+ }
+ if (setStart) {
+ if (lastNode.nodeType !== 3 && (lastNode.classList.contains("render-node") || lastNode.tagName === "BR") && lastNode.innerHTML === "") {
+ range.setStartAfter(lastNode);
+ } else {
+ range.setStart(lastNode, lastNode.textContent.length);
+ }
+ } else {
+ if (lastNode.nodeType !== 3 && (lastNode.classList.contains("render-node") || lastNode.tagName === "BR") && lastNode.innerHTML === "") {
+ range.setEndAfter(lastNode);
+ } else {
+ range.setEnd(lastNode, lastNode.textContent.length);
+ }
+ }
+ return range;
+};
+
+const getDOMOffset = (textNode: Text, offset: number, skipZWSP: boolean) => {
+ const text = getTextWithLegacyInlineBoundary(textNode);
+ const semanticPrefixLength = getSemanticMarkerPrefixLengthForNode(textNode);
+ let domOffset = 0;
+ let textOffset = 0;
+ while (domOffset < text.length && textOffset < offset) {
+ if (text[domOffset] !== Constants.ZWSP && domOffset >= semanticPrefixLength) {
+ textOffset++;
+ }
+ domOffset++;
+ }
+ if (skipZWSP) {
+ while (text[domOffset] === Constants.ZWSP || domOffset < semanticPrefixLength) {
+ domOffset++;
+ }
+ }
+ return domOffset;
+};
+
+// 根据正文偏移构造 DOM 选区,不执行编辑器的特殊块聚焦。
+export const createRangeByOffsets = (container: Element, start: number, end: number, ignoreZWSP = false,
+ fallbackElement: Element | null = container) => {
+ if (!container) {
+ return false;
+ }
+ const isSame = start === end;
+ let startNode: Node;
+ searchNode(container, container.firstChild, node => {
+ if (node.nodeType === Node.TEXT_NODE) {
+ const textNode = node as Text;
+ const dataLength = ignoreZWSP ? getMarkerAwareTextLength(textNode, true) : textNode.data.length;
+ if (start <= dataLength) {
+ startNode = node;
+ return true;
+ }
+ start -= dataLength;
+ end -= dataLength;
+ return false;
+ } else if (node.nodeType === Node.ELEMENT_NODE &&
+ ((node as Element).tagName === "BR" || (node as Element).classList.contains("emoji"))) {
+ if (start <= 1) {
+ startNode = node;
+ return true;
+ }
+ start -= 1;
+ end -= 1;
+ return false;
+ }
+ });
+
+ let endNode;
+ if (startNode) {
+ if (isSame) {
+ endNode = startNode;
+ } else {
+ searchNode(container, startNode, node => {
+ if (node.nodeType === Node.TEXT_NODE) {
+ const textNode = node as Text;
+ const dataLength = ignoreZWSP ? getMarkerAwareTextLength(textNode, true) : textNode.data.length;
+ if (end <= dataLength) {
+ endNode = node;
+ return true;
+ }
+ end -= dataLength;
+ return false;
+ } else if (node.nodeType === Node.ELEMENT_NODE &&
+ ((node as Element).tagName === "BR" || (node as Element).classList.contains("emoji"))) {
+ if (end <= 1) {
+ endNode = node;
+ return true;
+ }
+ end -= 1;
+ return false;
+ }
+ });
+ }
+ }
+
+ const range = document.createRange();
+ if (startNode) {
+ if (startNode.nodeType === Node.TEXT_NODE) {
+ range.setStart(startNode, ignoreZWSP ? getDOMOffset(startNode as Text, start, true) : start);
+ } else {
+ range.setStartAfter(startNode);
+ }
+ } else {
+ if (start === 0) {
+ range.setStart(container, 0);
+ } else {
+ setLastNodeRange(fallbackElement, range);
+ }
+ }
+ if (isSame) {
+ range.collapse(true);
+ } else {
+ if (endNode) {
+ if (endNode.nodeType === Node.TEXT_NODE) {
+ range.setEnd(endNode, ignoreZWSP ? getDOMOffset(endNode as Text, end, false) : end);
+ } else {
+ range.setEndAfter(endNode);
+ }
+ } else {
+ if (end === 0) {
+ range.setEnd(container, 0);
+ } else {
+ setLastNodeRange(fallbackElement, range, false);
+ }
+ }
+ }
+ return range;
+};
+
+export const focusByRange = (range: Range) => {
+ if (!range) {
+ return;
+ }
+
+ const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement;
+ if (startNode && startNode.nodeType !== 3 && ["INPUT", "TEXTAREA"].includes(startNode.tagName)) {
+ startNode.focus();
+ return;
+ }
+ const target = range.startContainer.nodeType === Node.ELEMENT_NODE ? range.startContainer as Element : range.startContainer.parentElement;
+ if (target) {
+ const tabTitle = target.closest(".tab-item-title");
+ if (tabTitle) {
+ tabTitle.closest<HTMLElement>(".tab-item").dataset.tabsEditing = "true";
+ }
+ revealTabsForTarget(target);
+ }
+ const selection = window.getSelection();
+ selection.removeAllRanges();
+ selection.addRange(range);
+};
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index 90d6314abe..f953018fab 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -4,12 +4,11 @@ import {openInputDialog} from "../../dialog/inputDialog";
import {updateTransaction} from "../wysiwyg/transaction";
import {
focusBlock,
- focusByRange,
focusByWbr,
getEditorRange,
- getSelectionOffset,
getUndoFocusContext,
} from "./selection";
+import {focusByRange, getSelectionOffset} from "./selectionOffsets";
import {hasClosestBlock, hasClosestByClassName, hasClosestByTag} from "./hasClosest";
import {matchHotKey} from "./hotKey";
import {isNotCtrl} from "./compatibility";
diff --git a/app/src/protyle/util/tableCellRichLute.test.ts b/app/src/protyle/util/tableCellRichLute.test.ts
index c4fe683dfd..b33b7f56d5 100644
--- a/app/src/protyle/util/tableCellRichLute.test.ts
+++ b/app/src/protyle/util/tableCellRichLute.test.ts
@@ -474,10 +474,11 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
check.equal(updates, editableUpdates, "closing the editor invalidates menu callbacks");
const selectionDependencies = {getContenteditableElement, isNotEditBlock: () => false, revealTabsForTarget: () => {}};
const selectionAPI = new Function(...Object.keys(selectionDependencies), selectionSource +
- "\nreturn {captureRichCellSelection, captureRichCellSelectionAtPoint, restoreRichCellSelection, focusByOffset, getSelectionOffset, setLastNodeRange};")(
+ "\nreturn {captureRichCellSelection, captureRichCellSelectionAtPoint, restoreRichCellSelection, focusByOffset, getSelectionOffset, setLastNodeRange, createRangeByOffsets, focusByRange};")(
...Object.values(selectionDependencies)) as typeof import("./tableCellRichSelection") & typeof import("./selection");
const renderDependencies = {
isFoldedRenderContent: () => false,
+ getContenteditableElement,
...selectionAPI, Constants: {PROTYLE_CDN: ""}, setCodeTheme: () => {}, addScript: () => Promise.resolve(),
};
const render = new Function(...Object.keys(renderDependencies), highlightSource + "\nreturn highlightRender;")(
@@ -639,7 +640,7 @@ test("table cells insert code through slash and Enter without losing soft breaks
const copySource = ["normalizeText.ts", "../wysiwyg/codeBlockUtil.ts", "../wysiwyg/codeBlock.ts", "../lite/codeActions.ts"]
.map(file => compile(read(file))).join("\n") +
"\nbindLiteCodeActions(host, fragment.protyle, {signal, canEdit, beforeChange, onChange: commit});";
- const selectionSource = compile(read("selection.ts")) + "\n" + compile(read("tableCellRichSelection.ts"));
+ const selectionSource = compile(read("selectionOffsets.ts")) + "\n" + compile(read("selection.ts")) + "\n" + compile(read("tableCellRichSelection.ts"));
const highlightSource = compile(read("../render/highlightRender.ts"));
const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-table-cell-code-test-"));
const script = path.join(temporary, "run.cjs");
diff --git a/app/src/protyle/util/tableCellRichSelection.ts b/app/src/protyle/util/tableCellRichSelection.ts
index 1d4c7b0efd..d203b6dc62 100644
--- a/app/src/protyle/util/tableCellRichSelection.ts
+++ b/app/src/protyle/util/tableCellRichSelection.ts
@@ -1,4 +1,5 @@
-import {focusByOffset, focusByRange, getSelectionOffset} from "./selection";
+import {focusByOffset} from "./selection";
+import {focusByRange, getSelectionOffset} from "./selectionOffsets";
const getCellEditables = (root: Element) => Array.from(root.querySelectorAll<HTMLElement>(
'[data-type="NodeParagraph"] > [contenteditable]:not(.protyle-attr), ' +
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index f9d249f85a..1e58564494 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -7,7 +7,8 @@ import {updateTransaction} from "../wysiwyg/transaction";
import {copyPlainText, encodeBase64, isMac, readClipboard} from "./compatibility";
import {removeZWJ} from "./normalizeText";
import {paste} from "./paste";
-import {focusByRange, getEditorRange, getUndoFocusContext} from "./selection";
+import {getEditorRange, getUndoFocusContext} from "./selection";
+import {focusByRange} from "./selectionOffsets";
import {matchHotKey} from "./hotKey";
import {
buildTableGrid,
diff --git a/app/src/protyle/util/undoReplayFocus.test.ts b/app/src/protyle/util/undoReplayFocus.test.ts
index cafa3e0565..9f4399cb9c 100644
--- a/app/src/protyle/util/undoReplayFocus.test.ts
+++ b/app/src/protyle/util/undoReplayFocus.test.ts
@@ -261,8 +261,8 @@ test("undo replay restores recorded carets across paragraphs, table cells and em
"isNotEditBlock", "isContainerBlock", "hasPreviousSibling"]) +
extract("../wysiwyg/transaction.ts", ["updateBlock"]) +
extract("../wysiwyg/transactionUpdate.ts", ["shouldDeferCodeBlockCaretRestore"]) +
- extract("selection.ts", ["getSelectionOffset", "getUndoFocusContext", "restoreFocusContext", "restoreUndoFocus",
- "focusByOffset", "focusByRange", "focusByWbr", "searchNode", "getDOMOffset", "setLastNodeRange"]);
+ extract("selectionOffsets.ts", ["getSelectionOffset", "focusByRange", "searchNode", "getDOMOffset", "setLastNodeRange", "createRangeByOffsets"]) +
+ extract("selection.ts", ["getUndoFocusContext", "restoreFocusContext", "restoreUndoFocus", "focusByOffset", "focusByWbr"]);
const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-table-cut-undo-"));
const script = path.join(temporary, "run.cjs");
writeFileSync(script, `const {app, BrowserWindow} = require("electron");
diff --git a/app/src/protyle/wysiwyg/callout.ts b/app/src/protyle/wysiwyg/callout.ts
index 1b1e221926..495bd53f4b 100644
--- a/app/src/protyle/wysiwyg/callout.ts
+++ b/app/src/protyle/wysiwyg/callout.ts
@@ -1,7 +1,7 @@
import {transaction} from "./transaction";
import {Constants} from "../../constants";
import {openInputDialog} from "../../dialog/inputDialog";
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
export interface ICalloutPreset {
id: string;
diff --git a/app/src/protyle/wysiwyg/codeBlock.ts b/app/src/protyle/wysiwyg/codeBlock.ts
index c2201c2536..630b78502a 100644
--- a/app/src/protyle/wysiwyg/codeBlock.ts
+++ b/app/src/protyle/wysiwyg/codeBlock.ts
@@ -1,5 +1,6 @@
import {getContenteditableElement} from "./getBlock";
-import {focusByOffset, getSelectionOffset, getUndoFocusContext, setLastNodeRange} from "../util/selection";
+import {focusByOffset, getUndoFocusContext} from "../util/selection";
+import {getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {updateTransaction} from "./transaction";
import {Constants} from "../../constants";
import {
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
index d370079753..b384eecc75 100644
--- a/app/src/protyle/wysiwyg/commonHotkey.ts
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -2,7 +2,8 @@ import type {FileTreeGetDocRequestInput} from "../../types/api";
import {matchHotKey} from "../util/hotKey";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {isMac, writeText} from "../util/compatibility";
-import {focusBlock, getBlockElementsByRange, getEditorRange, getSelectionOffset, setFirstNodeRange, setLastNodeRange,} from "../util/selection";
+import {focusBlock, getBlockElementsByRange, getEditorRange, setFirstNodeRange} from "../util/selection";
+import {getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {getContenteditableElement, getNextBlock} from "./getBlock";
import {hideElements} from "../ui/hideElements";
import {countBlockWord} from "../../layout/status";
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index aeaa87c1f8..ac1054b794 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -1,5 +1,6 @@
import {genEmptyElement, genHeadingElement, insertEmptyBlock} from "../../block/util";
-import {focusByRange, focusByWbr, getSelectionOffset, getUndoFocusContext, setLastNodeRange} from "../util/selection";
+import {focusByWbr, getUndoFocusContext} from "../util/selection";
+import {focusByRange, getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {
getContenteditableElement, getParentBlock,
getEmbedChildOperationContext,
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index e5bec46679..35eb725b6c 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -34,18 +34,16 @@ import {
import {
focusBlock,
focusByOffset,
- focusByRange,
focusByWbr,
focusSideBlock,
getBlockRangeSelectElements,
getBlockRanges,
getEditorRange,
- getSelectionOffset,
getUndoFocusContext,
setFirstNodeRange,
setInsertWbrHTML,
- setLastNodeRange,
} from "../util/selection";
+import {focusByRange, getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {Constants} from "../../constants";
import {mergeTableCellContents} from "../util/tableCellRich";
import {resolveDocumentBlockElement} from "../util/outlineBlock";
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index f8048557cd..5c271959ee 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -1,4 +1,5 @@
-import {focusBlock, focusByOffset, focusByWbr, getEditorRange, getSelectionOffset} from "../util/selection";
+import {focusBlock, focusByOffset, focusByWbr, getEditorRange} from "../util/selection";
+import {getSelectionOffset} from "../util/selectionOffsets";
import {Constants} from "../../constants";
import * as dayjs from "dayjs";
import {transaction, turnsOneInto, updateTransaction, wrapBlockInBlockquote} from "./transaction";
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 8063f2d4f8..094865063e 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -9,12 +9,10 @@ import {getBlockInsertionContext} from "./blockInsertion";
import {isNotCtrl, isOnlyMeta, updateHotkeyTip, writeText} from "../util/compatibility";
import {
focusBlock,
- focusByRange,
focusByWbr,
getBlockElementsByRange,
getBlockRanges,
getEditorRange,
- getSelectionOffset,
getSelectionPosition,
getUndoFocusContext,
restoreFocusContext,
@@ -22,8 +20,8 @@ import {
selectBlocksByRange,
setFirstNodeRange,
setInsertWbrHTML,
- setLastNodeRange,
} from "../util/selection";
+import {focusByRange, getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {selectTextToEditorBoundary} from "../util/selectionBoundary";
import {
getEmptySemanticInlineForDelete,
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index e838e285f7..92c8900b50 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -1,4 +1,5 @@
-import {focusByRange, focusByWbr, getEditorRange, getUndoFocusContext} from "../util/selection";
+import {focusByWbr, getEditorRange, getUndoFocusContext} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {transaction, turnsIntoOneTransaction, updateTransaction} from "./transaction";
import {genEmptyBlock} from "../../block/util";
import * as dayjs from "dayjs";
diff --git a/app/src/protyle/wysiwyg/listShortcut.dom.test.ts b/app/src/protyle/wysiwyg/listShortcut.dom.test.ts
index 5e33f777dc..ee5750dc96 100644
--- a/app/src/protyle/wysiwyg/listShortcut.dom.test.ts
+++ b/app/src/protyle/wysiwyg/listShortcut.dom.test.ts
@@ -131,7 +131,8 @@ test("keyboard and gutter selection route all three mindmap list shortcuts to th
clearBlockSelectionMode, getBlockOperationElements, getBlockSelectionStatusIDs} = (() => {${extract("blockSelection")}
return {BLOCK_SELECTION_CLASS, getBlockSelectionModeElement, setBlockSelectionModeElement,
clearBlockSelectionMode, getBlockOperationElements, getBlockSelectionStatusIDs};})();`, extract("listContext"),
- extract("../util/selection", ["getEditorRange", "focusBlock", "focusByRange"]),
+ (extract("../util/selectionOffsets", ["focusByRange"]) +
+ extract("../util/selection", ["getEditorRange", "focusBlock"])),
extract("../gutter/index", ["restoreGutterRange"]),
extract("verticalNavigation", ["focusAtomicRegion", "focusVerticalBlockSelection"]), extract("keydown"),
].join("\n"), {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 2d5b26c17f..18427243c4 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -4,15 +4,13 @@ import {captureTabsRemoval} from "./tabsRemoval";
import {
focusBlock,
focusByOffset,
- focusByRange,
focusByWbr,
getBlockRanges,
getEditorRange,
- getSelectionOffset,
getUndoFocusContext,
- restoreFocusContext,
- setLastNodeRange
+ restoreFocusContext
} from "../util/selection";
+import {focusByRange, getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {
fixAdjacentTags,
getContenteditableElement,
diff --git a/app/src/protyle/wysiwyg/tabs.ts b/app/src/protyle/wysiwyg/tabs.ts
index ef8378448e..bc308c9af6 100644
--- a/app/src/protyle/wysiwyg/tabs.ts
+++ b/app/src/protyle/wysiwyg/tabs.ts
@@ -3,7 +3,8 @@ import {repairActiveTab} from "./tabsRemoval";
import {transaction} from "./transaction";
import {Constants} from "../../constants";
import {fetchPost} from "../../util/fetch";
-import {focusBlock, focusByRange} from "../util/selection";
+import {focusBlock} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {genEmptyElement, genSBElement} from "../../block/util";
import {Menu} from "../../plugin/Menu";
import {processRender} from "../util/processCode";
diff --git a/app/src/protyle/wysiwyg/touchCaret.ts b/app/src/protyle/wysiwyg/touchCaret.ts
index 2173f2cd55..40e7f77998 100644
--- a/app/src/protyle/wysiwyg/touchCaret.ts
+++ b/app/src/protyle/wysiwyg/touchCaret.ts
@@ -1,5 +1,5 @@
import {Constants} from "../../constants";
-import {focusByRange} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {isCommittedTextInput} from "./compositionInput";
import {bindTouchNavigation} from "./touchNavigation";
diff --git a/app/src/protyle/wysiwyg/verticalCaret.ts b/app/src/protyle/wysiwyg/verticalCaret.ts
index 3a46fe61e5..783bf06b0c 100644
--- a/app/src/protyle/wysiwyg/verticalCaret.ts
+++ b/app/src/protyle/wysiwyg/verticalCaret.ts
@@ -1,4 +1,5 @@
-import {focusByRange, setFirstNodeRange, setLastNodeRange} from "../util/selection";
+import {setFirstNodeRange} from "../util/selection";
+import {focusByRange, setLastNodeRange} from "../util/selectionOffsets";
import {
getCodeTrailingZeroWidthLineLimit,
getNavigableVerticalRects,
diff --git a/app/src/protyle/wysiwyg/verticalNavigation.ts b/app/src/protyle/wysiwyg/verticalNavigation.ts
index 67ef94a416..553906f749 100644
--- a/app/src/protyle/wysiwyg/verticalNavigation.ts
+++ b/app/src/protyle/wysiwyg/verticalNavigation.ts
@@ -1,6 +1,7 @@
import {isInEmbedBlock} from "../util/hasClosest";
import {isDocumentBoundaryLoaded} from "../util/documentRange";
-import {focusBlock, focusByRange} from "../util/selection";
+import {focusBlock} from "../util/selection";
+import {focusByRange} from "../util/selectionOffsets";
import {scrollCenter} from "../../util/highlightById";
import {getContenteditableElement} from "./getBlock";
import {focusEditableAtGoalX, getCaretGoalX, TVerticalDirection} from "./verticalCaret";
diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts
index f02840b0f9..9ca6090ea5 100644
--- a/app/src/search/spread.ts
+++ b/app/src/search/spread.ts
@@ -2,7 +2,7 @@ import {getNotebookName, pathPosix} from "../util/pathName";
import {Constants} from "../constants";
import {Dialog} from "../dialog";
import {fetchPost, fetchSyncPost} from "../util/fetch";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {genSearch, updateConfig} from "./util";
import type {App} from "../index";
import {cancelSearchRequest} from "./request";
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 15b4a09e98..81b59e772f 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -51,7 +51,7 @@ import {getDefaultSubType, getDefaultType} from "./getDefault";
import {isSupportCSSHL, searchMarkRender} from "../protyle/render/searchMarkRender";
import {saveKeyList, toggleAssetHistory, toggleReplaceHistory, toggleSearchHistory} from "./toggleHistory";
import {highlightById, scrollCenter} from "../util/highlightById";
-import {getSelectionOffset} from "../protyle/util/selection";
+import {getSelectionOffset} from "../protyle/util/selectionOffsets";
import {getHostCapabilities} from "../util/hostCapabilities";
import {electronUndo} from "../protyle/undo";
import {getContenteditableElement} from "../protyle/wysiwyg/getBlock";
diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.ts
index 91faa36e9e..3d2144feeb 100644
--- a/app/src/util/backForward.ts
+++ b/app/src/util/backForward.ts
@@ -1,7 +1,8 @@
import type {FileTreeGetDocRequestInput} from "../types/api";
import {hasClosestBlock, isInEmbedBlock} from "../protyle/util/hasClosest";
import {getContenteditableElement} from "../protyle/wysiwyg/getBlock";
-import {focusByOffset, focusByRange, getSelectionOffset} from "../protyle/util/selection";
+import {focusByOffset} from "../protyle/util/selection";
+import {focusByRange, getSelectionOffset} from "../protyle/util/selectionOffsets";
import {hideElements} from "../protyle/ui/hideElements";
import {fetchPost, fetchSyncPost} from "./fetch";
import {Constants} from "../constants";
diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.ts
index b4371b63ef..388ee84f4f 100644
--- a/app/src/util/highlightById.ts
+++ b/app/src/util/highlightById.ts
@@ -1,7 +1,8 @@
import {revealTabsForTarget} from "../protyle/render/tabsRender";
import {resolveVisibleListMindmapBlock} from "../protyle/render/listMindmap/render";
import {hasClosestBlock, isInEmbedBlock} from "../protyle/util/hasClosest";
-import {focusByRange, getEditorRange} from "../protyle/util/selection";
+import {getEditorRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {getStartScrollTop} from "./highlightPosition";
import {isMobile} from "./functions";
diff --git a/app/src/util/newFile.ts b/app/src/util/newFile.ts
index 390a3036eb..9f75d504b1 100644
--- a/app/src/util/newFile.ts
+++ b/app/src/util/newFile.ts
@@ -20,7 +20,8 @@ import {
getNewDocTargetFromTree,
isCurrentDocSubDocTarget
} from "./parseNewDocTarget";
-import {focusByRange, selectAll} from "../protyle/util/selection";
+import {selectAll} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {
createNewFileSelectionContext,
isNewFileSelectionValid,
diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts
index 10e9a755b1..7a072b07e2 100644
--- a/app/src/util/pathName.ts
+++ b/app/src/util/pathName.ts
@@ -3,7 +3,7 @@ import {fetchPost} from "./fetch";
import {Dialog} from "../dialog";
import {escapeAriaLabel, escapeHtml, escapeHtmlTextAndAttr} from "./escape";
import {isMobile} from "./functions";
-import {focusByRange} from "../protyle/util/selection";
+import {focusByRange} from "../protyle/util/selectionOffsets";
import {Constants} from "../constants";
import {getFileTreeDefaultIconAttr, getFileTreeIconHTML} from "../emoji/fileTreeIcon";
/// #if !BROWSER
diff --git a/app/tests/compositionCaret.test.js b/app/tests/compositionCaret.test.js
index 732ad7cd4c..6e06ea733c 100644
--- a/app/tests/compositionCaret.test.js
+++ b/app/tests/compositionCaret.test.js
@@ -93,8 +93,8 @@ const rendererSource = () => {
extract("util/hasClosest", ["hasClosestBlock", "hasClosestByAttribute", "hasClosestByClassName",
"hasClosestByTag", "isBlockElement"]) +
extract("wysiwyg/getBlock", ["getContenteditableElement", "isContainerBlock", "isNotEditBlock", "hasPreviousSibling"]) +
- extract("util/selection", ["getEditorRange", "focusByRange", "getSelectionOffset", "selectIsEditor",
- "focusByOffset", "searchNode", "setLastNodeRange", "setInsertWbrHTML", "focusByWbr"])
+ (extract("util/selectionOffsets", ["focusByRange", "getSelectionOffset", "selectIsEditor", "searchNode", "setLastNodeRange", "createRangeByOffsets", "getDOMOffset"]) +
+ extract("util/selection", ["getEditorRange", "focusByOffset", "setInsertWbrHTML", "focusByWbr"]))
.replace("export const getEditorRange =", "const readEditorRange =") +
"const getEditorRange = (element) => { editorRangeReads++; return readEditorRange(element); };" +
extract("wysiwyg/keydown", ["keydown"]) +
diff --git a/app/tests/dialogFocus.test.js b/app/tests/dialogFocus.test.js
index 1f117efa3f..e77b529b32 100644
--- a/app/tests/dialogFocus.test.js
+++ b/app/tests/dialogFocus.test.js
@@ -256,7 +256,7 @@ const runFlashcardCases = async (dialogSource, cardSource, mobile) => {
"../util/functions": {isMobile: () => mobile},
"../constants": {Constants: constants},
"../block/panelOwnership": {getDialogBlockPanel() {}, destroyDialogBlockPanels() {}},
- "../protyle/util/selection": {focusByRange: range => {
+ "../protyle/util/selectionOffsets": {focusByRange: range => {
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}},
diff --git a/app/tests/exportDependencyBoundary.test.js b/app/tests/exportDependencyBoundary.test.js
new file mode 100644
index 0000000000..2005316508
--- /dev/null
+++ b/app/tests/exportDependencyBoundary.test.js
@@ -0,0 +1,68 @@
+const assert = require("node:assert/strict");
+const {existsSync, readFileSync} = require("node:fs");
+const {createRequire} = require("node:module");
+const path = require("node:path");
+const test = require("node:test");
+const ts = require("typescript");
+const {parse} = require("ifdef-loader/preprocessor");
+const {transformSync} = createRequire(require.resolve("esbuild-loader"))("esbuild");
+
+const root = path.resolve(__dirname, "../src");
+const configuration = require("../webpack.export")({}, {mode: "production"});
+const loaders = configuration.module.rules.find(rule => rule.test.test("example.ts")).use;
+const options = {...loaders.find(loader => loader.loader === "ifdef-loader").options};
+delete options["ifdef-verbose"];
+
+// 按导出包的条件编译与类型擦除流程检查静态和动态依赖,不生成构建产物。
+const getExportDependencies = () => {
+ const visited = new Set();
+ const pending = [path.join(root, "protyle/method.ts")];
+ while (pending.length) {
+ const file = pending.pop();
+ if (visited.has(file)) {
+ continue;
+ }
+ visited.add(file);
+ const original = readFileSync(file, "utf8");
+ const code = file.endsWith(".ts") ? transformSync(parse(original, options, false), {
+ loader: "ts", target: "es6", format: "esm",
+ }).code : original;
+ const source = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true);
+ const add = specifier => {
+ if (!specifier.startsWith(".")) {
+ return;
+ }
+ const target = path.resolve(path.dirname(file), specifier);
+ const dependency = [target, target + ".ts", target + ".js", path.join(target, "index.ts")]
+ .find(candidate => /\.(ts|js)$/.test(candidate) && existsSync(candidate));
+ if (dependency) {
+ pending.push(dependency);
+ }
+ };
+ const visit = node => {
+ if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier &&
+ ts.isStringLiteral(node.moduleSpecifier)) {
+ add(node.moduleSpecifier.text);
+ } else if (ts.isCallExpression(node) && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0]) &&
+ (node.expression.kind === ts.SyntaxKind.ImportKeyword ||
+ ts.isIdentifier(node.expression) && node.expression.text === "require")) {
+ add(node.arguments[0].text);
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(source);
+ }
+ return Array.from(visited, file => path.relative(root, file).replaceAll(path.sep, "/"));
+};
+
+test("export rendering keeps application UI outside its runtime dependency graph", t => {
+ const dependencies = getExportDependencies();
+ // 富文本字体规范化只处理值,不加载工具栏或编辑器界面。
+ const sharedRenderHelpers = new Set(["protyle/toolbar/fontFamilyCore.ts"]);
+ const applicationModules = dependencies.filter(file => !sharedRenderHelpers.has(file) && (/^(config|layout|menus|mobile|plugin)\//.test(file) ||
+ /^protyle\/(hint|toolbar|header|gutter|ui)\//.test(file) || file === "protyle/util/selection.ts" ||
+ file === "protyle/render/tableCellRichEditor.ts"));
+ assert.deepEqual(applicationModules, [], "Export rendering imported application or editing UI");
+ assert.ok(dependencies.includes("protyle/render/listMindmap/legacy.ts"), "Legacy mind map rendering must remain available");
+ t.diagnostic(`Export renderer runtime dependency graph: ${dependencies.length} modules`);
+});
diff --git a/app/tests/iosTouchCaret.test.js b/app/tests/iosTouchCaret.test.js
index ff57dae19e..5660fa1078 100644
--- a/app/tests/iosTouchCaret.test.js
+++ b/app/tests/iosTouchCaret.test.js
@@ -6,7 +6,7 @@ const os = require("node:os");
const rendererSource = () => {
const ts = require("typescript");
const read = name => readFileSync(path.join(__dirname, "../src/protyle", `${name}.ts`), "utf8");
- const selection = ts.createSourceFile("selection.ts", read("util/selection"), ts.ScriptTarget.Latest, true);
+ const selection = ts.createSourceFile("selectionOffsets.ts", read("util/selectionOffsets"), ts.ScriptTarget.Latest, true);
const focus = selection.statements.find(statement => ts.isVariableStatement(statement) &&
statement.declarationList.declarations.some(declaration => declaration.name.getText(selection) === "focusByRange"));
assert.ok(focus);
diff --git a/app/tests/listFoldRemoval.test.js b/app/tests/listFoldRemoval.test.js
index 84c9d48a08..5df474b3cc 100644
--- a/app/tests/listFoldRemoval.test.js
+++ b/app/tests/listFoldRemoval.test.js
@@ -65,7 +65,8 @@ const rendererSource = () => {
extract("wysiwyg/getBlock", ["getParentBlock", "getPreviousBlock", "getPreviousBlockSibling",
"getNextBlockSibling", "getLastBlock", "getContenteditableElement", "isContainerBlock",
"isNotEditBlock", "getTopEmptyElement", "hasPreviousSibling"]) +
- extract("util/selection", ["focusByRange", "focusByWbr"]) +
+ (extract("util/selectionOffsets", ["focusByRange"]) +
+ extract("util/selection", ["focusByWbr"])) +
extract("wysiwyg/verticalVisibility", ["getFoldedNavigationOwner"]) +
extract("wysiwyg/remove", ["getOperationParentID", "removeBlock"]) +
extract("util/blockFold", ["applyFoldState", "toggleListFold"]) + `
diff --git a/app/tests/mobileContentToolbar.test.js b/app/tests/mobileContentToolbar.test.js
index dc48c32d55..6b89136578 100644
--- a/app/tests/mobileContentToolbar.test.js
+++ b/app/tests/mobileContentToolbar.test.js
@@ -273,7 +273,8 @@ const runElectron = async () => {
"window.expandAndroidWordSelection = expandAndroidWordSelection;",
extract("protyle/wysiwyg/getBlock", ["getContenteditableElement"]),
extract("protyle/ui/hideElements", ["hideElements"]),
- extract("protyle/util/selection", ["selectIsEditor", "selectAll", "getSelectionOffset", "focusByRange", "getEditorRange"]),
+ (extract("protyle/util/selectionOffsets", ["selectIsEditor", "getSelectionOffset", "focusByRange"]) +
+ extract("protyle/util/selection", ["selectAll", "getEditorRange"])),
"class ContentToolbar { private readonly LINE_HEIGHT = 32; render() {}\n" +
methods.map(method => method.getText(toolbarSource)).join("\n") + "\n}",
"window.ContentToolbar = ContentToolbar; window.focusContentRange = focusByRange;",
diff --git a/app/tests/mobileEditingToolbar.test.js b/app/tests/mobileEditingToolbar.test.js
index bfc7138091..28261e964a 100644
--- a/app/tests/mobileEditingToolbar.test.js
+++ b/app/tests/mobileEditingToolbar.test.js
@@ -52,8 +52,8 @@ const runCases = async (sources, platform) => {
"protyle/util/tableCellRichContext": {getTableCellRichContext: () => undefined},
"editor/getIcon": {getIconByType: () => "iconParagraph"},
"plugin/EventBusCore": {forEachPluginSubscriber() {}},
- "protyle/util/selection": {
- getSelectionPosition: () => ({top: 100, left: 0}),
+ "protyle/util/selection": {getSelectionPosition: () => ({top: 100, left: 0})},
+ "protyle/util/selectionOffsets": {
focusByRange: range => {
editable.focus();
getSelection().removeAllRanges();
diff --git a/app/tests/superBlockCreation.test.js b/app/tests/superBlockCreation.test.js
index 3e495eeca1..4693e254b4 100644
--- a/app/tests/superBlockCreation.test.js
+++ b/app/tests/superBlockCreation.test.js
@@ -22,7 +22,8 @@ const sources = () => {
extract("block/superBlock.ts", ["getSuperBlockCommand", "getSuperBlockCommandLayout", "getSuperBlockTailHeadings"]),
extract("block/insertSuperBlock.ts", ["genEmptySuperBlock", "focusInsertedBlock", "insertSuperBlockChild", "createSuperBlockColumn"]),
extract("protyle/wysiwyg/transaction.ts", ["turnsIntoOneTransaction"]),
- extract("protyle/util/selection.ts", ["focusByWbr", "focusByRange"]),
+ (extract("protyle/util/selectionOffsets.ts", ["focusByRange"]) +
+ extract("protyle/util/selection.ts", ["focusByWbr"])),
extract("protyle/wysiwyg/getBlock.ts", ["getContenteditableElement", "getParentBlock"]),
extract("mobile/util/keyboardToolbar.ts", ["getSlashItem", "renderSlashMenu"]),
].join("\n"),
diff --git a/app/tests/verticalNavigation.test.js b/app/tests/verticalNavigation.test.js
index bbc119fcac..616cc336cb 100644
--- a/app/tests/verticalNavigation.test.js
+++ b/app/tests/verticalNavigation.test.js
@@ -24,9 +24,12 @@ const rendererModules = () => {
import {getAtomicVerticalNavigationOwner} from "../wysiwyg/verticalNavigationState";
import {getContenteditableElement} from "../wysiwyg/getBlock";
import {hasClosestBlock} from "./hasClosest";\n` +
- extract("util/selection", ["setFirstNodeRange", "setLastNodeRange", "focusByRange", "focusBlock", "getEditorRange"])
+ (extract("util/selectionOffsets", ["setLastNodeRange", "focusByRange"]) +
+ extract("util/selection", ["setFirstNodeRange", "focusBlock", "getEditorRange"]))
.replace(/\/\/\/ #else[\s\S]*?\/\/\/ #endif/g, "");
modules["util/hasClosest"] = readFileSync(path.join(root, "util/hasClosest.ts"), "utf8");
+ modules["util/selectionOffsets"] = "const revealTabsForTarget = () => {};\n" +
+ extract("util/selectionOffsets", ["focusByRange", "setLastNodeRange"]);
modules["util/documentRange"] = readFileSync(path.join(root, "util/documentRange.ts"), "utf8");
modules["wysiwyg/getBlock"] = 'import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";\n' +
extract("wysiwyg/getBlock", ["getContenteditableElement", "isContainerBlock", "getNextBlock", "getPreviousBlock"]);
@@ -150,7 +153,8 @@ const rendererModules = () => {
visitSelected(keydownSource);
assert.ok(selectedBranch);
modules["wysiwyg/blockSelection"] = readFileSync(path.join(root, "wysiwyg/blockSelection.ts"), "utf8");
- modules["wysiwyg/selectedNavigationKeydown"] = `import {getEditorRange, focusByRange, setLastNodeRange} from "../util/selection";
+ modules["wysiwyg/selectedNavigationKeydown"] = `import {getEditorRange} from "../util/selection";
+ import {focusByRange, setLastNodeRange} from "../util/selectionOffsets";
import {getAdjacentVerticalBlock, getAdjacentVisibleBlock} from "./verticalTarget";
import {focusVerticalBlockSelection} from "./verticalNavigation";
import {isDocumentBoundaryLoaded} from "../util/documentRange";