Skip to content

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

:art: Warn when select all excludes unloaded blocks https://github.com/siyuan-note/siyuan/issues/18621

Daniel74c1ed5a3677
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.json
index 5327583834..9bba61cd2e 100644
--- a/app/appearance/langs/ar.json
+++ b/app/appearance/langs/ar.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "تم تحديد كتل المحتوى المحمّلة فقط، ولم يتم تحديد كتل المحتوى غير المحمّلة",
"listBlock": "كتلة قائمة",
"prependListItem": "إضافة عنصر قائمة إلى بداية القائمة الحالية",
"selectToPageStart": "تحديد النص من المؤشر إلى بداية الصفحة",
diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.json
index b4dcc3f252..9ad2abf752 100644
--- a/app/appearance/langs/de.json
+++ b/app/appearance/langs/de.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Es wurden nur geladene Inhaltsblöcke ausgewählt; nicht geladene Inhaltsblöcke wurden nicht ausgewählt",
"listBlock": "Listenblock",
"prependListItem": "Listenelement am Anfang der aktuellen Liste hinzufügen",
"selectToPageStart": "Text vom Cursor bis zum Seitenanfang auswählen",
diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.json
index 5559e79566..08ad811441 100644
--- a/app/appearance/langs/en.json
+++ b/app/appearance/langs/en.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Only loaded content blocks were selected; unloaded content blocks were not selected",
"listBlock": "List block",
"prependListItem": "Add a list item to the beginning of the current list",
"selectToPageStart": "Select text from the cursor to the beginning of the page",
diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.json
index 413af259a4..9d07766bc1 100644
--- a/app/appearance/langs/es.json
+++ b/app/appearance/langs/es.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Solo se seleccionaron los bloques de contenido cargados; los bloques de contenido no cargados no se seleccionaron",
"listBlock": "Bloque de lista",
"prependListItem": "Añadir un elemento al principio de la lista actual",
"selectToPageStart": "Seleccionar texto desde el cursor hasta el principio de la página",
diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.json
index 0402b99d86..4d89c8d4f3 100644
--- a/app/appearance/langs/fr.json
+++ b/app/appearance/langs/fr.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Seuls les blocs de contenu chargés ont été sélectionnés ; les blocs de contenu non chargés ne l’ont pas été",
"listBlock": "Bloc de liste",
"prependListItem": "Ajouter un élément au début de la liste actuelle",
"selectToPageStart": "Sélectionner le texte du curseur jusqu'au début de la page",
diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.json
index e1b18956d1..1c347561df 100644
--- a/app/appearance/langs/he.json
+++ b/app/appearance/langs/he.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "נבחרו רק בלוקי התוכן שנטענו; בלוקי תוכן שלא נטענו לא נבחרו",
"listBlock": "בלוק רשימה",
"prependListItem": "הוספת פריט לתחילת הרשימה הנוכחית",
"selectToPageStart": "בחירת טקסט מהסמן עד לתחילת הדף",
diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.json
index b372f19839..9f363780a6 100644
--- a/app/appearance/langs/hi.json
+++ b/app/appearance/langs/hi.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "केवल लोड किए गए सामग्री ब्लॉक चुने गए हैं; लोड नहीं किए गए सामग्री ब्लॉक नहीं चुने गए हैं",
"listBlock": "सूची ब्लॉक",
"prependListItem": "वर्तमान सूची की शुरुआत में सूची आइटम जोड़ें",
"selectToPageStart": "कर्सर से पृष्ठ के आरंभ तक टेक्स्ट चुनें",
diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.json
index 813f42ed7f..2e90ca2642 100644
--- a/app/appearance/langs/id.json
+++ b/app/appearance/langs/id.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Hanya blok konten yang telah dimuat yang dipilih; blok konten yang belum dimuat tidak dipilih",
"listBlock": "Blok daftar",
"prependListItem": "Tambahkan item daftar ke awal daftar saat ini",
"selectToPageStart": "Pilih teks dari kursor hingga awal halaman",
diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.json
index 61ea02a20a..5275b2c9fc 100644
--- a/app/appearance/langs/it.json
+++ b/app/appearance/langs/it.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Sono stati selezionati solo i blocchi di contenuto caricati; i blocchi di contenuto non caricati non sono stati selezionati",
"listBlock": "Blocco elenco",
"prependListItem": "Aggiungi un elemento all'inizio dell'elenco corrente",
"selectToPageStart": "Seleziona il testo dal cursore all'inizio della pagina",
diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.json
index 0d9c58d8b0..975d87c58b 100644
--- a/app/appearance/langs/ja.json
+++ b/app/appearance/langs/ja.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "読み込み済みのコンテンツブロックのみが選択され、未読み込みのコンテンツブロックは選択されていません",
"listBlock": "リストブロック",
"prependListItem": "現在のリストの先頭にリスト項目を追加",
"selectToPageStart": "カーソルからページの先頭までのテキストを選択",
diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.json
index 16f43b76ba..4f2bb7325d 100644
--- a/app/appearance/langs/ko.json
+++ b/app/appearance/langs/ko.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "불러온 콘텐츠 블록만 선택되었으며 불러오지 않은 콘텐츠 블록은 선택되지 않았습니다",
"listBlock": "목록 블록",
"prependListItem": "현재 목록 시작 부분에 목록 항목 추가",
"selectToPageStart": "커서부터 페이지 시작까지 텍스트 선택",
diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.json
index c7484ca29d..6581fcc6ad 100644
--- a/app/appearance/langs/nl.json
+++ b/app/appearance/langs/nl.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Alleen geladen inhoudsblokken zijn geselecteerd; niet-geladen inhoudsblokken zijn niet geselecteerd",
"listBlock": "Lijstblok",
"prependListItem": "Lijstitem toevoegen aan het begin van de huidige lijst",
"selectToPageStart": "Tekst vanaf de cursor tot het begin van de pagina selecteren",
diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.json
index c9965aa5a5..1424c021c9 100644
--- a/app/appearance/langs/pl.json
+++ b/app/appearance/langs/pl.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Wybrano tylko załadowane bloki treści; niezaładowane bloki treści nie zostały wybrane",
"listBlock": "Blok listy",
"prependListItem": "Dodaj element na początku bieżącej listy",
"selectToPageStart": "Zaznacz tekst od kursora do początku strony",
diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.json
index 90814dc231..89b95031e0 100644
--- a/app/appearance/langs/pt-BR.json
+++ b/app/appearance/langs/pt-BR.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Somente os blocos de conteúdo carregados foram selecionados; os blocos de conteúdo não carregados não foram selecionados",
"listBlock": "Bloco de lista",
"prependListItem": "Adicionar item ao início da lista atual",
"selectToPageStart": "Selecionar texto do cursor até o início da página",
diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.json
index 972c7e05cb..1f775d1dbf 100644
--- a/app/appearance/langs/ru.json
+++ b/app/appearance/langs/ru.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Выбраны только загруженные блоки содержимого; незагруженные блоки содержимого не выбраны",
"listBlock": "Блок списка",
"prependListItem": "Добавить элемент в начало текущего списка",
"selectToPageStart": "Выделить текст от курсора до начала страницы",
diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.json
index e16c843169..8822715cfc 100644
--- a/app/appearance/langs/sk.json
+++ b/app/appearance/langs/sk.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Vybrali sa iba načítané bloky obsahu; nenačítané bloky obsahu neboli vybrané",
"listBlock": "Blok zoznamu",
"prependListItem": "Pridať položku na začiatok aktuálneho zoznamu",
"selectToPageStart": "Vybrať text od kurzora po začiatok stránky",
diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.json
index c4a394b4c4..a957fa1627 100644
--- a/app/appearance/langs/th.json
+++ b/app/appearance/langs/th.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "เลือกเฉพาะบล็อกเนื้อหาที่โหลดแล้ว บล็อกเนื้อหาที่ยังไม่ได้โหลดจะไม่ถูกเลือก",
"listBlock": "บล็อกรายการ",
"prependListItem": "เพิ่มรายการที่จุดเริ่มต้นของรายการปัจจุบัน",
"selectToPageStart": "เลือกข้อความจากเคอร์เซอร์ถึงจุดเริ่มต้นของหน้า",
diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.json
index 5eae3450b0..5ceaabb829 100644
--- a/app/appearance/langs/tr.json
+++ b/app/appearance/langs/tr.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Yalnızca yüklenen içerik blokları seçildi; yüklenmeyen içerik blokları seçilmedi",
"listBlock": "Liste bloğu",
"prependListItem": "Geçerli listenin başına liste öğesi ekle",
"selectToPageStart": "İmleçten sayfanın başına kadar metni seç",
diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.json
index f5614475d2..9c6039ae1b 100644
--- a/app/appearance/langs/uk.json
+++ b/app/appearance/langs/uk.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "Вибрано лише завантажені блоки вмісту; незавантажені блоки вмісту не вибрано",
"listBlock": "Блок списку",
"prependListItem": "Додати елемент на початок поточного списку",
"selectToPageStart": "Виділити текст від курсора до початку сторінки",
diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.json
index 11774aa790..da6d9b631a 100644
--- a/app/appearance/langs/zh-CN.json
+++ b/app/appearance/langs/zh-CN.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "仅选中了已加载的内容块,未加载的内容块未被选中",
"listBlock": "列表块",
"prependListItem": "在当前列表开头添加列表项",
"selectToPageStart": "选中光标至页首的文本",
diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.json
index 465f455180..0e14d07cfe 100644
--- a/app/appearance/langs/zh-TW.json
+++ b/app/appearance/langs/zh-TW.json
@@ -1,4 +1,5 @@
{
+ "selectAllIncompleteTip": "僅選取了已載入的內容區塊,未載入的內容區塊未被選取",
"listBlock": "列表區塊",
"prependListItem": "在目前列表開頭新增列表項",
"selectToPageStart": "選取游標至頁首的文字",
diff --git a/app/src/protyle/util/documentRange.test.ts b/app/src/protyle/util/documentRange.test.ts
index 075618b4a3..77df094abe 100644
--- a/app/src/protyle/util/documentRange.test.ts
+++ b/app/src/protyle/util/documentRange.test.ts
@@ -1,14 +1,27 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {updateDocumentBottomEof} from "./documentRange";
+import {hasUnloadedDocumentBlocks, updateDocumentBottomEof} from "./documentRange";
-const createWysiwygElement = (lastElementEof?: string, initialBottomEof = false) => {
- let bottomEof = initialBottomEof;
+const createWysiwygElement = (options: {
+ firstElementEof?: string,
+ firstElementIndex?: string,
+ lastElementEof?: string,
+ initialBottomEof?: boolean,
+} = {}) => {
+ let bottomEof = options.initialBottomEof || false;
+ const createElement = (eof?: string, index?: string) => ({
+ getAttribute: (name: string) => {
+ if (name === "data-eof") {
+ return eof || null;
+ }
+ return name === "data-node-index" ? index || null : null;
+ },
+ });
return {
element: {
- lastElementChild: lastElementEof ? {
- getAttribute: (name: string) => name === "data-eof" ? lastElementEof : null,
- } : null,
+ firstElementChild: options.firstElementEof || options.firstElementIndex ?
+ createElement(options.firstElementEof, options.firstElementIndex) : null,
+ lastElementChild: options.lastElementEof ? createElement(options.lastElementEof) : null,
hasAttribute: (name: string) => name === "data-bottom-eof" && bottomEof,
toggleAttribute: (name: string, force: boolean) => {
if (name === "data-bottom-eof") {
@@ -22,7 +35,7 @@ const createWysiwygElement = (lastElementEof?: string, initialBottomEof = false)
describe("updateDocumentBottomEof", () => {
it("marks the loaded range when its last block is the document end", () => {
- const wysiwyg = createWysiwygElement("2");
+ const wysiwyg = createWysiwygElement({lastElementEof: "2"});
updateDocumentBottomEof(wysiwyg.element);
@@ -30,7 +43,7 @@ describe("updateDocumentBottomEof", () => {
});
it("clears the state when the loaded range no longer contains the document end", () => {
- const wysiwyg = createWysiwygElement(undefined, true);
+ const wysiwyg = createWysiwygElement({initialBottomEof: true});
updateDocumentBottomEof(wysiwyg.element);
@@ -38,10 +51,42 @@ describe("updateDocumentBottomEof", () => {
});
it("preserves the document end when probing the beginning of a single-block range", () => {
- const wysiwyg = createWysiwygElement("1", true);
+ const wysiwyg = createWysiwygElement({lastElementEof: "1", initialBottomEof: true});
updateDocumentBottomEof(wysiwyg.element, true);
assert.equal(wysiwyg.hasBottomEof(), true);
});
});
+
+describe("hasUnloadedDocumentBlocks", () => {
+ it("ignores document boundaries when dynamic loading is disabled", () => {
+ const wysiwyg = createWysiwygElement();
+
+ assert.equal(hasUnloadedDocumentBlocks(wysiwyg.element, false), false);
+ });
+
+ it("recognizes the initial block index as the document start", () => {
+ const wysiwyg = createWysiwygElement({firstElementIndex: "0", initialBottomEof: true});
+
+ assert.equal(hasUnloadedDocumentBlocks(wysiwyg.element, true), false);
+ });
+
+ it("recognizes the explicit document boundaries", () => {
+ const wysiwyg = createWysiwygElement({firstElementEof: "1", initialBottomEof: true});
+
+ assert.equal(hasUnloadedDocumentBlocks(wysiwyg.element, true), false);
+ });
+
+ it("detects unloaded blocks before the loaded range", () => {
+ const wysiwyg = createWysiwygElement({firstElementIndex: "10", initialBottomEof: true});
+
+ assert.equal(hasUnloadedDocumentBlocks(wysiwyg.element, true), true);
+ });
+
+ it("detects unloaded blocks after the loaded range", () => {
+ const wysiwyg = createWysiwygElement({firstElementEof: "1"});
+
+ assert.equal(hasUnloadedDocumentBlocks(wysiwyg.element, true), true);
+ });
+});
diff --git a/app/src/protyle/util/documentRange.ts b/app/src/protyle/util/documentRange.ts
index b1ab767edd..4221b90328 100644
--- a/app/src/protyle/util/documentRange.ts
+++ b/app/src/protyle/util/documentRange.ts
@@ -7,3 +7,13 @@ export const updateDocumentBottomEof = (wysiwygElement: HTMLElement, preserveCur
wysiwygElement.lastElementChild?.getAttribute("data-eof") === "2"
);
};
+
+export const hasUnloadedDocumentBlocks = (wysiwygElement: HTMLElement, dynamicLoad: boolean) => {
+ if (!dynamicLoad) {
+ return false;
+ }
+ const firstElement = wysiwygElement.firstElementChild;
+ const topEof = firstElement?.getAttribute("data-eof") === "1" ||
+ firstElement?.getAttribute("data-node-index") === "0";
+ return !topEof || !wysiwygElement.hasAttribute("data-bottom-eof");
+};
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 4b44021531..d290672d4f 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -18,6 +18,7 @@ import {
setLastNodeRange,
} from "../util/selection";
import {selectTextToEditorBoundary} from "../util/selectionBoundary";
+import {hasUnloadedDocumentBlocks} from "../util/documentRange";
import {
hasClosestBlock,
hasClosestByAttribute,
@@ -160,6 +161,13 @@ const showSelectAllTip = () => {
});
};
+const showSelectAllIncompleteTip = () => {
+ if (window.siyuan.config.appearance.notifications?.selectAllTip === false) {
+ return;
+ }
+ showMessage(window.siyuan.languages.selectAllIncompleteTip, 6000, "info", "selectAllIncompleteTip");
+};
+
const getAdjacentInlineMath = (range: Range, editableElement: Element, previous: boolean): HTMLElement | undefined => {
if (range.startContainer !== editableElement && !editableElement.contains(range.startContainer)) {
return;
@@ -1406,6 +1414,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (selectedCurrentContent && !protyle.lite &&
!nodeElement.classList.contains("code-block") && !isMobile()) {
showSelectAllTip();
+ } else if (!selectedCurrentContent && hasUnloadedDocumentBlocks(
+ protyle.wysiwyg.element,
+ !protyle.lite && !protyle.block.showAll && protyle.block.scroll && !protyle.options.backlinkData
+ )) {
+ showSelectAllIncompleteTip();
}
return true;
}