Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/11171

Vanessaa77f998e162f
diff --git a/app/src/constants.ts b/app/src/constants.ts
index ea369e44ff..ba67cee7c2 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -102,7 +102,7 @@ export abstract class Constants {
public static readonly LOCAL_SEARCHUNREF = "local-searchunref";
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string
- public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string
+ public static readonly LOCAL_HISTORY = "local-history";
public static readonly LOCAL_CODELANG = "local-codelang"; // string
public static readonly LOCAL_FONTSTYLES = "local-fontstyles";
public static readonly LOCAL_EXPORTPDF = "local-exportpdf";
diff --git a/app/src/history/history.ts b/app/src/history/history.ts
index 8b5182da3e..3ee74538a8 100644
--- a/app/src/history/history.ts
+++ b/app/src/history/history.ts
@@ -30,22 +30,44 @@ 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;
- window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] = notebookElement.value;
- setStorageVal(Constants.LOCAL_HISTORYNOTEID, window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID]);
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;
docElement.classList.add("fn__none");
mdElement.classList.add("fn__none");
- if (typeElement.value === "0" || typeElement.value === "1") {
- opElement.removeAttribute("disabled");
- notebookElement.removeAttribute("disabled");
- assetElement.classList.add("fn__none");
- } else {
- opElement.setAttribute("disabled", "disabled");
+ if (typeElement.value === "2") {
notebookElement.setAttribute("disabled", "disabled");
assetElement.classList.remove("fn__none");
+ if (window.siyuan.storage[Constants.LOCAL_HISTORY].type !== 2) {
+ opElement.value = "all";
+ }
+ opElement.querySelector('option[value="clean"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="update"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="delete"]').classList.add("fn__none")
+ opElement.querySelector('option[value="format"]').classList.add("fn__none")
+ opElement.querySelector('option[value="sync"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="replace"]').classList.add("fn__none")
+ opElement.querySelector('option[value="outline"]').classList.add("fn__none")
+ } else {
+ notebookElement.removeAttribute("disabled");
+ assetElement.classList.add("fn__none");
+ if (window.siyuan.storage[Constants.LOCAL_HISTORY].type === 2) {
+ opElement.value = "all";
+ }
+ opElement.querySelector('option[value="clean"]').classList.add("fn__none")
+ opElement.querySelector('option[value="update"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="delete"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="format"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="sync"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="replace"]').classList.remove("fn__none")
+ opElement.querySelector('option[value="outline"]').classList.remove("fn__none")
}
+ window.siyuan.storage[Constants.LOCAL_HISTORY] = {
+ notebookId: notebookElement.value,
+ type: parseInt(typeElement.value),
+ operation: opElement.value
+ };
+ setStorageVal(Constants.LOCAL_HISTORY, window.siyuan.storage[Constants.LOCAL_HISTORY]);
fetchPost("/api/history/searchHistory", {
notebook: notebookElement.value,
query: inputElement.value,
@@ -303,19 +325,11 @@ export const openHistory = (app: App) => {
return;
}
- let existLocalHistoryNoteID = false;
- window.siyuan.notebooks.forEach((item) => {
- if (!item.closed) {
- if (item.id === window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID]) {
- existLocalHistoryNoteID = true;
- }
- }
- });
-
- let notebookSelectHTML = `<option value='%' ${!existLocalHistoryNoteID ? "selected" : ""}>${window.siyuan.languages.allNotebooks}</option>`;
+ const localHistory = window.siyuan.storage[Constants.LOCAL_HISTORY];
+ let notebookSelectHTML = `<option value='%' ${localHistory.notebookId === "%" ? "selected" : ""}>${window.siyuan.languages.allNotebooks}</option>`;
window.siyuan.notebooks.forEach((item) => {
if (!item.closed) {
- notebookSelectHTML += ` <option value="${item.id}"${item.id === window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] ? " selected" : ""}>${escapeHtml(item.name)}</option>`;
+ notebookSelectHTML += ` <option value="${item.id}"${item.id === localHistory.notebookId ? " selected" : ""}>${escapeHtml(item.name)}</option>`;
}
});
@@ -342,20 +356,20 @@ export const openHistory = (app: App) => {
</div>
<span class="fn__space"></span>
<select data-type="typeselect" class="b3-select ${isMobile() ? "fn__size96" : "fn__size200"}">
- <option value="0" selected>${window.siyuan.languages.docName}</option>
- <option value="1">${window.siyuan.languages.docNameAndContent}</option>
- <option value="2">${window.siyuan.languages.assets}</option>
+ <option value="0" ${localHistory.type === 0 ? "selected" : ""}>${window.siyuan.languages.docName}</option>
+ <option value="1" ${localHistory.type === 1 ? "selected" : ""}>${window.siyuan.languages.docNameAndContent}</option>
+ <option value="2" ${localHistory.type === 2 ? "selected" : ""}>${window.siyuan.languages.assets}</option>
</select>
<span class="fn__space"></span>
<select data-type="opselect" class="b3-select${isMobile() ? " fn__size96" : ""}">
- <option value="all" selected>${window.siyuan.languages.allOp}</option>
- <option value="clean">${window.siyuan.languages.historyClean}</option>
- <option value="update">${window.siyuan.languages.historyUpdate}</option>
- <option value="delete">${window.siyuan.languages.historyDelete}</option>
- <option value="format">${window.siyuan.languages.historyFormat}</option>
- <option value="sync">${window.siyuan.languages.historySync}</option>
- <option value="replace">${window.siyuan.languages.historyReplace}</option>
- <option value="outline">${window.siyuan.languages.historyOutline}</option>
+ <option value="all" ${localHistory.operation === "all" ? "selected" : ""}>${window.siyuan.languages.allOp}</option>
+ <option value="clean" ${localHistory.operation === "clean" ? "selected" : ""}>${window.siyuan.languages.historyClean}</option>
+ <option value="update" ${localHistory.operation === "update" ? "selected" : ""}>${window.siyuan.languages.historyUpdate}</option>
+ <option value="delete" ${localHistory.operation === "delete" ? "selected" : ""}>${window.siyuan.languages.historyDelete}</option>
+ <option value="format" ${localHistory.operation === "format" ? "selected" : ""}>${window.siyuan.languages.historyFormat}</option>
+ <option value="sync" ${localHistory.operation === "sync" ? "selected" : ""}>${window.siyuan.languages.historySync}</option>
+ <option value="replace" ${localHistory.operation === "replace" ? "selected" : ""}>${window.siyuan.languages.historyReplace}</option>
+ <option value="outline" ${localHistory.operation === "outline" ? "selected" : ""}>${window.siyuan.languages.historyOutline}</option>
</select>
<span class="fn__space"></span>
<select data-type="notebookselect" class="b3-select ${isMobile() ? "fn__size96" : "fn__size200"}">
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 2c6a54dc8f..7f07553d17 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -195,6 +195,9 @@ export const getLocalStorage = (cb: () => void) => {
defaultStorage[Constants.LOCAL_OUTLINE] = {keepExpand: true};
defaultStorage[Constants.LOCAL_FILEPOSITION] = {}; // {id: IScrollAttr}
defaultStorage[Constants.LOCAL_DIALOGPOSITION] = {}; // {id: IPosition}
+ defaultStorage[Constants.LOCAL_HISTORY] = {
+ notebookId: "%", type: 0, operation: "all"
+ };
defaultStorage[Constants.LOCAL_FLASHCARD] = {
fullscreen: false
};
@@ -256,7 +259,7 @@ export const getLocalStorage = (cb: () => void) => {
Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES,
Constants.LOCAL_SEARCHDATA, Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI,
Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD,
- Constants.LOCAL_DIALOGPOSITION, Constants.LOCAL_SEARCHUNREF,
+ Constants.LOCAL_DIALOGPOSITION, Constants.LOCAL_SEARCHUNREF, Constants.LOCAL_HISTORY,
Constants.LOCAL_OUTLINE, Constants.LOCAL_FILEPOSITION].forEach((key) => {
if (typeof response.data[key] === "string") {
try {