Skip to content

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

:sparkles: Simplify mobile database text editor actions https://github.com/siyuan-note/siyuan/issues/19949

Daniel67c0e7f68c8d
diff --git a/app/src/protyle/render/av/richTextEditor.ts b/app/src/protyle/render/av/richTextEditor.ts
index 0ba7b3a6dd..2cf1aebd3b 100644
--- a/app/src/protyle/render/av/richTextEditor.ts
+++ b/app/src/protyle/render/av/richTextEditor.ts
@@ -107,8 +107,7 @@ export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
maskElement.style.zIndex = (++window.siyuan.zIndex).toString();
maskElement.innerHTML = `<div class="av__richtext-editor" role="dialog">
${mobile ? `<div class="av__richtext-actions">
- <button type="button" class="b3-button b3-button--cancel" data-type="cancel">${escapeHtml(window.siyuan.languages.cancel)}</button>
- <button type="button" class="b3-button b3-button--text" data-type="save">${escapeHtml(window.siyuan.languages.save)}</button>
+ <button type="button" class="b3-button b3-button--text" data-type="confirm">${escapeHtml(window.siyuan.languages.confirm)}</button>
</div>` : ""}
<div class="av__richtext-host"></div>
</div>`;
@@ -240,8 +239,7 @@ export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
void finish(true);
}
});
- panelElement.querySelector('[data-type="cancel"]')?.addEventListener("click", () => void finish(false));
- panelElement.querySelector('[data-type="save"]')?.addEventListener("click", () => void finish(true));
+ panelElement.querySelector('[data-type="confirm"]')?.addEventListener("click", () => void finish(true));
panelElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (event.key === "Escape" && fragment.hintElement.classList.contains("fn__none") &&
fragment.protyle.toolbar.element.classList.contains("fn__none") &&
diff --git a/app/tests/avRichTextEditor.test.js b/app/tests/avRichTextEditor.test.js
index 37a7dc6a42..d431420bea 100644
--- a/app/tests/avRichTextEditor.test.js
+++ b/app/tests/avRichTextEditor.test.js
@@ -9,7 +9,7 @@ const runCases = async (sources) => {
const dataByElement = new WeakMap();
let mobile = false;
let fragment;
- window.siyuan = {zIndex: 0, languages: {empty: "Empty", cancel: "Cancel", save: "Save"}};
+ window.siyuan = {zIndex: 0, languages: {empty: "Empty", confirm: "Confirm"}};
const hiddenElement = () => {
const element = document.createElement("div");
element.className = "fn__none";
@@ -105,14 +105,13 @@ const runCases = async (sources) => {
toolbar.className = "keyboard";
toolbar.style.zIndex = "100";
document.body.append(toolbar);
- const save = document.querySelector('[data-type="save"]');
- const cancel = document.querySelector('[data-type="cancel"]');
- for (const button of [save, cancel]) {
- const rect = button.getBoundingClientRect();
- assert.ok(rect.bottom <= toolbar.getBoundingClientRect().top, "actions must remain above the keyboard toolbar");
- assert.ok(button.contains(document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)),
- "mobile actions must receive pointer events");
- }
+ const confirm = document.querySelector('[data-type="confirm"]');
+ assert.equal(document.querySelectorAll(".av__richtext-actions button").length, 1);
+ assert.equal(confirm.textContent, window.siyuan.languages.confirm);
+ const rect = confirm.getBoundingClientRect();
+ assert.ok(rect.bottom <= toolbar.getBoundingClientRect().top, "actions must remain above the keyboard toolbar");
+ assert.ok(confirm.contains(document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)),
+ "mobile actions must receive pointer events");
}
for (const input of ["a", "b", "中文"]) {
fragment.input.append(document.createTextNode(input));
@@ -125,7 +124,7 @@ const runCases = async (sources) => {
assert.equal(hasAVEditorSession(state.owner), true, `${mode}: track the visible owner`);
fragment.pendingInput = "待提交";
if (mobile) {
- document.querySelector('[data-type="save"]').click();
+ document.querySelector('[data-type="confirm"]').click();
} else {
document.querySelector(".av__richtext-mask").dispatchEvent(new MouseEvent("mousedown", {bubbles: true}));
}
@@ -141,12 +140,11 @@ const runCases = async (sources) => {
assert.equal(document.querySelector(".av__richtext-mask"), null);
if (mobile) {
- const cancelled = createOwner(true);
- fragment.input.append(document.createTextNode("discarded"));
- document.querySelector('[data-type="cancel"]').click();
+ const unchanged = createOwner(true);
+ document.querySelector('[data-type="confirm"]').click();
await settle();
- assert.equal(cancelled.saves.length, 0);
- assert.equal(cancelled.closed(), 1);
+ assert.equal(unchanged.saves.length, 0);
+ assert.equal(unchanged.closed(), 1);
assert.equal(document.querySelector(".av__richtext-mask"), null);
const returned = createOwner(true);