This commit is contained in:
Vanessa 2022-06-28 10:20:55 +08:00
parent ff9b6172e8
commit 321ac0cf19
10 changed files with 41 additions and 34 deletions

View file

@ -6,6 +6,7 @@ import {fetchPost} from "../util/fetch";
import {mountHelp} from "../util/mount"; import {mountHelp} from "../util/mount";
/// #if !BROWSER /// #if !BROWSER
import {getCurrentWindow} from "@electron/remote"; import {getCurrentWindow} from "@electron/remote";
import {isMobile} from "../util/functions";
/// #endif /// #endif
export const initStatus = () => { export const initStatus = () => {
@ -126,23 +127,29 @@ export const initStatus = () => {
}; };
export const countSelectWord = (range: Range) => { export const countSelectWord = (range: Range) => {
if (isMobile()) {
return;
}
const selectText = range.toString(); const selectText = range.toString();
if (selectText) { if (selectText) {
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => { fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.blockRuneCount}</span> ${response.data.runeCount}<span class="ft__on-surface">${window.siyuan.languages.blockWordCount}</span> ${response.data.wordCount}`; document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.blockRuneCount}</span> ${response.data.runeCount}<span class="ft__on-surface">${window.siyuan.languages.blockWordCount}</span> ${response.data.wordCount}`;
}) });
} else { } else {
document.querySelector("#status .status__counter").innerHTML = ""; document.querySelector("#status .status__counter").innerHTML = "";
} }
} };
export const countBlockWord = (ids: string[]) => { export const countBlockWord = (ids: string[]) => {
if (isMobile()) {
return;
}
if (ids.length > 0) { if (ids.length > 0) {
fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => { fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.blockRuneCount}</span> ${response.data.runeCount}<span class="ft__on-surface">${window.siyuan.languages.blockWordCount}</span> ${response.data.wordCount}`; document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.blockRuneCount}</span> ${response.data.runeCount}<span class="ft__on-surface">${window.siyuan.languages.blockWordCount}</span> ${response.data.wordCount}`;
}) });
} else { } else {
document.querySelector("#status .status__counter").innerHTML = ""; document.querySelector("#status .status__counter").innerHTML = "";
} }
} };

View file

