From 84689820058e0ac5f2b429a62b51b3e5d748b6f7 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 12 Jan 2023 21:53:27 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/7047 --- app/src/config/editor.ts | 2 ++ app/src/dialog/processSystem.ts | 30 +++++++++++++++++++++++++++++- app/src/editor/util.ts | 2 +- app/src/menus/protyle.ts | 2 ++ app/src/protyle/header/Title.ts | 3 +-- app/src/protyle/util/onGet.ts | 4 ++-- 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/src/config/editor.ts b/app/src/config/editor.ts index 8b7a93afc..c3ce51a24 100644 --- a/app/src/config/editor.ts +++ b/app/src/config/editor.ts @@ -6,6 +6,7 @@ import {setPadding} from "../protyle/ui/initUI"; import {reloadProtyle} from "../protyle/util/reload"; import {disabledProtyle, enableProtyle} from "../protyle/util/onGet"; import {updateHotkeyTip} from "../protyle/util/compatibility"; +import {updateTitle} from "../dialog/processSystem"; export const editor = { element: undefined as Element, @@ -22,6 +23,7 @@ export const editor = { target.setAttribute("aria-label", `${window.siyuan.languages.use} ${window.siyuan.languages.editReadonly} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}`); target.querySelector("use").setAttribute("xlink:href", "#iconEdit"); } + updateTitle(readOnly); fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => { const allModels = getAllModels(); allModels.editor.forEach(editor => { diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 9e5f6ea44..f72fa9fc9 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -271,7 +271,7 @@ export const bootSync = () => { }); }; -export const setTitle = (title: string) => { +export const setTitle = (title: string, protyle?: IProtyle) => { const dragElement = document.getElementById("drag"); const workspaceName = getWorkspaceName(); if (title === window.siyuan.languages.siyuanNote) { @@ -281,12 +281,40 @@ export const setTitle = (title: string) => { dragElement.setAttribute("title", versionTitle); } else { title = title || "Untitled"; + if (protyle && protyle.disabled) { + title = `[${window.siyuan.languages.editReadonly}] ${title}` + } + if (protyle && protyle.block.showAll) { + title = `[${window.siyuan.languages.enter}] ${title}` + } document.title = `${title} - ${workspaceName} - ${window.siyuan.languages.siyuanNote} v${Constants.SIYUAN_VERSION}`; dragElement.textContent = title; dragElement.setAttribute("title", title); } }; +export const updateTitle = (readonly?: boolean, zoomIn?: boolean) => { + const title = document.getElementById("drag").textContent; + if (typeof readonly === "boolean") { + if (readonly) { + if (title.indexOf(window.siyuan.languages.editReadonly) === -1) { + setTitle(`[${window.siyuan.languages.editReadonly}] ${title}`) + } + } else { + setTitle(title.replace(`[${window.siyuan.languages.editReadonly}] `, "")) + } + } + if (typeof zoomIn === "boolean") { + if (zoomIn) { + if (title.indexOf(window.siyuan.languages.enter) === -1) { + setTitle(`[${window.siyuan.languages.enter}] ${title}`); + } + } else { + setTitle(title.replace(`[${window.siyuan.languages.enter}] `, "")) + } + } +} + export const downloadProgress = (data: { id: string, percent: number }) => { const bazzarElement = document.getElementById("configBazaarReadme"); if (!bazzarElement) { diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 98b9da7e5..109933fb1 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -357,7 +357,7 @@ export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackSt const models = getAllModels(); updateOutline(models, protyle, reload); updateBacklinkGraph(models, protyle); - setTitle(title); + setTitle(title, protyle); }; export const isCurrentEditor = (blockId: string) => { diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 7fa643f59..261ea812e 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -45,6 +45,7 @@ import {exportAsset} from "./util"; import {removeLink} from "../protyle/toolbar/Link"; import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey"; import {getEnableHTML} from "../protyle/wysiwyg/removeEmbed"; +import {updateTitle} from "../dialog/processSystem"; export const refMenu = (protyle: IProtyle, element: HTMLElement) => { const nodeElement = hasClosestBlock(element); @@ -473,6 +474,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB } else { onGet(getResponse, protyle, id === protyle.block.rootID ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HTML, Constants.CB_GET_UNUNDO] : [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO, Constants.CB_GET_HTML]); } + updateTitle(undefined, id !== protyle.block.rootID); // https://github.com/siyuan-note/siyuan/issues/4874 if (focusId) { const focusElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${focusId}"]`); diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 53363e626..1266a9b6a 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -282,7 +282,7 @@ export class Title { title: fileName, }); this.setTitle(fileName); - setTitle(fileName); + setTitle(fileName, protyle); }, Constants.TIMEOUT_INPUT); } @@ -368,7 +368,6 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14)) if (this.editElement.getAttribute("data-render") === "true" && !refresh) { return false; } - setTitle(response.data.ial.title); protyle.background.render(response.data.ial, protyle.block.rootID); protyle.wysiwyg.renderCustom(response.data.ial); this.editElement.setAttribute("data-render", "true"); diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 5ba8f38cd..674e22935 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -1,4 +1,4 @@ -import {lockFile} from "../../dialog/processSystem"; +import {lockFile, setTitle} from "../../dialog/processSystem"; import {Constants} from "../../constants"; import {hideElements} from "../ui/hideElements"; import {genEmptyElement} from "../../block/util"; @@ -121,7 +121,7 @@ export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] unScroll: (scrollObj && scrollObj.focusId) ? true : false, isSyncing: data.data.isSyncing, }, protyle); - + setTitle(response.data.ial.title, protyle); if (scrollObj && protyle.options.mode !== "preview") { restoreScroll(protyle, scrollObj); }