Skip to content

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

:art: Move the recent documents clear action into the dialog footer

Jeffrey Chen129e003577ee
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy
index 3af1c88980..93e8eccef5 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy
@@ -1273,7 +1273,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "In the desktop and mobile recent documents list, select recently viewed, opened, or closed documents and click the trash button at the top to clear all three types of records after confirmation. This clears only the local records in the current workspace; documents, recent creation and modification lists, and tab navigation history are kept. New browsing, opening, or closing activity will be recorded again, including closing a tab that was already open."
+ "Data": "In the desktop recent documents list, select recently viewed, opened, or closed documents and click Clear at the bottom to clear all three types of records after confirmation; on mobile, use the trash button at the top of the list. This clears only the local records in the current workspace; documents, recent creation and modification lists, and tab navigation history are kept, and the clear action is unavailable in those two lists. New browsing, opening, or closing activity will be recorded again, including closing a tab that was already open."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy
index 52ad39f3bb..37efabf8eb 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy
@@ -1277,7 +1277,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "在桌面端和移动端的最近文档列表中,选择最近浏览、最近打开或最近关闭后,点击顶部的垃圾桶按钮并确认,即可一次清空这三类记录。清空仅影响当前工作区的本地记录,不删除文档,不影响最近创建、最近修改列表及页签前进后退记录。后续浏览、打开或关闭文档会重新产生记录,包括关闭清空前已经打开的页签。"
+ "Data": "在桌面端的最近文档列表中,选择最近浏览、最近打开或最近关闭后,点击底部的「清空」按钮并确认,即可一次清空这三类记录;移动端使用列表顶部的垃圾桶按钮。清空仅影响当前工作区的本地记录,不删除文档,不影响最近创建、最近修改列表及页签前进后退记录,这两类列表下清空按钮不可用。后续浏览、打开或关闭文档会重新产生记录,包括关闭清空前已经打开的页签。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy
index c688f52c19..a4ea980065 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy
@@ -1277,7 +1277,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "在桌面端和行動端的最近文件列表中,選擇最近瀏覽、最近開啟或最近關閉後,點擊頂部的垃圾桶按鈕並確認,即可一次清空這三類記錄。清空僅影響目前工作區的本機記錄,不刪除文件,不影響最近建立、最近修改列表及分頁前進後退記錄。後續瀏覽、開啟或關閉文件會重新產生記錄,包括關閉清空前已經開啟的分頁。"
+ "Data": "在桌面端的最近文件列表中,選擇最近瀏覽、最近開啟或最近關閉後,點擊底部的「清空」按鈕並確認,即可一次清空這三類記錄;行動端使用列表頂部的垃圾桶按鈕。清空僅影響目前工作區的本機記錄,不刪除文件,不影響最近建立、最近修改列表及分頁前進後退記錄,這兩類列表下清空按鈕無法使用。後續瀏覽、開啟或關閉文件會重新產生記錄,包括關閉清空前已經開啟的分頁。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy
index ebfd53fb13..8b237c7d42 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy
@@ -1282,7 +1282,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "デスクトップ版とモバイル版の最近のドキュメント一覧で、最近閲覧した、開いた、または閉じたドキュメントを選び、上部のごみ箱ボタンを押して確認すると、この3種類の履歴をまとめて消去できます。消去するのは現在のワークスペースのローカル履歴のみで、ドキュメント、最近作成・更新されたドキュメントの一覧、タブの進む・戻る履歴は保持されます。その後の閲覧、開く、閉じる操作は再び記録され、消去前から開いていたタブを閉じる場合も記録されます。"
+ "Data": "デスクトップ版の最近のドキュメント一覧で、最近閲覧した、開いた、または閉じたドキュメントを選び、下部の「消去」ボタンを押して確認すると、この3種類の履歴をまとめて消去できます。モバイル版では一覧上部のごみ箱ボタンを使用します。消去するのは現在のワークスペースのローカル履歴のみで、ドキュメント、最近作成・更新されたドキュメントの一覧、タブの進む・戻る履歴は保持され、これら2つの一覧では消去は使用できません。その後の閲覧、開く、閉じる操作は再び記録され、消去前から開いていたタブを閉じる場合も記録されます。"
}
]
},
diff --git a/app/src/assets/scss/main/_main.scss b/app/src/assets/scss/main/_main.scss
index 5135376de9..75a1b8e7e7 100644
--- a/app/src/assets/scss/main/_main.scss
+++ b/app/src/assets/scss/main/_main.scss
@@ -515,9 +515,19 @@ body.body--harmony {
border-left: 1px solid var(--b3-theme-surface-lighter);
}
- &__path {
+ &__footer {
+ display: flex;
+ align-items: center;
+ gap: 8px;
padding: 4px 8px;
border-top: 1px solid var(--b3-theme-surface-lighter);
+ min-height: 36px;
+ box-sizing: border-box;
+ }
+
+ &__path {
+ flex: 1;
+ min-width: 0;
color: var(--b3-theme-on-surface);
font-size: 12px;
white-space: nowrap;
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index 6672d5508d..9307235f8c 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -1459,7 +1459,8 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
});
if (openRecentDocsDialog && openRecentDocsDialog.element.contains(event.target as Node) &&
!openRecentDocsDialog.element.hasAttribute("data-dialog-closing")) {
- if ((event.target as HTMLElement).closest("select")) {
+ // 下拉菜单和按钮需要自行处理按键,Enter 不能转发为打开当前选中文档
+ if ((event.target as HTMLElement).closest("select, button")) {
return;
}
event.preventDefault();
diff --git a/app/src/business/clearRecentDocs.test.ts b/app/src/business/clearRecentDocs.test.ts
index 86dacee933..ab6d92bbf5 100644
--- a/app/src/business/clearRecentDocs.test.ts
+++ b/app/src/business/clearRecentDocs.test.ts
@@ -17,7 +17,7 @@ const harness = () => {
const requests: Array<{resolve: (response: {code: number}) => void, reject: (error: Error) => void}> = [];
const errors: string[] = [];
const siyuan = {config: {readonly: false}, isPublish: false,
- languages: {clearRecentDocs: "Clear recent history", confirmClearRecentDocs: "Confirm clear"}};
+ languages: {clear: "Clear", clearRecentDocs: "Clear recent history", confirmClearRecentDocs: "Confirm clear"}};
const exports: any = {};
runInNewContext(transpileModule(readFileSync("src/business/clearRecentDocs.ts", "utf8"), {
compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
@@ -32,7 +32,7 @@ const harness = () => {
"../util/escape": {escapeHtmlTextAndAttr: (text: string) => text},
})});
const update = exports.bindClearRecentDocs(button, () => sortBy, () => active, () => cleared++);
- return {button, hidden, confirmations, requests, errors, siyuan, update, click: () => click(),
+ return {exports, button, hidden, confirmations, requests, errors, siyuan, update, click: () => click(),
sort: (value: string) => { sortBy = value; update(); }, deactivate: () => { active = false; }, cleared: () => cleared};
};
@@ -73,16 +73,34 @@ test("failed clears retain records and allow retry", async () => {
}
});
+test("footer button carries its own label instead of relying on a hover tip", () => {
+ const h = harness();
+ const textButton = h.exports.clearRecentDocsTextButtonHTML();
+ assert.match(textButton, /data-action="clear-recent-docs"/);
+ assert.match(textButton, /Clear<\/button>/);
+ // 中性色按钮,避免底部操作在列表内容之上产生主色强调
+ assert.match(textButton, /b3-button--cancel/);
+ assert.doesNotMatch(textButton, /b3-button--text/);
+ assert.doesNotMatch(textButton, /b3-tooltips/);
+ const iconButton = h.exports.clearRecentDocsButtonHTML();
+ assert.match(iconButton, /b3-tooltips/);
+ assert.match(iconButton, /aria-label="Clear recent history"/);
+});
+
test("clear is available only in writable history views", () => {
const h = harness();
for (const mode of ["created", "updated"]) {
h.sort(mode);
- assert.equal(h.hidden.has("fn__none"), true);
+ // 不可清空的排序保留按钮占位,只禁用,避免切换排序时推挤相邻控件
+ assert.equal(h.hidden.has("fn__none"), false);
+ assert.equal(h.button.disabled, true);
h.click();
}
+ assert.equal(h.confirmations.length, 0);
for (const mode of ["viewedAt", "openAt", "closedAt"]) {
h.sort(mode);
assert.equal(h.hidden.has("fn__none"), false);
+ assert.equal(h.button.disabled, false);
}
h.siyuan.config.readonly = true;
h.update();
diff --git a/app/src/business/clearRecentDocs.ts b/app/src/business/clearRecentDocs.ts
index 5b4fdcd25b..4ca254f7ab 100644
--- a/app/src/business/clearRecentDocs.ts
+++ b/app/src/business/clearRecentDocs.ts
@@ -3,18 +3,27 @@ import {showMessage} from "../dialog/message";
import {fetchSyncPost} from "../util/fetch";
import {escapeHtmlTextAndAttr} from "../util/escape";
-export const clearRecentDocsButtonHTML = () => `<button type="button" data-action="clear-recent-docs" class="block__icon block__icon--show fn__none b3-tooltips b3-tooltips__sw" aria-label="${escapeHtmlTextAndAttr(window.siyuan.languages.clearRecentDocs)}"><svg><use xlink:href="#iconTrashcan"></use></svg></button>`;
+const clearRecentDocsIconHTML = '<svg><use xlink:href="#iconTrashcan"></use></svg>';
+
+/** 移动端工具栏使用的图标按钮,悬浮提示由 aria-label 提供 */
+export const clearRecentDocsButtonHTML = () => `<button type="button" data-action="clear-recent-docs" class="block__icon block__icon--show fn__none b3-tooltips b3-tooltips__sw" aria-label="${escapeHtmlTextAndAttr(window.siyuan.languages.clearRecentDocs)}">${clearRecentDocsIconHTML}</button>`;
+
+/** 最近文档对话框底部使用的文字按钮,使用中性色避免抢夺列表内容的注意力 */
+export const clearRecentDocsTextButtonHTML = () => `<button type="button" data-action="clear-recent-docs" class="b3-button b3-button--cancel fn__none">${clearRecentDocsIconHTML}${escapeHtmlTextAndAttr(window.siyuan.languages.clear)}</button>`;
export const bindClearRecentDocs = (button: HTMLButtonElement, getSortBy: () => string,
isActive: () => boolean, onCleared: () => void) => {
let pending = false;
const canWrite = () => !window.siyuan.config.readonly && !window.siyuan.isPublish;
+ // 最近创建、最近修改来自块数据查询,清空本地浏览记录不会改变这两类列表
+ const isSortClearable = () => !["created", "updated"].includes(getSortBy());
const update = () => {
- button.classList.toggle("fn__none", !canWrite() || ["created", "updated"].includes(getSortBy()));
- button.disabled = pending;
+ // 无写权限时完全隐藏;当前排序不可清空时保留占位并禁用,避免切换排序推挤相邻控件
+ button.classList.toggle("fn__none", !canWrite());
+ button.disabled = pending || !isSortClearable();
};
button.addEventListener("click", () => {
- if (pending || !canWrite() || !isActive() || ["created", "updated"].includes(getSortBy())) {
+ if (pending || !canWrite() || !isActive() || !isSortClearable()) {
return;
}
pending = true;
diff --git a/app/src/business/openRecentDocs.layout.test.ts b/app/src/business/openRecentDocs.layout.test.ts
index dd0378fdf0..6297668e94 100644
--- a/app/src/business/openRecentDocs.layout.test.ts
+++ b/app/src/business/openRecentDocs.layout.test.ts
@@ -84,7 +84,7 @@ const browserCases = async (sources: string[], css: string, languages: Record<st
const rect = container.getBoundingClientRect();
check.ok(Math.abs(rect.width - width) <= 2, `${direction}: requested ${width}, got ${rect.width}`);
const label = `${theme}/${lang.recentDocs}/${fontSize}/${isDetached}/${direction}/${width}`;
- for (const control of root.querySelectorAll<HTMLElement>(".b3-dialog__header input, .b3-dialog__header select, .b3-dialog__header button")) {
+ for (const control of root.querySelectorAll<HTMLElement>(".b3-dialog__header input, .b3-dialog__header select, .switch-doc__footer button")) {
const controlRect = control.getBoundingClientRect();
check.ok(controlRect.width > 0 && controlRect.left >= rect.left && controlRect.right <= rect.right &&
controlRect.top >= rect.top && controlRect.bottom <= rect.bottom, label);
diff --git a/app/src/business/openRecentDocs.test.ts b/app/src/business/openRecentDocs.test.ts
index b60791cbec..c81172a888 100644
--- a/app/src/business/openRecentDocs.test.ts
+++ b/app/src/business/openRecentDocs.test.ts
@@ -22,7 +22,7 @@ const createHarness = () => {
let clearCallback: () => void;
let clearUpdates = 0;
const host = {innerHTML: ""};
- const path = {innerHTML: "", previousElementSibling: host};
+ const path = {innerHTML: ""};
let icons: Array<{tagName: string, classes: Set<string>, classList: {add: (name: string) => void},
dataset: Record<string, string>, parentElement: {dataset: {nodeId: string}}}> = [];
const attributes = new Map<string, string>();
@@ -35,6 +35,9 @@ const createHarness = () => {
if (selector === ".switch-doc__path") {
return path;
}
+ if (selector === "[data-type=\"recentDocsList\"]") {
+ return host;
+ }
return selector === "input" ? input : select;
},
querySelectorAll: (selector: string) => {
@@ -87,7 +90,7 @@ const createHarness = () => {
cleanups.push(host.innerHTML);
}},
"./clearRecentDocs": {
- clearRecentDocsButtonHTML: () => "<button data-action=\"clear-recent-docs\"></button>",
+ clearRecentDocsTextButtonHTML: () => "<button data-action=\"clear-recent-docs\"></button>",
bindClearRecentDocs: (_button: unknown, _getSort: unknown, _isActive: unknown, callback: () => void) => {
clearCallback = callback;
return () => clearUpdates++;
@@ -204,9 +207,11 @@ test("recent Arrow and Enter handlers ignore popover editors and closing dialog
assert.ok(statement, "load the actual recent-document branch");
const input = {closest: (): null => null};
const editor = {closest: (): null => null};
+ const button = {closest: (selector: string) => selector.includes("button") ? {} : null};
let closing = false;
let calls = 0;
- const element = {getAttribute: () => "recent", hasAttribute: () => closing, contains: (target: unknown) => target === input};
+ const element = {getAttribute: () => "recent", hasAttribute: () => closing,
+ contains: (target: unknown) => target === input || target === button};
const exports: any = {};
runInNewContext(transpileModule(`exports.keydown = (event, app) => { ${statement.getText(source)} };`, {
compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
@@ -218,6 +223,9 @@ test("recent Arrow and Enter handlers ignore popover editors and closing dialog
exports.keydown({...event, target: editor}, {});
}
assert.equal(calls, 3);
+ // 焦点在底部清空按钮上时 Enter 交由按钮自身处理,不得打开选中文档
+ exports.keydown({key: "Enter", target: button, preventDefault() {}}, {});
+ assert.equal(calls, 3);
closing = true;
exports.keydown({key: "Enter", target: input, preventDefault() {}}, {});
assert.equal(calls, 3);
diff --git a/app/src/business/openRecentDocs.ts b/app/src/business/openRecentDocs.ts
index b2616ec181..8d1ba20117 100644
--- a/app/src/business/openRecentDocs.ts
+++ b/app/src/business/openRecentDocs.ts
@@ -11,9 +11,10 @@ import {Dialog} from "../dialog";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {hideElements} from "../protyle/ui/hideElements";
import {destroyDialogBlockPanels} from "../block/panelOwnership";
-import {bindClearRecentDocs, clearRecentDocsButtonHTML} from "./clearRecentDocs";
+import {bindClearRecentDocs, clearRecentDocsTextButtonHTML} from "./clearRecentDocs";
const recentDocsRenderVersions = new WeakMap<Element, number>();
+const RECENT_DOCS_LIST = "recentDocsList";
const renderRecentDocsContent = async (data: {
rootID: string,
@@ -82,9 +83,8 @@ const renderRecentDocsContent = async (data: {
return;
}
destroyDialogBlockPanels(element as HTMLElement);
- const pathElement = element.querySelector(".switch-doc__path");
- pathElement.innerHTML = switchPath;
- pathElement.previousElementSibling.innerHTML = `<div class="fn__flex fn__flex-1" style="overflow: auto;">
+ element.querySelector(".switch-doc__path").innerHTML = switchPath;
+ element.querySelector(`[data-type="${RECENT_DOCS_LIST}"]`).innerHTML = `<div class="fn__flex fn__flex-1" style="overflow: auto;">
${dockHtml}
<ul style="${isWindow() ? "border-left: 0;" : ""}min-width: 360px;" class="b3-list b3-list--background fn__flex-1">${tabHtml}</ul>
</div>`;
@@ -121,13 +121,14 @@ export const openRecentDocs = (openOnly = false) => {
<option value="openAt">${window.siyuan.languages.recentOpened}</option>
<option value="closedAt">${window.siyuan.languages.recentClosed}</option>
</select>
- <span class="fn__space"></span>
- ${clearRecentDocsButtonHTML()}
</div>
</div>`,
content: `<div class="fn__flex-column switch-doc">
- <div class="fn__flex fn__flex-1" style="overflow: auto;"></div>
- <div class="switch-doc__path"></div>
+ <div class="fn__flex fn__flex-1" data-type="${RECENT_DOCS_LIST}" style="overflow: auto;"></div>
+ <div class="switch-doc__footer">
+ <div class="switch-doc__path"></div>
+ ${clearRecentDocsTextButtonHTML()}
+ </div>
</div>`,
height: "80vh",
});