Skip to content

Commit

Permalink
Merge remote-tracking branch 'forke-siyuan/dev' into v0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Jun 12, 2024
2 parents a4869e1 + c342c06 commit fd916de
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 21 deletions.
16 changes: 8 additions & 8 deletions app/src/layout/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -54,6 +54,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 => {
Expand Down Expand Up @@ -126,14 +127,13 @@ export const switchWnd = (newWnd: Wnd, targetWnd: Wnd) => {

export const getWndByLayout: (layout: Layout) => Wnd = (layout: Layout) => {
window.sout.tracker("invoked");
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) => {
Expand Down
5 changes: 3 additions & 2 deletions app/src/protyle/util/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,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;
};

Expand Down
5 changes: 3 additions & 2 deletions app/src/protyle/util/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
window.sout.tracker("invoked");
Expand Down Expand Up @@ -477,14 +478,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;
Expand Down
4 changes: 2 additions & 2 deletions app/src/protyle/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,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]);
}
});
Expand Down
5 changes: 3 additions & 2 deletions app/src/protyle/wysiwyg/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,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().substring(position.start).indexOf("\n") === -1 && (
// 需使用 innerText 否则表格内 br 无法传唤为 /n
if (event.key === "ArrowDown" && nodeEditableElement?.innerText.trimRight().substring(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))
Expand Down Expand Up @@ -700,7 +701,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);
Expand Down
2 changes: 1 addition & 1 deletion kernel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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.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
Expand Down
4 changes: 2 additions & 2 deletions kernel/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.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=
Expand Down
6 changes: 6 additions & 0 deletions kernel/model/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,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
}
Expand Down Expand Up @@ -1464,6 +1469,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)
Expand Down Expand Up @@ -1609,6 +1617,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)
}
}

Expand Down Expand Up @@ -1740,7 +1751,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 ""
}
Expand Down

0 comments on commit fd916de

Please sign in to comment.