From c1035076298bdd441134bdc5ce52add18b4d6152 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 12 Apr 2023 12:10:20 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/7947 --- app/src/assets/scss/util/_function.scss | 4 + app/src/mobile/settings/editor.ts | 233 ++++++++++++++++++++++-- app/src/types/index.d.ts | 2 +- 3 files changed, 220 insertions(+), 19 deletions(-) diff --git a/app/src/assets/scss/util/_function.scss b/app/src/assets/scss/util/_function.scss index bc410f810..426d75681 100644 --- a/app/src/assets/scss/util/_function.scss +++ b/app/src/assets/scss/util/_function.scss @@ -81,6 +81,10 @@ } } + &__displayblock { + display: block; + } + &__block { width: 100%; } diff --git a/app/src/mobile/settings/editor.ts b/app/src/mobile/settings/editor.ts index 40ca33a76..b35eb8004 100644 --- a/app/src/mobile/settings/editor.ts +++ b/app/src/mobile/settings/editor.ts @@ -2,6 +2,7 @@ import {openModel} from "../menu/model"; import {fetchPost} from "../../util/fetch"; import {reloadProtyle} from "../../protyle/util/reload"; import {setInlineStyle} from "../../util/assets"; +import {confirmDialog} from "../../dialog/confirmDialog"; const reloadEditor = (data: IEditor) => { window.siyuan.config.editor = data; @@ -9,37 +10,233 @@ const reloadEditor = (data: IEditor) => { setInlineStyle(); }; +const setEditor = (modelMainElement: Element) => { + let dynamicLoadBlocks = parseInt((modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value); + if (48 > dynamicLoadBlocks) { + dynamicLoadBlocks = 48; + (modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value = "48"; + } + if (1024 < dynamicLoadBlocks) { + dynamicLoadBlocks = 1024; + (modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value = "1024"; + } + window.siyuan.config.editor.dynamicLoadBlocks = dynamicLoadBlocks; + window.siyuan.config.editor.justify = (modelMainElement.querySelector("#justify") as HTMLInputElement).checked; + window.siyuan.config.editor.rtl = (modelMainElement.querySelector("#rtl") as HTMLInputElement).checked; + window.siyuan.config.editor.displayBookmarkIcon = (modelMainElement.querySelector("#displayBookmarkIcon") as HTMLInputElement).checked; + window.siyuan.config.editor.displayNetImgMark = (modelMainElement.querySelector("#displayNetImgMark") as HTMLInputElement).checked; + window.siyuan.config.editor.codeSyntaxHighlightLineNum = (modelMainElement.querySelector("#codeSyntaxHighlightLineNum") as HTMLInputElement).checked; + window.siyuan.config.editor.embedBlockBreadcrumb = (modelMainElement.querySelector("#embedBlockBreadcrumb") as HTMLInputElement).checked; + window.siyuan.config.editor.listLogicalOutdent = (modelMainElement.querySelector("#listLogicalOutdent") as HTMLInputElement).checked; + window.siyuan.config.editor.spellcheck = (modelMainElement.querySelector("#spellcheck") as HTMLInputElement).checked; + window.siyuan.config.editor.plantUMLServePath = (modelMainElement.querySelector("#plantUMLServePath") as HTMLInputElement).value; + window.siyuan.config.editor.katexMacros = (modelMainElement.querySelector("#katexMacros") as HTMLTextAreaElement).value; + window.siyuan.config.editor.codeLineWrap = (modelMainElement.querySelector("#codeLineWrap") as HTMLInputElement).checked; + window.siyuan.config.editor.virtualBlockRef = (modelMainElement.querySelector("#virtualBlockRef") as HTMLInputElement).checked; + window.siyuan.config.editor.virtualBlockRefInclude = (modelMainElement.querySelector("#virtualBlockRefInclude") as HTMLInputElement).value; + window.siyuan.config.editor.virtualBlockRefExclude = (modelMainElement.querySelector("#virtualBlockRefExclude") as HTMLInputElement).value; + window.siyuan.config.editor.blockRefDynamicAnchorTextMaxLen = parseInt((modelMainElement.querySelector("#blockRefDynamicAnchorTextMaxLen") as HTMLInputElement).value); + window.siyuan.config.editor.backlinkExpandCount = parseInt((modelMainElement.querySelector("#backlinkExpandCount") as HTMLInputElement).value); + window.siyuan.config.editor.backmentionExpandCount = parseInt((modelMainElement.querySelector("#backmentionExpandCount") as HTMLInputElement).value); + window.siyuan.config.editor.codeLigatures = (modelMainElement.querySelector("#codeLigatures") as HTMLInputElement).checked; + window.siyuan.config.editor.codeTabSpaces = parseInt((modelMainElement.querySelector("#codeTabSpaces") as HTMLInputElement).value); + window.siyuan.config.editor.fontSize = parseInt((modelMainElement.querySelector("#fontSize") as HTMLInputElement).value); + window.siyuan.config.editor.generateHistoryInterval = parseInt((modelMainElement.querySelector("#generateHistoryInterval") as HTMLInputElement).value); + window.siyuan.config.editor.historyRetentionDays = parseInt((modelMainElement.querySelector("#historyRetentionDays") as HTMLInputElement).value); + fetchPost("/api/setting/setEditor", window.siyuan.config.editor, response => { + reloadEditor(response.data); + }); +}; + export const initEditor = () => { openModel({ title: window.siyuan.languages.editor, icon: "iconEdit", - html: `
- ${window.siyuan.languages.fontSize} ${window.siyuan.config.editor.fontSize}px + html: ` + + + + + + + + + + + + + + + + + + + +
-
+ + +
`, +`, bindEvent(modelMainElement: HTMLElement) { - modelMainElement.querySelector(".b3-slider").addEventListener("input", (event: InputEvent & { - target: HTMLInputElement - }) => { - modelMainElement.querySelector("#fontSize").textContent = event.target.value + "px"; - window.siyuan.config.editor.fontSize = parseInt(event.target.value); - fetchPost("/api/setting/setEditor", window.siyuan.config.editor, (response) => { - reloadEditor(response.data); + modelMainElement.querySelector("#clearHistory").addEventListener("click", () => { + confirmDialog(window.siyuan.languages.clearHistory, window.siyuan.languages.confirmClearHistory, () => { + fetchPost("/api/history/clearWorkspaceHistory", {}); }); }); - const katexMacrosElement = modelMainElement.querySelector("#katexMacros") as HTMLTextAreaElement; - katexMacrosElement.addEventListener("blur", () => { - window.siyuan.config.editor.katexMacros = katexMacrosElement.value; - fetchPost("/api/setting/setEditor", window.siyuan.config.editor, (response) => { - reloadEditor(response.data); + + modelMainElement.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => { + item.addEventListener("change", () => { + setEditor(modelMainElement); + }); + }); + modelMainElement.querySelectorAll("textarea.b3-text-field, input.b3-text-field, input.b3-slider").forEach((item) => { + item.addEventListener("blur", () => { + setEditor(modelMainElement); + }); + }); + modelMainElement.querySelectorAll("input.b3-slider").forEach((item) => { + item.addEventListener("input", (event) => { + const target = event.target as HTMLInputElement; + target.previousElementSibling.previousElementSibling.textContent = target.value; }); }); } diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 15bc63d99..7aa425a92 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -346,7 +346,7 @@ declare interface IEditor { codeLigatures: boolean; codeTabSpaces: number; fontFamily: string; - virtualBlockRef: string; + virtualBlockRef: boolean; virtualBlockRefExclude: string; virtualBlockRefInclude: string; blockRefDynamicAnchorTextMaxLen: number;