@ -414,7 +414,7 @@ export const resizeTabs = () => {
setPadding(item.editor.protyle); setPadding(item.editor.protyle);
if (typeof echarts !== "undefined") { if (typeof echarts !== "undefined") {
item.editor.protyle.wysiwyg.element.querySelectorAll('[data-subtype="echarts"], [data-subtype="mindmap"]').forEach((chartItem: HTMLElement) => { item.editor.protyle.wysiwyg.element.querySelectorAll('[data-subtype="echarts"], [data-subtype="mindmap"]').forEach((chartItem: HTMLElement) => {
const chartInstance = echarts.getInstanceById(chartItem.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_")) const chartInstance = echarts.getInstanceById(chartItem.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_"));
if (chartInstance) { if (chartInstance) {
chartInstance.resize(); chartInstance.resize();
} }

View file

@ -109,7 +109,7 @@ class Protyle {
this.protyle.model.parent.updateTitle(data.data.title); this.protyle.model.parent.updateTitle(data.data.title);
} }
if (this.protyle.background) { if (this.protyle.background) {
this.protyle.background.ial.title = data.data.title this.protyle.background.ial.title = data.data.title;
} }
} }
if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) { if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) {

View file

@ -86,9 +86,9 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
const ids: string [] = []; const ids: string [] = [];
Array.from(protyle.wysiwyg.element.children).forEach(item => { Array.from(protyle.wysiwyg.element.children).forEach(item => {
item.classList.add("protyle-wysiwyg--select"); item.classList.add("protyle-wysiwyg--select");
ids.push(item.getAttribute("data-node-id")) ids.push(item.getAttribute("data-node-id"));
}); });
countBlockWord(ids) countBlockWord(ids);
}; };
export const getEditorRange = (element: Element) => { export const getEditorRange = (element: Element) => {

View file

@ -204,7 +204,7 @@ export class WYSIWYG {
if (selectElements.length === 0 && range.toString() === "" && !range.cloneContents().querySelector("img") && if (selectElements.length === 0 && range.toString() === "" && !range.cloneContents().querySelector("img") &&
!selectImgElement) { !selectImgElement) {
nodeElement.classList.add("protyle-wysiwyg--select"); nodeElement.classList.add("protyle-wysiwyg--select");
countBlockWord([nodeElement.getAttribute("data-node-id")]) countBlockWord([nodeElement.getAttribute("data-node-id")]);
selectElements = [nodeElement]; selectElements = [nodeElement];
} }
let html = ""; let html = "";
@ -494,7 +494,7 @@ export class WYSIWYG {
} }
}); });
let mousewheelTime = 0 let mousewheelTime = 0;
this.element.addEventListener("mousewheel", (event: WheelEvent) => { this.element.addEventListener("mousewheel", (event: WheelEvent) => {
// https://ld246.com/article/1648865235549 // https://ld246.com/article/1648865235549
if (event.timeStamp - mousewheelTime > 6000 && if (event.timeStamp - mousewheelTime > 6000 &&
@ -885,14 +885,14 @@ export class WYSIWYG {
// 只有一个 p 时不选中 // 只有一个 p 时不选中
protyle.selectElement.style.backgroundColor = "transparent"; protyle.selectElement.style.backgroundColor = "transparent";
} else { } else {
const ids: string[] = [] const ids: string[] = [];
selectElements.forEach(item => { selectElements.forEach(item => {
if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) { if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) {
item.classList.add("protyle-wysiwyg--select"); item.classList.add("protyle-wysiwyg--select");
ids.push(item.getAttribute("data-node-id")) ids.push(item.getAttribute("data-node-id"));
} }
}); });
countBlockWord(ids) countBlockWord(ids);
protyle.selectElement.style.backgroundColor = ""; protyle.selectElement.style.backgroundColor = "";
} }
}; };
@ -1280,7 +1280,7 @@ export class WYSIWYG {
if (nodeElement) { if (nodeElement) {
if (isNotEditBlock(nodeElement) && !this.element.querySelector(".protyle-wysiwyg--select")) { if (isNotEditBlock(nodeElement) && !this.element.querySelector(".protyle-wysiwyg--select")) {
nodeElement.classList.add("protyle-wysiwyg--select"); nodeElement.classList.add("protyle-wysiwyg--select");
countBlockWord([nodeElement.getAttribute("data-node-id")]) countBlockWord([nodeElement.getAttribute("data-node-id")]);
} else if (!nodeElement.classList.contains("protyle-wysiwyg--select")) { } else if (!nodeElement.classList.contains("protyle-wysiwyg--select")) {
countSelectWord(range); countSelectWord(range);
} }
@ -1791,10 +1791,10 @@ export class WYSIWYG {
// 单个 p 不选中 // 单个 p 不选中
shiftStartElement = undefined; shiftStartElement = undefined;
} else { } else {
const ids: string[] = [] const ids: string[] = [];
selectElements.forEach(item => { selectElements.forEach(item => {
item.classList.add("protyle-wysiwyg--select"); item.classList.add("protyle-wysiwyg--select");
ids.push(item.getAttribute("data-node-id")) ids.push(item.getAttribute("data-node-id"));
}); });
countBlockWord(ids); countBlockWord(ids);
if (toDown) { if (toDown) {
@ -1828,9 +1828,9 @@ export class WYSIWYG {
if (ctrlParentElement && !ctrlElement.isSameNode(ctrlParentElement)) { if (ctrlParentElement && !ctrlElement.isSameNode(ctrlParentElement)) {
ctrlParentElement.classList.remove("protyle-wysiwyg--select"); ctrlParentElement.classList.remove("protyle-wysiwyg--select");
} }
const ids: string[] = [] const ids: string[] = [];
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => { protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
ids.push(item.getAttribute("data-node-id")) ids.push(item.getAttribute("data-node-id"));
}); });
countBlockWord(ids); countBlockWord(ids);
} }

View file

@ -153,7 +153,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
} }
nextElement.classList.add("protyle-wysiwyg--select"); nextElement.classList.add("protyle-wysiwyg--select");
countBlockWord([nextElement.getAttribute("data-node-id")]) countBlockWord([nextElement.getAttribute("data-node-id")]);
const bottom = nextElement.getBoundingClientRect().bottom - protyle.contentElement.getBoundingClientRect().bottom; const bottom = nextElement.getBoundingClientRect().bottom - protyle.contentElement.getBoundingClientRect().bottom;
if (bottom > 0) { if (bottom > 0) {
protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + bottom; protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + bottom;
@ -190,7 +190,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
} }
if (previousElement) { if (previousElement) {
previousElement.classList.add("protyle-wysiwyg--select"); previousElement.classList.add("protyle-wysiwyg--select");
countBlockWord([previousElement.getAttribute("data-node-id")]) countBlockWord([previousElement.getAttribute("data-node-id")]);
const top = previousElement.getBoundingClientRect().top - protyle.contentElement.getBoundingClientRect().top; const top = previousElement.getBoundingClientRect().top - protyle.contentElement.getBoundingClientRect().top;
if (top < 0) { if (top < 0) {
protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + top; protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + top;
@ -315,10 +315,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
selectElements[0].parentElement.classList.add("protyle-wysiwyg--select"); selectElements[0].parentElement.classList.add("protyle-wysiwyg--select");
} }
} }
const ids: string[] = [] const ids: string[] = [];
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => { protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
ids.push(item.getAttribute("data-node-id")) ids.push(item.getAttribute("data-node-id"));
}) });
countBlockWord(ids); countBlockWord(ids);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -362,10 +362,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
selectLastElement.parentElement.classList.add("protyle-wysiwyg--select"); selectLastElement.parentElement.classList.add("protyle-wysiwyg--select");
} }
} }
const ids: string[] = [] const ids: string[] = [];
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => { protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
ids.push(item.getAttribute("data-node-id")) ids.push(item.getAttribute("data-node-id"));
}) });
countBlockWord(ids); countBlockWord(ids);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -966,7 +966,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
protyle.hint.enableEmoji = false; protyle.hint.enableEmoji = false;
} else if (nodeElement.classList.contains("protyle-wysiwyg--select")) { } else if (nodeElement.classList.contains("protyle-wysiwyg--select")) {
hideElements(["select"], protyle); hideElements(["select"], protyle);
countBlockWord([]) countBlockWord([]);
} else if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) { } else if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
// 防止 ESC 时选中当前块 // 防止 ESC 时选中当前块
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
@ -975,7 +975,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
item.classList.remove("protyle-wysiwyg--select"); item.classList.remove("protyle-wysiwyg--select");
}); });
nodeElement.classList.add("protyle-wysiwyg--select"); nodeElement.classList.add("protyle-wysiwyg--select");
countBlockWord([nodeElement.getAttribute("data-node-id")]) countBlockWord([nodeElement.getAttribute("data-node-id")]);
} }
event.preventDefault(); event.preventDefault();
return; return;

