Skip to content

Commit

Permalink
🎨 fix #7047
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 12, 2023
1 parent 1c90c34 commit 8468982
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/config/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 => {
Expand Down
30 changes: 29 additions & 1 deletion app/src/dialog/processSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/editor/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 2 additions & 0 deletions app/src/menus/protyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}"]`);
Expand Down
3 changes: 1 addition & 2 deletions app/src/protyle/header/Title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class Title {
title: fileName,
});
this.setTitle(fileName);
setTitle(fileName);
setTitle(fileName, protyle);
}, Constants.TIMEOUT_INPUT);
}

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions app/src/protyle/util/onGet.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8468982

Please sign in to comment.