@@ -609,7 +597,7 @@ export const bazaar = {
});
} else {
// sort
- const localSort = JSON.parse(localStorage.getItem(Constants.LOCAL_BAZAAR));
+ const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];
const panelElement = selectElement.parentElement.parentElement;
let html = "";
if (selectElement.value === "0") { // 更新时间降序
@@ -638,7 +626,6 @@ export const bazaar = {
});
}
localSort[selectElement.parentElement.parentElement.getAttribute("data-type")] = selectElement.value;
- localStorage.setItem(Constants.LOCAL_BAZAAR, JSON.stringify(localSort));
panelElement.querySelector(".b3-cards").innerHTML = html;
}
});
@@ -667,7 +654,7 @@ export const bazaar = {
bazaar.data[bazaarType] = response.data.packages;
element.innerHTML = `
${html}
`;
- const localSort = JSON.parse(localStorage.getItem(Constants.LOCAL_BAZAAR));
+ const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];
if (localSort[bazaarType.replace("s", "")] === "1") {
html = "";
Array.from(element.querySelectorAll(".b3-card")).sort((a, b) => {
diff --git a/app/src/constants.ts b/app/src/constants.ts
index ce134069e..848de3946 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -59,11 +59,11 @@ export abstract class Constants {
// localstorage
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
- public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; // "keys", "col", "row", "replaceKeys", "layout"
+ public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys";
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
- public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid";
- public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid";
- public static readonly LOCAL_CODELANG = "local-codelang";
+ public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string
+ public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string
+ public static readonly LOCAL_CODELANG = "local-codelang"; // string
public static readonly LOCAL_FONTSTYLES = "local-fontstyles";
public static readonly LOCAL_EXPORTPDF = "local-exportpdf";
public static readonly LOCAL_EXPORTWORD = "local-exportword";
diff --git a/app/src/history/history.ts b/app/src/history/history.ts
index 08261e755..3ee7badc9 100644
--- a/app/src/history/history.ts
+++ b/app/src/history/history.ts
@@ -25,7 +25,7 @@ const renderDoc = (element: HTMLElement, currentPage: number) => {
const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement;
const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement;
const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement;
- localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, notebookElement.value);
+ window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] = notebookElement.value;
const docElement = element.querySelector('.history__text[data-type="docPanel"]');
const assetElement = element.querySelector('.history__text[data-type="assetPanel"]');
const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;
@@ -211,7 +211,7 @@ export const openHistory = () => {
return;
}
- const currentNotebookId = localStorage.getItem(Constants.LOCAL_HISTORYNOTEID);
+ const currentNotebookId = window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID];
let notebookSelectHTML = "";
window.siyuan.notebooks.forEach((item) => {
if (!item.closed) {
diff --git a/app/src/index.ts b/app/src/index.ts
index b2544ecaf..72727a9e9 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -122,9 +122,9 @@ class App {
}),
menus: new Menus()
};
- setLocalStorage();
fetchPost("/api/system/getConf", {}, response => {
window.siyuan.config = response.data.conf;
+ setLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages;
bootSync();
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index d97b00221..8f7b98c56 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -455,10 +455,10 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
}
}
if (window.siyuan.mobileEditor) {
- localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({
+ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id,
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL]
- }));
+ };
if (isPushBack) {
pushBack();
}
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index 2e5240406..f3a01ff99 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -14,7 +14,7 @@ import {hideElements} from "../protyle/ui/hideElements";
import {pushBack} from "./util/MobileBackFoward";
export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => {
- localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({id, action}));
+ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
if (window.siyuan.mobileEditor) {
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) {
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 7e3b054d0..132a55ae8 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -44,10 +44,10 @@ class App {
window.siyuan.menus.menu.remove();
}
});
- setLocalStorage();
fetchPost("/api/system/getConf", {}, confResponse => {
confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP;
window.siyuan.config = confResponse.data.conf;
+ setLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages;
document.title = window.siyuan.languages.siyuanNote;
diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts
index 352a68d0b..77bcb87e3 100644
--- a/app/src/mobile/util/MobileBackFoward.ts
+++ b/app/src/mobile/util/MobileBackFoward.ts
@@ -12,10 +12,10 @@ const forwardStack: IBackStack[] = [];
const focusStack = (backStack: IBackStack) => {
const protyle = window.siyuan.mobileEditor.protyle;
- localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({
+ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id: backStack.id,
action: backStack.callback,
- }));
+ };
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (protyle.contentElement.classList.contains("fn__none")) {
setEditMode(protyle, "wysiwyg");
diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts
index 8633364a9..f66d9114b 100644
--- a/app/src/mobile/util/initFramework.ts
+++ b/app/src/mobile/util/initFramework.ts
@@ -127,7 +127,7 @@ export const initFramework = () => {
});
initEditorName();
if (getOpenNotebookCount() > 0) {
- const localDoc = JSON.parse(localStorage.getItem(Constants.LOCAL_DOCINFO) || '{"id": ""}');
+ const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
if (existResponse.data) {
openMobileFileById(localDoc.id, localDoc.action);
diff --git a/app/src/mobile/util/menu.ts b/app/src/mobile/util/menu.ts
index 72cd1b5df..50616c783 100644
--- a/app/src/mobile/util/menu.ts
+++ b/app/src/mobile/util/menu.ts
@@ -1,5 +1,5 @@
import {fetchPost} from "../../util/fetch";
-import {getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";
+import {exportLocalStorage, getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";
import {popSearch} from "./search";
import {initAppearance} from "../settings/appearance";
import {closePanel} from "./closePanel";
@@ -172,7 +172,9 @@ ${accountHTML}
event.stopPropagation();
break;
} else if (target.id === "menuSafeQuit") {
- exitSiYuan();
+ exportLocalStorage(() => {
+ exitSiYuan();
+ });
event.preventDefault();
event.stopPropagation();
break;
@@ -439,8 +441,10 @@ ${accountHTML}
event.stopPropagation();
break;
} else if (target.id === "menuLock") {
- fetchPost("/api/system/logoutAuth", {}, () => {
- window.location.href = "/";
+ exportLocalStorage(() => {
+ fetchPost("/api/system/logoutAuth", {}, () => {
+ window.location.href = "/";
+ });
});
event.preventDefault();
event.stopPropagation();
@@ -457,6 +461,7 @@ ${accountHTML}
event.stopPropagation();
break;
} else if (target.id === "menuSyncNow") {
+ exportLocalStorage();
syncGuide();
event.preventDefault();
event.stopPropagation();
diff --git a/app/src/mobile/util/search.ts b/app/src/mobile/util/search.ts
index d0bb5266b..ac310663c 100644
--- a/app/src/mobile/util/search.ts
+++ b/app/src/mobile/util/search.ts
@@ -37,17 +37,14 @@ export const toolbarSearchEvent = () => {
onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount);
});
}
- const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}");
- localData.k = inputElement.value;
- localStorage.setItem(Constants.LOCAL_SEARCHEDATA, JSON.stringify(localData));
+ window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k = inputElement.value;
}, Constants.TIMEOUT_SEARCH);
};
const initToolbarSearch = () => {
const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
inputElement.focus();
- const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}");
- inputElement.value = localData.k || "";
+ inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k;
inputElement.addEventListener("compositionend", (event: InputEvent) => {
if (event && event.isComposing) {
return;
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index ddad3b7bd..18dd21345 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -26,7 +26,7 @@ export const saveExport = (option: { type: string, id: string }) => {
renderPDF(option.id);
}
} else if (option.type === "word") {
- const localData = localStorage.getItem(Constants.LOCAL_EXPORTWORD);
+ const localData = window.siyuan.storage[Constants.LOCAL_EXPORTWORD];
const wordDialog = new Dialog({
title: "Word " + window.siyuan.languages.config,
content: `
@@ -35,14 +35,14 @@ export const saveExport = (option: { type: string, id: string }) => {
${window.siyuan.languages.exportPDF4}
-
+
@@ -58,7 +58,6 @@ export const saveExport = (option: { type: string, id: string }) => {
btnsElement[1].addEventListener("click", () => {
const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked;
const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked;
- localStorage.setItem(Constants.LOCAL_EXPORTWORD, JSON.stringify({removeAssets, mergeSubdocs}));
getExportPath(option, removeAssets, mergeSubdocs);
wordDialog.destroy();
});
@@ -71,15 +70,7 @@ export const saveExport = (option: { type: string, id: string }) => {
/// #if !BROWSER
let originalZoomFactor = 1;
const renderPDF = (id: string) => {
- const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({
- landscape: false,
- marginType: "0",
- scale: 1,
- pageSize: "A4",
- removeAssets: true,
- keepFold: false,
- mergeSubdocs: false,
- }));
+ const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
const servePath = window.location.protocol + "//" + window.location.host;
const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight");
let themeStyle = "";
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 532f4b107..5f6c71370 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -591,7 +591,7 @@ export class Gutter {
click() {
let html = "";
selectsElement.forEach(item => {
- item.querySelectorAll('[spellcheck]').forEach(editItem => {
+ item.querySelectorAll("[spellcheck]").forEach(editItem => {
const cloneNode = editItem.cloneNode(true) as HTMLElement;
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
slashItem.firstElementChild.remove();
@@ -980,7 +980,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
click() {
let text = "";
- nodeElement.querySelectorAll('[spellcheck]').forEach(item => {
+ nodeElement.querySelectorAll("[spellcheck]").forEach(item => {
const cloneNode = item.cloneNode(true) as HTMLElement;
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
slashItem.firstElementChild.remove();
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index e5667faec..506ad8d95 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -556,7 +556,7 @@ ${unicode2Emoji(emoji.unicode, true)}`;
}
let textContent = value;
if (value === "```") {
- textContent = value + (localStorage.getItem(Constants.LOCAL_CODELANG) || "") + Lute.Caret + "\n```";
+ textContent = value + window.siyuan.storage[Constants.LOCAL_CODELANG] + Lute.Caret + "\n```";
}
const editableElement = getContenteditableElement(nodeElement);
if (value === "![]()") { // https://github.com/siyuan-note/siyuan/issues/4586 1
diff --git a/app/src/protyle/markdown/highlightRender.ts b/app/src/protyle/markdown/highlightRender.ts
index f323c57c7..8dd1f729b 100644
--- a/app/src/protyle/markdown/highlightRender.ts
+++ b/app/src/protyle/markdown/highlightRender.ts
@@ -9,7 +9,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
let isPreview = false;
if (element.classList.contains("code-block")) {
// 编辑器内代码块编辑渲染
- codeElements = element.querySelectorAll('[spellcheck]');
+ codeElements = element.querySelectorAll("[spellcheck]");
} else {
if (element.classList.contains("item__readme")) {
// bazaar reademe
@@ -22,7 +22,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
codeElements = element.querySelectorAll(".code-block code");
isPreview = true;
} else {
- codeElements = element.querySelectorAll('.code-block [spellcheck]');
+ codeElements = element.querySelectorAll(".code-block [spellcheck]");
}
}
if (codeElements.length === 0) {
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index 27696b305..b22cd2341 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -46,7 +46,7 @@ export const fontMenu = (protyle: IProtyle) => {
const element = document.createElement("div");
element.classList.add("protyle-font");
let lastColorHTML = "";
- const lastFonts = JSON.parse(localStorage.getItem(Constants.LOCAL_FONTSTYLES) || "[]");
+ const lastFonts = window.siyuan.storage[Constants.LOCAL_FONTSTYLES];
if (lastFonts.length > 0) {
lastColorHTML = `
${window.siyuan.languages.lastUsed}
@@ -136,14 +136,13 @@ export const fontMenu = (protyle: IProtyle) => {
};
export const fontEvent = (protyle: IProtyle, type?: string, color?: string) => {
- let localFontStyles = JSON.parse(localStorage.getItem(Constants.LOCAL_FONTSTYLES) || "[]");
+ let localFontStyles = window.siyuan.storage[Constants.LOCAL_FONTSTYLES];
if (type) {
localFontStyles.splice(0, 0, `${type}${Constants.ZWSP}${color}`);
localFontStyles = [...new Set(localFontStyles)];
if (localFontStyles.length > 8) {
localFontStyles.splice(7, 1);
}
- localStorage.setItem(Constants.LOCAL_FONTSTYLES, JSON.stringify(localFontStyles));
} else {
if (localFontStyles.length === 0) {
type = "color";
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index ee09d8553..577d1bbf7 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1162,7 +1162,7 @@ export class Toolbar {
if (event.key === "Enter") {
const activeText = this.subElement.querySelector(".b3-list-item--focus").textContent;
languageElement.textContent = activeText === window.siyuan.languages.clear ? "" : activeText;
- localStorage.setItem(Constants.LOCAL_CODELANG, languageElement.textContent);
+ window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
const editElement = getContenteditableElement(nodeElement);
const lineNumber = nodeElement.getAttribute("linenumber");
if (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum)) {
@@ -1226,7 +1226,7 @@ export class Toolbar {
return;
}
languageElement.textContent = listElement.textContent === window.siyuan.languages.clear ? "" : listElement.textContent;
- localStorage.setItem(Constants.LOCAL_CODELANG, languageElement.textContent);
+ window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
const nodeElement = hasClosestBlock(languageElement);
if (nodeElement) {
const editElement = getContenteditableElement(nodeElement);
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index eff473675..d758fd51e 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -141,21 +141,79 @@ export const hotKey2Electron = (key: string) => {
export const setLocalStorage = () => {
fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
- if (response.data) {
- localStorage.clear();
- Object.keys(response.data).forEach(item => {
- if (item !== "setItem" && item !== "removeItem") {
- localStorage.setItem(item, response.data[item]);
+ window.siyuan.storage = response.data;
+ // 历史数据迁移
+ const defaultStorage: any = {};
+ defaultStorage[Constants.LOCAL_SEARCHEKEYS] = {
+ keys: [],
+ replaceKeys: [],
+ col: "",
+ row: "",
+ layout: 0
+ };
+ defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
+ defaultStorage[Constants.LOCAL_BAZAAR] = {
+ theme: "0",
+ template: "0",
+ icon: "0",
+ widget: "0",
+ };
+ defaultStorage[Constants.LOCAL_EXPORTWORD] = {removeAssets: false, mergeSubdocs: false};
+ defaultStorage[Constants.LOCAL_EXPORTPDF] = {
+ landscape: false,
+ marginType: "0",
+ scale: 1,
+ pageSize: "A4",
+ removeAssets: true,
+ keepFold: false,
+ mergeSubdocs: false,
+ };
+ defaultStorage[Constants.LOCAL_DOCINFO] = {
+ id: "",
+ action: []
+ };
+ defaultStorage[Constants.LOCAL_FONTSTYLES] = [];
+ defaultStorage[Constants.LOCAL_SEARCHEDATA] = {
+ sort: 0,
+ group: 0,
+ hasReplace: false,
+ method: 0,
+ hPath: "",
+ idPath: [],
+ k: "",
+ r: "",
+ types: {
+ document: window.siyuan.config.search.document,
+ heading: window.siyuan.config.search.heading,
+ list: window.siyuan.config.search.list,
+ listItem: window.siyuan.config.search.listItem,
+ codeBlock: window.siyuan.config.search.codeBlock,
+ htmlBlock: window.siyuan.config.search.htmlBlock,
+ mathBlock: window.siyuan.config.search.mathBlock,
+ table: window.siyuan.config.search.table,
+ blockquote: window.siyuan.config.search.blockquote,
+ superBlock: window.siyuan.config.search.superBlock,
+ paragraph: window.siyuan.config.search.paragraph,
+ }
+ };
+
+ [Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD,
+ Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA].forEach((key) => {
+ if (typeof response.data[key] === "string") {
+ try {
+ window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
+ } catch (e) {
+ window.siyuan.storage[key] = defaultStorage[key];
}
- });
- } else {
- exportLocalStorage();
- }
+ } else if (typeof response.data[key] === "undefined") {
+ window.siyuan.storage[key] = defaultStorage[key];
+ }
+ });
});
};
export const exportLocalStorage = (cb?: () => void) => {
- fetchPost("/api/storage/setLocalStorage", {val: localStorage}, () => {
+ fetchPost("/api/storage/setLocalStorage", {val: window.siyuan.storage}, () => {
if (cb) {
cb();
}
diff --git a/app/src/protyle/util/processCode.ts b/app/src/protyle/util/processCode.ts
index 40fa74061..63616dea2 100644
--- a/app/src/protyle/util/processCode.ts
+++ b/app/src/protyle/util/processCode.ts
@@ -36,7 +36,7 @@ export const processPasteCode = (html: string, text: string) => {
if (isCode) {
const code = text || html;
if (/\n/.test(code) || pres.length === 1) {
- return `
${localStorage.getItem(Constants.LOCAL_CODELANG) || ""}
${code.replace(/&/g, "&").replace(/
${Constants.ZWSP}
`;
+ return `
${window.siyuan.storage[Constants.LOCAL_CODELANG]}
${code.replace(/&/g, "&").replace(/
${Constants.ZWSP}
`;
} else {
return code;
}
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index f637257cd..ad8a7f97e 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -244,10 +244,10 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
blockElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${blockElement.getAttribute("data-node-id")}"]`);
const languageElement = blockElement.querySelector(".protyle-action__language");
if (languageElement) {
- if (localStorage.getItem(Constants.LOCAL_CODELANG) && languageElement.textContent === "") {
- languageElement.textContent = localStorage.getItem(Constants.LOCAL_CODELANG);
+ if (window.siyuan.storage[Constants.LOCAL_CODELANG] && languageElement.textContent === "") {
+ languageElement.textContent = window.siyuan.storage[Constants.LOCAL_CODELANG];
} else {
- localStorage.setItem(Constants.LOCAL_CODELANG, languageElement.textContent);
+ window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
}
highlightRender(blockElement);
} else {
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index 5c3fc63bc..f18b2c68f 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -170,8 +170,8 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
if (realType === "NodeCodeBlock") {
const languageElement = realElement.querySelector(".protyle-action__language");
if (languageElement) {
- if (localStorage.getItem(Constants.LOCAL_CODELANG) && languageElement.textContent === "") {
- languageElement.textContent = localStorage.getItem(Constants.LOCAL_CODELANG);
+ if (window.siyuan.storage[Constants.LOCAL_CODELANG] && languageElement.textContent === "") {
+ languageElement.textContent = window.siyuan.storage[Constants.LOCAL_CODELANG];
}
highlightRender(realElement);
} else if (tempElement.content.childElementCount === 1) {
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index ad3b43001..74277abb9 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -1248,7 +1248,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const id = nodeElement.getAttribute("data-node-id");
const html = nodeElement.outerHTML;
const editElement = getContenteditableElement(nodeElement);
- editElement.innerHTML = "```" + (localStorage.getItem(Constants.LOCAL_CODELANG) || "") + "\n" + editElement.textContent + "
\n```";
+ editElement.innerHTML = "```" + window.siyuan.storage[Constants.LOCAL_CODELANG] + "\n" + editElement.textContent + "\n```";
const newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
nodeElement.outerHTML = newHTML;
const newNodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`);
diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts
index 15b84cbda..99f89d220 100644
--- a/app/src/search/spread.ts
+++ b/app/src/search/spread.ts
@@ -45,22 +45,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
if (exitDialog) {
return;
}
- const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}");
- if (!localData.types) {
- localData.types = {
- document: window.siyuan.config.search.document,
- heading: window.siyuan.config.search.heading,
- list: window.siyuan.config.search.list,
- listItem: window.siyuan.config.search.listItem,
- codeBlock: window.siyuan.config.search.codeBlock,
- htmlBlock: window.siyuan.config.search.htmlBlock,
- mathBlock: window.siyuan.config.search.mathBlock,
- table: window.siyuan.config.search.table,
- blockquote: window.siyuan.config.search.blockquote,
- superBlock: window.siyuan.config.search.superBlock,
- paragraph: window.siyuan.config.search.paragraph,
- };
- }
+ const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA];
let hPath = "";
let idPath: string[] = [];
if (notebookId) {
@@ -75,8 +60,8 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
idPath[0] = pathPosix().join(idPath[0], searchPath);
}
} else if (window.siyuan.config.keymap.general.globalSearch.custom === hotkey) {
- hPath = localData.hPath || "";
- idPath = localData.idPath || [];
+ hPath = localData.hPath;
+ idPath = localData.idPath;
// 历史原因,2.5.2 之前为 string https://github.com/siyuan-note/siyuan/issues/6902
if (typeof idPath === "string") {
idPath = [idPath];
@@ -103,13 +88,13 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
dialog.element.setAttribute("data-key", hotkey);
const edit = genSearch({
k: key || localData.k,
- r: localData.r || "",
+ r: localData.r,
hasReplace: hotkey === window.siyuan.config.keymap.general.replace.custom,
- method: localData.method || 0,
+ method: localData.method,
hPath,
idPath,
- group: localData.group || 0,
- sort: localData.sort || 0,
+ group: localData.group,
+ sort: localData.sort,
types: localData.types
}, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => {
dialog.destroy();
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 1cf5f737a..4a0c85897 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -20,15 +20,12 @@ import {Dialog} from "../dialog";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
- const searchKeys = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}");
- let list: string[] = searchKeys[type] || [];
+ let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type];
list.splice(0, 0, value);
list = Array.from(new Set(list));
if (list.length > window.siyuan.config.search.limit) {
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
}
- searchKeys[type] = list;
- localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(searchKeys));
};
export const openGlobalSearch = (text: string, replace: boolean) => {
@@ -52,33 +49,18 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
icon: "iconSearch",
title: window.siyuan.languages.search,
callback(tab) {
- const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}");
- if (!localData.types) {
- localData.types = {
- document: window.siyuan.config.search.document,
- heading: window.siyuan.config.search.heading,
- list: window.siyuan.config.search.list,
- listItem: window.siyuan.config.search.listItem,
- codeBlock: window.siyuan.config.search.codeBlock,
- htmlBlock: window.siyuan.config.search.htmlBlock,
- mathBlock: window.siyuan.config.search.mathBlock,
- table: window.siyuan.config.search.table,
- blockquote: window.siyuan.config.search.blockquote,
- superBlock: window.siyuan.config.search.superBlock,
- paragraph: window.siyuan.config.search.paragraph,
- };
- }
+ const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA];
const asset = new Search({
tab,
config: {
k: text,
r: "",
hasReplace: false,
- method: localData.method || 0,
+ method: localData.method,
hPath: "",
idPath: [],
- group: localData.group || 0,
- sort: localData.sort || 0,
+ group: localData.group,
+ sort: localData.sort,
types: localData.types
}
});
@@ -109,7 +91,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
enableIncludeChild = true;
}
});
- const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}");
+ const data = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS];
element.innerHTML = `