diff --git a/app/src/assets/scss/base.scss b/app/src/assets/scss/base.scss index d594a1a60..0be2768bc 100644 --- a/app/src/assets/scss/base.scss +++ b/app/src/assets/scss/base.scss @@ -247,6 +247,11 @@ progressLoading: 400 overflow: hidden; } + &__counter { + font-size: 12px; + flex-shrink: 0; + } + #barDock { .b3-menu__item:hover { background-color: var(--b3-list-hover); diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts new file mode 100644 index 000000000..8f163014b --- /dev/null +++ b/app/src/layout/status.ts @@ -0,0 +1,137 @@ +import {getAllDocks} from "./getAll"; +import {updateHotkeyTip} from "../protyle/util/compatibility"; +import {exportLayout, getDockByType, resizeTabs} from "./util"; +import {hasClosestByClassName} from "../protyle/util/hasClosest"; +import {fetchPost} from "../util/fetch"; +import {mountHelp} from "../util/mount"; +/// #if !BROWSER +import {getCurrentWindow} from "@electron/remote"; +/// #endif + +export const initStatus = () => { + const allDocks = getAllDocks(); + let menuHTML = ""; + allDocks.forEach(item => { + menuHTML += ``; + }); + document.getElementById("status").innerHTML = `
+ + + +
+ ${menuHTML} +
+
+
+
+
+
+ +
+
+ +
+
+ + + +
+
+ +
`; + const dockElement = document.getElementById("barDock"); + dockElement.addEventListener("mousemove", () => { + dockElement.querySelector(".b3-menu").classList.remove("fn__none"); + }); + dockElement.addEventListener("mouseleave", () => { + dockElement.querySelector(".b3-menu").classList.add("fn__none"); + }); + /// #if !BROWSER + document.querySelector("#barDebug").classList.remove("fn__none"); + /// #endif + document.querySelector("#status").addEventListener("click", (event) => { + let target = event.target as HTMLElement; + while (target.id !== "status") { + if (target.id === "barDock") { + const useElement = target.firstElementChild.firstElementChild; + const dockIsShow = useElement.getAttribute("xlink:href") === "#iconHideDock"; + if (dockIsShow) { + useElement.setAttribute("xlink:href", "#iconDock"); + target.setAttribute("aria-label", window.siyuan.languages.showDock); + } else { + useElement.setAttribute("xlink:href", "#iconHideDock"); + target.setAttribute("aria-label", window.siyuan.languages.hideDock); + } + document.querySelectorAll(".dock").forEach(item => { + if (dockIsShow) { + if (item.querySelector(".dock__item")) { + item.classList.add("fn__none"); + } + } else { + if (item.querySelector(".dock__item")) { + item.classList.remove("fn__none"); + } + } + }); + resizeTabs(); + target.querySelector(".b3-menu").classList.add("fn__none"); + event.stopPropagation(); + break; + } else if (target.classList.contains("b3-menu__item")) { + const type = target.getAttribute("data-type") as TDockType; + getDockByType(type).toggleModel(type); + if (type === "file" && getSelection().rangeCount > 0) { + const range = getSelection().getRangeAt(0); + const wysiwygElement = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true); + if (wysiwygElement) { + wysiwygElement.blur(); + } + } + target.parentElement.classList.add("fn__none"); + event.stopPropagation(); + break; + } else if (target.id === "barLock") { + exportLayout(false, () => { + fetchPost("/api/system/logoutAuth", {}, () => { + window.location.href = "/"; + }); + }); + event.stopPropagation(); + break; + } else if (target.id === "barHelp") { + mountHelp(); + event.stopPropagation(); + break; + } else if (target.id === "barDebug") { + /// #if !BROWSER + getCurrentWindow().webContents.openDevTools({mode: "bottom"}); + /// #endif + event.stopPropagation(); + break; + } else if (target.id === "barFeedback") { + if ("zh_CN" === window.siyuan.config.lang) { + window.open("https://ld246.com/article/1649901726096"); + } else { + window.open("https://github.com/siyuan-note/siyuan/issues"); + } + event.stopPropagation(); + break; + } + target = target.parentElement; + } + }); + if (window.siyuan.config.appearance.hideStatusBar) { + document.getElementById("status").classList.add("fn__none"); + } +}; + +export const countSelectWord = (range: Range) => { + const selectText = range.toString(); + if (selectText) { + fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => { + document.querySelector("#status .status__counter").innerHTML = `${window.siyuan.languages.blockRuneCount} ${response.data.runeCount}${window.siyuan.languages.blockWordCount} ${response.data.wordCount}`; + }) + } else { + document.querySelector("#status .status__counter").innerHTML = ""; + } +} diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts index 07b88bc96..7365b03af 100644 --- a/app/src/protyle/util/selection.ts +++ b/app/src/protyle/util/selection.ts @@ -1,5 +1,6 @@ import {getContenteditableElement, getNextBlock, getPreviousBlock, hasPreviousSibling} from "../wysiwyg/getBlock"; import {hasClosestByMatchTag} from "./hasClosest"; +import {countSelectWord} from "../../layout/status"; const selectIsEditor = (editor: Element, range?: Range) => { if (!range) { @@ -26,6 +27,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); return true; } } @@ -68,6 +70,7 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range) } } protyle.toolbar.render(protyle, range); + countSelectWord(range); return true; } } diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index fa7eab8fb..6376189ed 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -54,6 +54,7 @@ import {MenuItem} from "../../menus/Menu"; import {fetchPost} from "../../util/fetch"; import {onGet} from "../util/onGet"; import {setTableAlign} from "../util/table"; +import {countSelectWord} from "../../layout/status"; export class WYSIWYG { public lastHTMLs: { [key: string]: string } = {}; @@ -1266,6 +1267,7 @@ export class WYSIWYG { if ((event.shiftKey || isCtrl(event)) && !event.isComposing && range.toString() !== "") { // 工具栏 protyle.toolbar.render(protyle, range, event); + countSelectWord(range); } 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) { @@ -1277,6 +1279,7 @@ export class WYSIWYG { } this.setEmptyOutline(protyle, nodeElement); } + countSelectWord(range); event.stopPropagation(); } }); @@ -1705,6 +1708,7 @@ export class WYSIWYG { } else { hideElements(["toolbar"], protyle); } + countSelectWord(range); pushBack(protyle, newRange); }, isMobile() ? 520 : 0); // Android 双击慢了出不来 diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 4dfc4b734..0b68802da 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -21,9 +21,8 @@ import {focusByRange} from "../protyle/util/selection"; import {exitSiYuan} from "../dialog/processSystem"; import {openSetting} from "../config"; import {getSearch} from "./functions"; -import {getAllDocks} from "../layout/getAll"; -import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {openHistory} from "./history"; +import {initStatus} from "../layout/status"; const matchKeymap = (keymap: Record, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => { if (key1 === "general") { @@ -156,122 +155,6 @@ export const onGetConfig = () => { } }; -const initStatus = () => { - const allDocks = getAllDocks(); - let menuHTML = ""; - allDocks.forEach(item => { - menuHTML += ``; - }); - document.getElementById("status").innerHTML = `
- - - -
- ${menuHTML} -
-
-
-
-
- -
-
- -
-
- - - -
-
- -
`; - const dockElement = document.getElementById("barDock"); - dockElement.addEventListener("mousemove", () => { - dockElement.querySelector(".b3-menu").classList.remove("fn__none"); - }); - dockElement.addEventListener("mouseleave", () => { - dockElement.querySelector(".b3-menu").classList.add("fn__none"); - }); - /// #if !BROWSER - document.querySelector("#barDebug").classList.remove("fn__none"); - /// #endif - document.querySelector("#status").addEventListener("click", (event) => { - let target = event.target as HTMLElement; - while (target.id !== "status") { - if (target.id === "barDock") { - const useElement = target.firstElementChild.firstElementChild; - const dockIsShow = useElement.getAttribute("xlink:href") === "#iconHideDock"; - if (dockIsShow) { - useElement.setAttribute("xlink:href", "#iconDock"); - target.setAttribute("aria-label", window.siyuan.languages.showDock); - } else { - useElement.setAttribute("xlink:href", "#iconHideDock"); - target.setAttribute("aria-label", window.siyuan.languages.hideDock); - } - document.querySelectorAll(".dock").forEach(item => { - if (dockIsShow) { - if (item.querySelector(".dock__item")) { - item.classList.add("fn__none"); - } - } else { - if (item.querySelector(".dock__item")) { - item.classList.remove("fn__none"); - } - } - }); - resizeTabs(); - target.querySelector(".b3-menu").classList.add("fn__none"); - event.stopPropagation(); - break; - } else if (target.classList.contains("b3-menu__item")) { - const type = target.getAttribute("data-type") as TDockType; - getDockByType(type).toggleModel(type); - if (type === "file" && getSelection().rangeCount > 0) { - const range = getSelection().getRangeAt(0); - const wysiwygElement = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true); - if (wysiwygElement) { - wysiwygElement.blur(); - } - } - target.parentElement.classList.add("fn__none"); - event.stopPropagation(); - break; - } else if (target.id === "barLock") { - exportLayout(false, () => { - fetchPost("/api/system/logoutAuth", {}, () => { - window.location.href = "/"; - }); - }); - event.stopPropagation(); - break; - } else if (target.id === "barHelp") { - mountHelp(); - event.stopPropagation(); - break; - } else if (target.id === "barDebug") { - /// #if !BROWSER - getCurrentWindow().webContents.openDevTools({mode: "bottom"}); - /// #endif - event.stopPropagation(); - break; - } else if (target.id === "barFeedback") { - if ("zh_CN" === window.siyuan.config.lang) { - window.open("https://ld246.com/article/1649901726096"); - } else { - window.open("https://github.com/siyuan-note/siyuan/issues"); - } - event.stopPropagation(); - break; - } - target = target.parentElement; - } - }); - if (window.siyuan.config.appearance.hideStatusBar) { - document.getElementById("status").classList.add("fn__none"); - } -}; - const initBar = () => { document.querySelector(".toolbar").innerHTML = `