From 511a4bdd8aaea6a60d01c42619240d2ee271d1b0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 12 Jun 2024 10:20:17 +0800 Subject: [PATCH 1/5] :art: Display database title in bookmark panel https://github.com/siyuan-note/siyuan/issues/11666 --- kernel/go.mod | 2 +- kernel/go.sum | 4 ++-- kernel/model/bookmark.go | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index ded89a30db..8c01c9e961 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -7,7 +7,7 @@ require ( github.com/88250/clipboard v0.1.5 github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48 github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 - github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866 + github.com/88250/gulu v1.2.3-0.20240612021457-b8e8cadd87f3 github.com/88250/lute v1.7.7-0.20240611024745-53a7d0cc6568 github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 diff --git a/kernel/go.sum b/kernel/go.sum index 4301b984c8..737e1aac6f 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -10,8 +10,8 @@ github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 h1:MafIFwSS0x6A4 github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7/go.mod h1:HrKCCTin3YNDSLBD02K0AOljjV6eNwc3/zyEI+xyV1I= github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceTVVqrYaDlLio2QSKbXMUmAZPbzCwT5eNCw= github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866 h1:RFfNFS0hv6TbOuwET6xZAfGlV4hNlXiWTnfbLN1eF6k= -github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8= +github.com/88250/gulu v1.2.3-0.20240612021457-b8e8cadd87f3 h1:vgVJ0e9hrdEpHOkKcSe45+ht1+O13PWi2ssq8yDVAvQ= +github.com/88250/gulu v1.2.3-0.20240612021457-b8e8cadd87f3/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8= github.com/88250/lute v1.7.7-0.20240611024745-53a7d0cc6568 h1:1TwBQATNCmPi4XvEZReYDam8aouz3DZPXUciciTITdg= github.com/88250/lute v1.7.7-0.20240611024745-53a7d0cc6568/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk= github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0= diff --git a/kernel/model/bookmark.go b/kernel/model/bookmark.go index c2d9dab7cd..b1c7142f1f 100644 --- a/kernel/model/bookmark.go +++ b/kernel/model/bookmark.go @@ -22,8 +22,10 @@ import ( "sort" "strings" + "github.com/88250/gulu" "github.com/88250/lute/parse" "github.com/siyuan-note/logging" + "github.com/siyuan-note/siyuan/kernel/av" "github.com/siyuan-note/siyuan/kernel/cache" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" @@ -171,6 +173,10 @@ func BuildBookmark() (ret *Bookmarks) { if "" != block.Name { // Blocks in the bookmark panel display their name instead of content https://github.com/siyuan-note/siyuan/issues/8514 block.Content = block.Name + } else if "NodeAttributeView" == block.Type { + // Display database title in bookmark panel https://github.com/siyuan-note/siyuan/issues/11666 + avID := gulu.Str.SubStringBetween(block.Markdown, "av-id=\"", "\"") + block.Content, _ = av.GetAttributeViewName(avID) } else { // Improve bookmark panel rendering https://github.com/siyuan-note/siyuan/issues/9361 tree, err := LoadTreeByBlockID(block.ID) From 1f918e07733ffa6896956593beddba2908f1aa9f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 12 Jun 2024 10:55:26 +0800 Subject: [PATCH 2/5] :art: fix https://github.com/siyuan-note/siyuan/issues/11694 --- app/src/protyle/util/selection.ts | 5 +++-- app/src/protyle/util/table.ts | 5 +++-- app/src/protyle/wysiwyg/keydown.ts | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts index 85b6db3a47..925dab49b8 100644 --- a/app/src/protyle/util/selection.ts +++ b/app/src/protyle/util/selection.ts @@ -261,8 +261,9 @@ export const getSelectionOffset = (selectElement: Node, editorElement?: Element, preSelectionRange.selectNodeContents(selectElement); } preSelectionRange.setEnd(range.startContainer, range.startOffset); - position.start = preSelectionRange.toString().length; - position.end = position.start + range.toString().length; + // 需加上表格内软换行 br 的长度 + position.start = preSelectionRange.toString().length + preSelectionRange.cloneContents().querySelectorAll("br").length; + position.end = position.start + range.toString().length + range.cloneContents().querySelectorAll("br").length; return position; }; diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts index c19409e999..d146965731 100644 --- a/app/src/protyle/util/table.ts +++ b/app/src/protyle/util/table.ts @@ -6,6 +6,7 @@ import {isNotCtrl} from "./compatibility"; import {scrollCenter} from "../../util/highlightById"; import {insertEmptyBlock} from "../../block/util"; import {removeBlock} from "../wysiwyg/remove"; +import {hasPreviousSibling} from "../wysiwyg/getBlock"; const scrollToView = (nodeElement: Element, rowElement: HTMLElement, protyle: IProtyle) => { if (nodeElement.getAttribute("custom-pinthead") === "true") { @@ -463,14 +464,14 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range) const startContainer = range.startContainer as HTMLElement; let previousBrElement; if (startContainer.nodeType !== 3 && (startContainer.tagName === "TH" || startContainer.tagName === "TD")) { - previousBrElement = (startContainer.childNodes[Math.max(0, range.startOffset - 1)] as HTMLElement)?.previousElementSibling; + previousBrElement = (startContainer.childNodes[Math.min(range.startOffset, startContainer.childNodes.length - 1)] as HTMLElement); } else if (startContainer.parentElement.tagName === "SPAN") { previousBrElement = startContainer.parentElement.previousElementSibling; } else { previousBrElement = startContainer.previousElementSibling; } while (previousBrElement) { - if (previousBrElement.tagName === "BR") { + if (previousBrElement.tagName === "BR" && hasPreviousSibling(previousBrElement)) { return false; } previousBrElement = previousBrElement.previousElementSibling; diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 68e26cced9..8453562144 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -622,7 +622,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { const tdElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH"); const nodeEditableElement = (tdElement || getContenteditableElement(nodeElement) || nodeElement) as HTMLElement; const position = getSelectionOffset(nodeEditableElement, protyle.wysiwyg.element, range); - if (event.key === "ArrowDown" && nodeEditableElement?.textContent.trimRight().substr(position.start).indexOf("\n") === -1 && ( + // 需使用 innerText 否则表格内 br 无法传唤为 /n + if (event.key === "ArrowDown" && nodeEditableElement?.innerText.trimRight().substr(position.start).indexOf("\n") === -1 && ( (tdElement && !tdElement.parentElement.nextElementSibling && nodeElement.getAttribute("data-type") === "NodeTable" && !getNextBlock(nodeElement)) || (nodeElement.getAttribute("data-type") === "NodeCodeBlock" && !getNextBlock(nodeElement)) || (nodeElement.parentElement.getAttribute("data-type") === "NodeBlockquote" && nodeElement.nextElementSibling.classList.contains("protyle-attr") && !getNextBlock(nodeElement.parentElement)) @@ -697,7 +698,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { } } if (event.key === "ArrowDown") { - if (nodeEditableElement?.textContent.trimRight().substr(position.start).indexOf("\n") === -1 && + if (nodeEditableElement?.innerText.trimRight().substr(position.start).indexOf("\n") === -1 && nodeElement.isSameNode(protyle.wysiwyg.element.lastElementChild)) { setLastNodeRange(getContenteditableElement(nodeEditableElement), range, false); range.collapse(false); From f39c4b3b695ea92127f1e263e53c7cb4a91a1723 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 12 Jun 2024 11:13:09 +0800 Subject: [PATCH 3/5] :bug: fix https://github.com/siyuan-note/siyuan/issues/11695 --- app/src/protyle/wysiwyg/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 7c8dc7050d..5fda31d781 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -138,14 +138,14 @@ export class WYSIWYG { const ialKeys = Object.keys(ial); for (let i = 0; i < this.element.attributes.length; i++) { const oldKey = this.element.attributes[i].nodeName; - if (!["type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth"].includes(oldKey) && + if (!["type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth", "data-readonly"].includes(oldKey) && !ialKeys.includes(oldKey)) { this.element.removeAttribute(oldKey); i--; } } ialKeys.forEach((key: string) => { - if (!["title-img", "title", "updated", "icon", "id", "type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth"].includes(key)) { + if (!["title-img", "title", "updated", "icon", "id", "type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth", "data-readonly"].includes(key)) { this.element.setAttribute(key, ial[key]); } }); From f51b33769302868327e510f1021a95d7ea85875e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 12 Jun 2024 12:03:31 +0800 Subject: [PATCH 4/5] :art: Display details when exporting .sy.zip and data.zip https://github.com/siyuan-note/siyuan/issues/11696 --- kernel/go.mod | 2 +- kernel/go.sum | 4 ++-- kernel/model/export.go | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index 8c01c9e961..eea1b1cddc 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -7,7 +7,7 @@ require ( github.com/88250/clipboard v0.1.5 github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48 github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 - github.com/88250/gulu v1.2.3-0.20240612021457-b8e8cadd87f3 + github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 github.com/88250/lute v1.7.7-0.20240611024745-53a7d0cc6568 github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 diff --git a/kernel/go.sum b/kernel/go.sum index 737e1aac6f..3c28b33eab 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -10,8 +10,8 @@ github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 h1:MafIFwSS0x6A4 github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7/go.mod h1:HrKCCTin3YNDSLBD02K0AOljjV6eNwc3/zyEI+xyV1I= github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceTVVqrYaDlLio2QSKbXMUmAZPbzCwT5eNCw= github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/88250/gulu v1.2.3-0.20240612021457-b8e8cadd87f3 h1:vgVJ0e9hrdEpHOkKcSe45+ht1+O13PWi2ssq8yDVAvQ= -github.com/88250/gulu v1.2.3-0.20240612021457-b8e8cadd87f3/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8= +github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY= +github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8= github.com/88250/lute v1.7.7-0.20240611024745-53a7d0cc6568 h1:1TwBQATNCmPi4XvEZReYDam8aouz3DZPXUciciTITdg= github.com/88250/lute v1.7.7-0.20240611024745-53a7d0cc6568/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk= github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0= diff --git a/kernel/model/export.go b/kernel/model/export.go index 6f0a91d307..407431d735 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -471,7 +471,12 @@ func exportData(exportFolder string) (zipPath string, err error) { return } - if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err { + zipCallback := func(filename string) { + msg := Conf.language(65) + " " + fmt.Sprintf(Conf.language(70), filename) + util.PushEndlessProgress(msg) + } + + if err = zip.AddDirectory(baseFolderName, exportFolder, zipCallback); nil != err { logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err) return } @@ -1462,6 +1467,9 @@ func yfm(docIAL map[string]string) string { } func exportBoxSYZip(boxID string) (zipPath string) { + util.PushEndlessProgress(Conf.Language(65)) + defer util.ClearPushProgress(100) + box := Conf.Box(boxID) if nil == box { logging.LogErrorf("not found box [%s]", boxID) @@ -1607,6 +1615,9 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) ( } copiedAssets.Add(asset) + + msg := Conf.language(65) + " " + fmt.Sprintf(Conf.language(70), asset) + util.PushEndlessProgress(msg) } } @@ -1738,7 +1749,12 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) ( return "" } - if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err { + zipCallback := func(filename string) { + msg := Conf.language(65) + " " + fmt.Sprintf(Conf.language(70), filename) + util.PushEndlessProgress(msg) + } + + if err = zip.AddDirectory(baseFolderName, exportFolder, zipCallback); nil != err { logging.LogErrorf("create export .sy.zip [%s] failed: %s", exportFolder, err) return "" } From e22ac7759ec8d628fb88726fa9edd9bd45772b06 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 12 Jun 2024 12:09:02 +0800 Subject: [PATCH 5/5] :art: fix https://github.com/siyuan-note/siyuan/issues/11676 --- app/src/layout/util.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index 80f2d30ca3..b2c8327302 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -8,7 +8,7 @@ import {Files} from "./dock/Files"; import {Outline} from "./dock/Outline"; import {Bookmark} from "./dock/Bookmark"; import {Tag} from "./dock/Tag"; -import {getAllModels, getAllTabs} from "./getAll"; +import {getAllModels, getAllTabs, getAllWnds} from "./getAll"; import {Asset} from "../asset"; import {Search} from "../search"; import {Dock} from "./dock"; @@ -53,6 +53,7 @@ export const setPanelFocus = (element: Element) => { }); if (element.getAttribute("data-type") === "wnd") { element.classList.add("layout__wnd--active"); + element.querySelector(".layout-tab-bar .item--focus")?.setAttribute("data-activetime", (new Date()).getTime().toString()); } else { element.classList.add("layout__tab--active"); Array.from(element.classList).find(item => { @@ -123,14 +124,13 @@ export const switchWnd = (newWnd: Wnd, targetWnd: Wnd) => { }; export const getWndByLayout: (layout: Layout) => Wnd = (layout: Layout) => { - for (let i = 0; i < layout.children.length; i++) { - const item = layout.children[i]; - if (item instanceof Wnd) { - return item; - } else { - return getWndByLayout(item); + const wndsTemp: Wnd[] = []; + getAllWnds(layout, wndsTemp); + return wndsTemp.sort((a, b) => { + if (a.element.querySelector(".fn__flex .item--focus")?.getAttribute("data-activetime") > b.element.querySelector(".fn__flex .item--focus")?.getAttribute("data-activetime")) { + return -1; } - } + })[0]; }; const dockToJSON = (dock: Dock) => {