View file

@ -413,7 +413,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
return; return;
} }
previousLastElement.classList.add("protyle-wysiwyg--select"); previousLastElement.classList.add("protyle-wysiwyg--select");
countBlockWord([previousId]) countBlockWord([previousId]);
if (previousLastElement.getAttribute("data-type") === "NodeBlockQueryEmbed" || editableElement.textContent !== "") { if (previousLastElement.getAttribute("data-type") === "NodeBlockQueryEmbed" || editableElement.textContent !== "") {
focusByRange(range); focusByRange(range);
return; return;

View file

@ -189,7 +189,7 @@ export class Search extends Model {
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => { }, getResponse => {
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]); onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`) const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);
if (matchElement) { if (matchElement) {
matchElement.scrollIntoView(); matchElement.scrollIntoView();
} }
@ -204,7 +204,7 @@ export class Search extends Model {
breadcrumbDocName: true, breadcrumbDocName: true,
}, },
after: () => { after: () => {
const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`) const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);
if (matchElement) { if (matchElement) {
matchElement.scrollIntoView(); matchElement.scrollIntoView();
} }

View file

@ -648,7 +648,7 @@ const getArticle = (options: {
breadcrumbDocName: true breadcrumbDocName: true
}, },
after: () => { after: () => {
const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`) const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);
if (matchElement) { if (matchElement) {
matchElement.scrollIntoView(); matchElement.scrollIntoView();
} }
@ -664,7 +664,7 @@ const getArticle = (options: {
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]); onGet(getResponse, protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`) const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);
if (matchElement) { if (matchElement) {
matchElement.scrollIntoView(); matchElement.scrollIntoView();
} }

View file

@ -1,5 +1,5 @@
import {openSearch} from "../search/spread"; import {openSearch} from "../search/spread";
import {exportLayout, getDockByType, JSONToLayout, resizeDrag, resizeTabs} from "../layout/util"; import {exportLayout, JSONToLayout, resizeDrag, resizeTabs} from "../layout/util";
import {hotKey2Electron, updateHotkeyTip} from "../protyle/util/compatibility"; import {hotKey2Electron, updateHotkeyTip} from "../protyle/util/compatibility";
/// #if !BROWSER /// #if !BROWSER
import {ipcRenderer} from "electron"; import {ipcRenderer} from "electron";