Skip to content

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

:bug: Skip block statistics requests in Protyle Lite https://github.com/siyuan-note/siyuan/issues/19137

Daniel720bf11518f5
diff --git a/app/src/editor/index.ts b/app/src/editor/index.ts
index 5b9fa75553..5e9972e5e7 100644
--- a/app/src/editor/index.ts
+++ b/app/src/editor/index.ts
@@ -71,7 +71,7 @@ export class Editor extends Model {
if (window.siyuan.editorIsFullscreen) {
editor.setFullscreen(true);
}
- countBlockWord([], editor.protyle.block.rootID);
+ countBlockWord([], editor.protyle);
/// #if !BROWSER
setModelsHash();
/// #endif
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index 940484226c..d57aa0b72a 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -653,7 +653,7 @@ export const updatePanelByEditor = (options: {
if (options.focus) {
if (options.protyle.toolbar.range) {
focusByRange(options.protyle.toolbar.range);
- countSelectWord(options.protyle.toolbar.range, options.protyle.block.rootID);
+ countSelectWord(options.protyle.toolbar.range, options.protyle);
if (options.pushBackStack && options.protyle.preview.element.classList.contains("fn__none")) {
pushBack(options.protyle, options.protyle.toolbar.range);
}
@@ -662,7 +662,7 @@ export const updatePanelByEditor = (options: {
if (options.pushBackStack && options.protyle.preview.element.classList.contains("fn__none")) {
pushBack(options.protyle, undefined, options.protyle.wysiwyg.element.firstElementChild);
}
- countBlockWord([], options.protyle.block.rootID);
+ countBlockWord([], options.protyle);
}
}
if (window.siyuan.config.fileTree.alwaysSelectOpenedFile && options.protyle) {
diff --git a/app/src/layout/status.test.ts b/app/src/layout/status.test.ts
new file mode 100644
index 0000000000..6cc28621c1
--- /dev/null
+++ b/app/src/layout/status.test.ts
@@ -0,0 +1,96 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import {test} from "node:test";
+import {runInNewContext} from "node:vm";
+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
+
+const compiled = transpileModule(readFileSync("src/layout/status.ts", "utf8"), {
+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
+}).outputText;
+
+const createStatus = () => {
+ const timers = new Map<number, () => void>();
+ const requests: {url: string, data: Record<string, unknown>, callback: (response: unknown) => void}[] = [];
+ let timerID = 0;
+ const exports = {} as {
+ countBlockWord: (ids: string[], context?: unknown, clearCache?: boolean) => void;
+ countSelectWord: (range: {toString: () => string}, context?: unknown) => void;
+ renderStatusbarCounter: (stat: unknown) => void;
+ };
+ const rendered: unknown[] = [];
+ runInNewContext(compiled, {
+ exports,
+ require: () => ({
+ Constants: {TIMEOUT_COUNT: 100},
+ fetchPost: (url: string, data: Record<string, unknown>, callback: (response: unknown) => void) => {
+ requests.push({url, data, callback});
+ },
+ }),
+ AbortController,
+ clearTimeout: (id: number) => timers.delete(id),
+ window: {
+ setTimeout: (callback: () => void) => {
+ timers.set(++timerID, callback);
+ return timerID;
+ },
+ },
+ document: {getElementById: () => ({classList: {contains: () => false}})},
+ getSelection: () => ({rangeCount: 0}),
+ });
+ exports.renderStatusbarCounter = stat => rendered.push(stat);
+ return {
+ ...exports,
+ requests,
+ rendered,
+ flush: () => {
+ const callbacks = Array.from(timers.values());
+ timers.clear();
+ callbacks.forEach(callback => callback());
+ },
+ };
+};
+
+test("lite selection and deletion statistics never query temporary block IDs", () => {
+ const status = createStatus();
+ const lite = {lite: true, block: {}};
+ status.countBlockWord(["temporary-block"], lite);
+ status.flush();
+ status.countBlockWord([], lite);
+ status.countBlockWord(["restored-block"], lite, true);
+ status.countSelectWord({toString: () => "draft"}, lite);
+ status.flush();
+ assert.equal(status.requests.length, 0);
+});
+
+test("normal editor block and text statistics remain available", () => {
+ const status = createStatus();
+ const protyle = {lite: false, block: {rootID: "document"}};
+ status.countBlockWord(["block"], protyle);
+ status.flush();
+ assert.equal(status.requests[0].url, "/api/block/getBlocksWordCount");
+ assert.deepEqual(status.requests[0].data.ids, ["block"]);
+ const stat = {wordCount: 1};
+ status.requests[0].callback({code: 0, data: {stat}});
+ assert.deepEqual(status.rendered, [stat]);
+ status.countSelectWord({toString: () => "selected text"}, protyle);
+ status.flush();
+ assert.equal(status.requests[1].url, "/api/block/getContentWordCount");
+ assert.equal(status.requests[1].data.content, "selected text");
+});
+
+test("failed statistics responses do not render and document statistics can retry", () => {
+ const status = createStatus();
+ status.countBlockWord(["missing"]);
+ status.flush();
+ assert.doesNotThrow(() => status.requests[0].callback({code: -1, data: null}));
+ status.countBlockWord([], "document");
+ status.flush();
+ assert.doesNotThrow(() => status.requests[1].callback({code: -1, data: null}));
+ status.countBlockWord([], "document");
+ status.flush();
+ assert.equal(status.requests[2].url, "/api/block/getTreeStat");
+ status.requests[2].callback({code: 0, data: {stat: {}, containsEmbed: true}});
+ assert.equal(status.requests[3].data.includeEmbed, true);
+ assert.doesNotThrow(() => status.requests[3].callback({code: -1, data: null}));
+ assert.equal(status.rendered.length, 1);
+});
diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts
index c9dd613161..5984e17d82 100644
--- a/app/src/layout/status.ts
+++ b/app/src/layout/status.ts
@@ -159,6 +159,10 @@ const scheduleStatusStat = (rootID: string, content?: string, ids?: string[]) =>
if (signal.aborted) {
return;
}
+ if (response.code !== 0 || !response.data?.stat) {
+ finishRequest();
+ return;
+ }
renderStatusbarCounter(response.data.stat);
finishRequest();
};
@@ -175,6 +179,11 @@ const scheduleStatusStat = (rootID: string, content?: string, ids?: string[]) =>
if (signal.aborted) {
return;
}
+ if (response.code !== 0 || !response.data?.stat) {
+ lastRootId = null;
+ finishRequest();
+ return;
+ }
renderStatusbarCounter(response.data.stat);
if (!response.data.containsEmbed) {
finishRequest();
@@ -184,6 +193,11 @@ const scheduleStatusStat = (rootID: string, content?: string, ids?: string[]) =>
if (signal.aborted) {
return;
}
+ if (embedResponse.code !== 0 || !embedResponse.data?.stat) {
+ lastRootId = null;
+ finishRequest();
+ return;
+ }
renderStatusbarCounter(
embedResponse.data.stat,
embedResponse.data.statWithEmbed,
@@ -199,8 +213,12 @@ const scheduleStatusStat = (rootID: string, content?: string, ids?: string[]) =>
}, Constants.TIMEOUT_COUNT);
};
-export const countSelectWord = (range: Range, rootID?: string) => {
+export const countSelectWord = (range: Range, context?: string | IProtyle) => {
/// #if !MOBILE
+ if (typeof context === "object" && context.lite) {
+ return;
+ }
+ const rootID = typeof context === "object" ? context.block.rootID : context;
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
@@ -208,8 +226,12 @@ export const countSelectWord = (range: Range, rootID?: string) => {
/// #endif
};
-export const countBlockWord = (ids: string[], rootID?: string, clearCache = false) => {
+export const countBlockWord = (ids: string[], context?: string | IProtyle, clearCache = false) => {
/// #if !MOBILE
+ if (typeof context === "object" && context.lite) {
+ return;
+ }
+ const rootID = typeof context === "object" ? context.block.rootID : context;
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 0b7bdbb5f3..3018dd5034 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -500,7 +500,7 @@ export class Gutter {
return;
}
hideElements(["gutter"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
insertEmptyBlock(protyle, buttonElement.dataset.type === "gutterPlusBefore" ? "beforebegin" : "afterend", nodeElement);
return;
}
@@ -1639,7 +1639,7 @@ export class Gutter {
const turnIntoSubmenu: IMenu[] = [];
hideElements(["select"], protyle);
nodeElement.classList.add("protyle-wysiwyg--select");
- countBlockWord([id], protyle.block.rootID);
+ countBlockWord([id], protyle);
if (isMobile() && !protyle.toolbar.isMultiSelectMode()) {
window.siyuan.menus.menu.append(new MenuItem({
id: "multiSelect",
@@ -2146,7 +2146,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.list.prependListItem.custom,
click() {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
void prependListItem(protyle, nodeElement as HTMLElement, range);
}
}, {
@@ -2156,7 +2156,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.list.appendListItem.custom,
click() {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
void appendListItem(protyle, nodeElement as HTMLElement, range);
}
});
@@ -2792,7 +2792,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.insertBefore.custom,
click() {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
insertEmptyBlock(protyle, "beforebegin", nodeElement);
}
}).element);
@@ -2803,7 +2803,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.insertAfter.custom,
click() {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
insertEmptyBlock(protyle, "afterend", nodeElement);
}
}).element);
@@ -2816,7 +2816,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.insertSuperBlockLeft.custom,
click() {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
insertEmptySuperBlockColumn(protyle, "left", nodeElement);
}
}).element);
@@ -2827,7 +2827,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.insertSuperBlockRight.custom,
click() {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
insertEmptySuperBlockColumn(protyle, "right", nodeElement);
}
}).element);
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index cb377c746b..5193b71446 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -864,7 +864,7 @@ export const hintMoveBlock = async (pathString: string, sourceElements: Element[
if (targetElement) {
setBlockSelectionModeElement(editorElement, targetElement);
focusBlock(targetElement);
- countBlockWord(getBlockSelectionStatusIDs(editorElement), protyle.block.rootID);
+ countBlockWord(getBlockSelectionStatusIDs(editorElement), protyle);
}
} : undefined,
});
@@ -905,7 +905,7 @@ export const hintMoveBlock = async (pathString: string, sourceElements: Element[
if (nextSelectionModeElement) {
setBlockSelectionModeElement(editorElement, nextSelectionModeElement);
focusBlock(nextSelectionModeElement);
- countBlockWord(getBlockSelectionStatusIDs(editorElement), protyle.block.rootID);
+ countBlockWord(getBlockSelectionStatusIDs(editorElement), protyle);
}
}
// 跨文档不支持撤销
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 70b02a0dc0..12c7bf9718 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -74,7 +74,7 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
range.setStart(cellElement.firstChild, 0);
range.setEndAfter(cellElement.lastChild);
protyle.toolbar.render(protyle, range);
- countSelectWord(range, protyle.block.rootID);
+ countSelectWord(range, protyle);
return true;
}
}
@@ -120,7 +120,7 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
// 列表回车后,左键全选无法选中
focusByRange(range);
protyle.toolbar.render(protyle, range);
- countSelectWord(range, protyle.block.rootID);
+ countSelectWord(range, protyle);
return true;
}
}
@@ -140,7 +140,7 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
ids.push(nodeId);
}
});
- countBlockWord(ids, protyle.block.rootID);
+ countBlockWord(ids, protyle);
return false;
};
@@ -171,7 +171,7 @@ export const selectBlocksByRange = (protyle: IProtyle, range: Range) => {
});
});
range.collapse(false);
- countBlockWord(selectElements.map(item => item.getAttribute("data-node-id")), protyle.block.rootID);
+ countBlockWord(selectElements.map(item => item.getAttribute("data-node-id")), protyle);
};
// https://github.com/siyuan-note/siyuan/issues/8196
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
index e181c2438f..1f5f205c1a 100644
--- a/app/src/protyle/wysiwyg/commonHotkey.ts
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -186,7 +186,7 @@ export const upSelect = (options: {
options.protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
ids.push(item.getAttribute("data-node-id"));
});
- countBlockWord(ids, options.protyle.block.rootID);
+ countBlockWord(ids, options.protyle);
options.event.stopPropagation();
options.event.preventDefault();
};
@@ -240,7 +240,7 @@ export const downSelect = (options: {
options.protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
ids.push(item.getAttribute("data-node-id"));
});
- countBlockWord(ids, options.protyle.block.rootID);
+ countBlockWord(ids, options.protyle);
options.event.stopPropagation();
options.event.preventDefault();
};
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 520f189a0e..4e848254c2 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -461,7 +461,7 @@ export class WYSIWYG {
});
}
});
- countBlockWord(ids);
+ countBlockWord(ids, protyle);
if (toDown) {
focusBlock(selectElements[selectElements.length - 1], protyle.wysiwyg.element, false);
} else {
@@ -779,7 +779,7 @@ export class WYSIWYG {
const copyElement = selectionModeElement || nodeElement;
if (!selectionModeElement) {
copyElement.classList.add(BLOCK_SELECTION_CLASS);
- countBlockWord([copyElement.getAttribute("data-node-id")]);
+ countBlockWord([copyElement.getAttribute("data-node-id")], protyle);
}
selectElements = [copyElement];
}
@@ -1129,7 +1129,7 @@ export class WYSIWYG {
const preserveMarks = isOnlyMeta(event) || event.shiftKey;
clearBlockSelectionMode(this.element, !preserveMarks);
if (!preserveMarks) {
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
}
if (getAVTemplateInteractiveElement(event.target)) {
@@ -1256,7 +1256,7 @@ export class WYSIWYG {
}
ctrlElement = getTopAloneElement(ctrlElement) as HTMLElement;
toggleBlockSelection(protyle.wysiwyg.element, ctrlElement);
- countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element));
+ countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element), protyle);
}
return;
}
@@ -1983,7 +1983,7 @@ export class WYSIWYG {
y: mouseUpEvent.clientY,
detail: mouseUpEvent.detail,
});
- countSelectWord(range, protyle.block.rootID);
+ countSelectWord(range, protyle);
}
}
});
@@ -2860,14 +2860,14 @@ export class WYSIWYG {
const selectElement = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
if (avDragSelectMode === "items" && avDragSelectElement) {
setAVDragItemAnchor(avDragSelectElement);
- countBlockWord([]);
+ countBlockWord([], protyle);
focusBlock(avDragSelectElement);
} else {
const ids: string[] = [];
selectElement.forEach(item => {
ids.push(item.getAttribute("data-node-id"));
});
- countBlockWord(ids);
+ countBlockWord(ids, protyle);
}
// 修正三击及跨块选区落在块边界时的 range
if (getSelection().rangeCount > 0) {
@@ -3043,7 +3043,7 @@ export class WYSIWYG {
autoSelectedElement.removeAttribute("select-start");
autoSelectedElement.removeAttribute("select-end");
if (selectionModeElement) {
- countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element), protyle.block.rootID);
+ countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element), protyle);
}
};
const selectedStateElements = [...selectElements];
@@ -3964,7 +3964,7 @@ export class WYSIWYG {
const selectionModeElement = getBlockSelectionModeElement(protyle.wysiwyg.element);
if (selectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
if (nodeElement) {
const startCell = hasClosestByTag(range.startContainer, "TD") || hasClosestByTag(range.startContainer, "TH");
@@ -4298,7 +4298,7 @@ export class WYSIWYG {
if ((event.shiftKey || isOnlyMeta(event)) && !event.isComposing && range.toString() !== "") {
// 工具栏
protyle.toolbar.render(protyle, range);
- countSelectWord(range);
+ countSelectWord(range, protyle);
}
if (event.eventPhase !== 3 && !event.shiftKey && (event.key.indexOf("Arrow") > -1 || event.key === "Home" || event.key === "End" || event.key === "PageUp" || event.key === "PageDown") && !event.isComposing) {
@@ -4307,7 +4307,7 @@ export class WYSIWYG {
clearSelect(["img", "av"], protyle.wysiwyg.element);
this.setEmptyOutline(protyle, nodeElement);
if (range.toString() === "" && !nodeElement.classList.contains("protyle-wysiwyg--select")) {
- countSelectWord(range, protyle.block.rootID);
+ countSelectWord(range, protyle);
}
if (protyle.breadcrumb) {
const indentElement = protyle.breadcrumb.element.parentElement.querySelector('[data-type="indent"]');
@@ -5142,7 +5142,7 @@ export class WYSIWYG {
refreshGutterByPointer(protyle, pointerElement);
}
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {
- countSelectWord(newRange, protyle.block.rootID);
+ countSelectWord(newRange, protyle);
}
if (getSelection().rangeCount === 0 && !mobileBlur) {
// https://github.com/siyuan-note/siyuan/issues/14589
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 3078bddf6b..dca5d53458 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -156,7 +156,7 @@ import {
} from "./blockSelection";
const countBlockSelectionMode = (protyle: IProtyle) => {
- countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element), protyle.block.rootID);
+ countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element), protyle);
};
const syncBlockSelectionModeToSelectionEnd = (protyle: IProtyle, direction: "up" | "down") => {
@@ -376,7 +376,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.wysiwyg.element.blur();
if (blockSelectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
// 阻止中文输入的残留
setTimeout(() => {
@@ -389,7 +389,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.wysiwyg.element.blur();
if (blockSelectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
setTimeout(() => {
insertEmptyBlock(protyle, "beforebegin", blockSelectionModeElement);
@@ -530,7 +530,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
countBlockSelectionMode(protyle);
} else {
nextElement.classList.add(BLOCK_SELECTION_CLASS);
- countBlockWord([nextElement.getAttribute("data-node-id")]);
+ countBlockWord([nextElement.getAttribute("data-node-id")], protyle);
}
const bottom = nextElement.getBoundingClientRect().bottom - protyle.contentElement.getBoundingClientRect().bottom;
if (bottom > 0) {
@@ -567,7 +567,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault();
if (blockSelectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
} else if (protyle.contentElement.scrollTop !== 0) {
protyle.contentElement.scrollTop = 0;
@@ -581,7 +581,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
countBlockSelectionMode(protyle);
} else {
previousElement.classList.add(BLOCK_SELECTION_CLASS);
- countBlockWord([previousElement.getAttribute("data-node-id")]);
+ countBlockWord([previousElement.getAttribute("data-node-id")], protyle);
}
const top = previousElement.getBoundingClientRect().top - protyle.contentElement.getBoundingClientRect().top;
if (top < 0) {
@@ -626,7 +626,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
let inputNodeElement = nodeElement;
if (blockSelectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
if (!isNotEditBlock(blockSelectionModeElement)) {
if (!blockSelectionModeElement.contains(inputRange.startContainer)) {
focusBlock(blockSelectionModeElement);
@@ -897,7 +897,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.wysiwyg.element.lastElementChild?.scrollIntoView(false);
}
protyle.toolbar.render(protyle, selectedRange);
- countSelectWord(selectedRange, protyle.block.rootID);
+ countSelectWord(selectedRange, protyle);
}
event.preventDefault();
event.stopPropagation();
@@ -1699,7 +1699,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
endTrackedRangeInsertion(trackedRangeInsertion);
}
if (blockSelectionModeElement) {
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
return;
}
@@ -1952,15 +1952,15 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
window.siyuan.menus.menu.remove(true);
} else if (blockSelectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
} else if (nodeElement.classList.contains(BLOCK_SELECTION_CLASS)) {
hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
} else {
hideElements(["select"], protyle);
range.collapse(false);
setBlockSelectionModeElement(protyle.wysiwyg.element, nodeElement);
- countBlockWord([nodeElement.getAttribute("data-node-id")], protyle.block.rootID);
+ countBlockWord([nodeElement.getAttribute("data-node-id")], protyle);
}
}
event.stopPropagation();
@@ -2648,7 +2648,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.wysiwyg.preventKeyup = true;
}
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
if (tabNodeElement.getAttribute("data-type") === "NodeCodeBlock") {
if (selectText !== "" || !event.shiftKey) {
@@ -2836,7 +2836,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
hideElements(["select"], protyle);
if (blockSelectionModeElement) {
clearBlockSelectionMode(protyle.wysiwyg.element, true);
- countBlockWord([], protyle.block.rootID);
+ countBlockWord([], protyle);
}
}
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index c029df8ce5..a422308b81 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -1228,7 +1228,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
setBlockSelectionModeElement(protyle.wysiwyg.element, targetElement);
focusBlock(targetElement);
countBlockWord(getBlockSelectionStatusIDs(protyle.wysiwyg.element),
- protyle.block.rootID);
+ protyle);
}
} : undefined,
});
@@ -1851,7 +1851,7 @@ export const removeBlockPreservingSelectionMode = async (protyle: IProtyle, bloc
setBlockSelectionModeElement(editorElement, nextSelectionModeElement);
focusBlock(nextSelectionModeElement);
}
- countBlockWord(getBlockSelectionStatusIDs(editorElement), protyle.block.rootID);
+ countBlockWord(getBlockSelectionStatusIDs(editorElement), protyle);
return removed;
};
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index b37e138a28..8a72481434 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -550,7 +550,7 @@ const promiseTransaction = (options: {
callback: (responseTransaction: {doOperations: IOperation[]}) => {
invalidateViewFoldRequests(protyle);
const ids = getBlockSelectionStatusIDs(protyle.wysiwyg.element);
- countBlockWord(ids, protyle.block.rootID, true);
+ countBlockWord(ids, protyle, true);
if (!options.skipSync) {
responseTransaction.doOperations.forEach((operation: IOperation) => {
if (handleViewFoldSourceOperation(protyle, operation)) {