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";
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
import {isMobile} from "../util/functions";
/// #endif
export const initStatus = () => {
@ -126,23 +127,29 @@ export const initStatus = () => {
};
export const countSelectWord = (range: Range) => {
if (isMobile()) {
return;
}
const selectText = range.toString();
if (selectText) {
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}`;
})
});
} else {
document.querySelector("#status .status__counter").innerHTML = "";
}
}
};
export const countBlockWord = (ids: string[]) => {
if (isMobile()) {
return;
}
if (ids.length > 0) {
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}`;
})
});
} else {
document.querySelector("#status .status__counter").innerHTML = "";
}
}
};

View file

@ -414,7 +414,7 @@ export const resizeTabs = () => {
setPadding(item.editor.protyle);
if (typeof echarts !== "undefined") {
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) {
chartInstance.resize();
}

View file

@ -109,7 +109,7 @@ class Protyle {
this.protyle.model.parent.updateTitle(data.data.title);
}
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) {

View file

@ -86,9 +86,9 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
const ids: string [] = [];
Array.from(protyle.wysiwyg.element.children).forEach(item => {
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) => {

View file

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

View file

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

View file

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

View file

@ -189,7 +189,7 @@ export class Search extends Model {
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
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) {
matchElement.scrollIntoView();
}
@ -204,7 +204,7 @@ export class Search extends Model {
breadcrumbDocName: true,
},
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) {
matchElement.scrollIntoView();
}

View file

@ -648,7 +648,7 @@ const getArticle = (options: {
breadcrumbDocName: true
},
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) {
matchElement.scrollIntoView();
}
@ -664,7 +664,7 @@ const getArticle = (options: {
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
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) {
matchElement.scrollIntoView();
}

View file

@ -1,5 +1,5 @@
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";
/// #if !BROWSER
import {ipcRenderer} from "electron";