Skip to content

Commit

Permalink
Merge remote-tracking branch 'fork-siyuan/dev' into huge_merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Mar 24, 2024
2 parents 14c00f9 + f0fd8f9 commit a0bb28b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
25 changes: 19 additions & 6 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,19 +969,32 @@ app.whenReady().then(() => {
}
data.filePaths = result.filePaths;
data.webContentsId = event.sender.id;
getWindowByContentId(event.sender.id).getParentWindow().send("siyuan-export-pdf", data);
const wnd = getWindowByContentId(event.sender.id);
if (!wnd) {
// 文档已经被删除的情况下关闭窗口,下同
event.sender.destroy();
return;
}
const parentWnd = wnd.getParentWindow();
if (!parentWnd) {
event.sender.destroy();
return;
}
parentWnd.send("siyuan-export-pdf", data);
});
});
ipcMain.on("siyuan-export-newwindow", (event, data) => {
const parentWnd = getWindowByContentId(event.sender.id);
const parentWndBounds = parentWnd.getBounds();
const parentWndScreen = screen.getDisplayNearestPoint({x: parentWndBounds.x, y: parentWndBounds.y});
parentWndScreen.size.width;

// The PDF/Word export preview window automatically adjusts according to the size of the main window https://github.com/siyuan-note/siyuan/issues/10554
const printWin = new BrowserWindow({
parent: parentWnd,
modal: false,
show: true,
width: Math.floor(parentWnd.getBounds().width * 0.8),
height: Math.floor(parentWnd.getBounds().height * 0.8),
resizable: false,
width: parentWndScreen.size.width * 0.9,
height: parentWndScreen.size.height * 0.9,
resizable: true,
frame: "darwin" === process.platform,
icon: path.join(appDir, "stage", "icon-large.png"),
titleBarStyle: "hidden",
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/hint/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const hintSlash = (key: string, protyle: IProtyle) => {
value: Constants.ZWSP + 5,
html: '<div class="b3-list-item__first"><svg class="b3-list-item__graphic"><use xlink:href="#iconSparkles"></use></svg><span class="b3-list-item__text">AI Chat</span></div>',
},{
filter: ["数据库", "属性视图", "shujuku", "shuxingshitu", "sjk", "sxst", "database", "attribute view"],
filter: ["数据库", "视图", "shujuku", "shitu", "sjk", "st", "database", "view", "db"],
value: '<div data-type="NodeAttributeView" data-av-type="table"></div>',
html: `<div class="b3-list-item__first"><svg class="b3-list-item__graphic"><use xlink:href="#iconDatabase"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.database}</span></div>`,
}, {
Expand Down
8 changes: 4 additions & 4 deletions app/src/protyle/util/insertHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
}
} else if (tempElement.content.querySelector("table")) {
tempElement.content.querySelectorAll("tr").forEach(item => {
values.push([])
values.push([]);
Array.from(item.children).forEach(cell => {
values[values.length - 1].push({
text: {content: cell.textContent},
Expand All @@ -51,7 +51,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
const avID = blockElement.dataset.avId;
const id = blockElement.dataset.nodeId;
let currentRowElement: Element;
const firstColIndex = cellElements[0].getAttribute("data-col-id")
const firstColIndex = cellElements[0].getAttribute("data-col-id");
values.find(rowItem => {
if (!currentRowElement) {
currentRowElement = cellElements[0].parentElement;
Expand All @@ -64,9 +64,9 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
let cellElement: HTMLElement;
rowItem.find(cellValue => {
if (!cellElement) {
cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement
cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement;
} else {
cellElement = cellElement.nextElementSibling as HTMLElement
cellElement = cellElement.nextElementSibling as HTMLElement;
}
if (!cellElement.classList.contains("av__cell")) {
return true;
Expand Down
5 changes: 3 additions & 2 deletions app/src/protyle/util/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {cellScrollIntoView} from "../render/av/cell";

export const pasteEscaped = async (protyle: IProtyle, nodeElement: Element) => {
try {
// * _ [ ] ! \ ` < > & ~ { } ( ) = # $ ^ |
// * _ [ ] ! \ ` < > & ~ { } ( ) = # $ ^ | .
let clipText = await readText();
// https://github.com/siyuan-note/siyuan/issues/5446
// A\B\C\D\
Expand Down Expand Up @@ -47,7 +47,8 @@ export const pasteEscaped = async (protyle: IProtyle, nodeElement: Element) => {
.replace(/#/g, "\\#")
.replace(/\$/g, "\\$")
.replace(/\^/g, "\\^")
.replace(/\|/g, "\\|");
.replace(/\|/g, "\\|")
.replace(/\./g, "\\.");
pasteText(protyle, clipText, nodeElement);
} catch (e) {
console.log(e);
Expand Down
2 changes: 1 addition & 1 deletion kernel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
code.sajari.com/docconv v1.3.8
github.com/88250/clipboard v0.1.5
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/gulu v1.2.3-0.20231209020950-b7b6994e395c
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30
github.com/88250/lute v1.7.7-0.20240317033923-b5d564e25df7
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 @@ -8,8 +8,8 @@ github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48 h1:qiE88Pw/9GG8hvMfpfB4
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48/go.mod h1:UgVSq5iO9pOvqs3hIGNVk6WXDiAB0v3Dlg4nssQJ7W4=
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.20231209020950-b7b6994e395c h1:Fas3hxqP33xA9KKDV50jUmppiiOukk5bdV00Hk5VSSk=
github.com/88250/gulu v1.2.3-0.20231209020950-b7b6994e395c/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30 h1:IeE4DVRWnVpcbMj7gGZoSMiBWs3h/ihiyOmualS1Mas=
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240317033923-b5d564e25df7 h1:egkoxNZeGBDcUCd4kUHgeYIZZ7uNHTK+TT+K2yZTHm0=
github.com/88250/lute v1.7.7-0.20240317033923-b5d564e25df7/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
Expand Down
27 changes: 20 additions & 7 deletions kernel/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,13 +1177,13 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
table = "blocks_fts_case_insensitive"
}
projections := "id, parent_id, root_id, hash, box, path, " +
// Improve the highlight snippet when search result content is too long https://github.com/siyuan-note/siyuan/issues/9215
"snippet(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 192) AS hpath, " +
"snippet(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 192) AS name, " +
"snippet(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 192) AS alias, " +
"snippet(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 192) AS memo, " +
// Search result content snippet returns more text https://github.com/siyuan-note/siyuan/issues/10707
"snippet(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 512) AS hpath, " +
"snippet(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 512) AS name, " +
"snippet(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 512) AS alias, " +
"snippet(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 512) AS memo, " +
"tag, " +
"snippet(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 192) AS content, " +
"snippet(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 512) AS content, " +
"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
stmt := "SELECT " + projections + " FROM " + table + " WHERE (`" + table + "` MATCH '" + columnFilter() + ":(" + query + ")'"
stmt += ") AND type IN " + typeFilter
Expand Down Expand Up @@ -1315,7 +1315,20 @@ func fromSQLBlock(sqlBlock *sql.Block, terms string, beforeLen int) (block *Bloc
}

id := sqlBlock.ID
content := util.EscapeHTML(sqlBlock.Content) // Search dialog XSS https://github.com/siyuan-note/siyuan/issues/8525
content := sqlBlock.Content
if 1 < strings.Count(content, search.SearchMarkRight) && strings.HasSuffix(content, search.SearchMarkRight+"...") {
// 返回多个关键字命中时需要检查最后一个关键字是否被截断
firstKeyword := gulu.Str.SubStringBetween(content, search.SearchMarkLeft, search.SearchMarkRight)
lastKeyword := gulu.Str.LastSubStringBetween(content, search.SearchMarkLeft, search.SearchMarkRight)
if firstKeyword != lastKeyword {
// 如果第一个关键字和最后一个关键字不相同,说明最后一个关键字被截断了
// 此时需要将 content 中的最后一个关键字替换为完整的关键字
content = strings.TrimSuffix(content, search.SearchMarkLeft+lastKeyword+search.SearchMarkRight+"...")
content += search.SearchMarkLeft + firstKeyword + search.SearchMarkRight + "..."
}
}

content = util.EscapeHTML(content) // Search dialog XSS https://github.com/siyuan-note/siyuan/issues/8525
content, _ = markSearch(content, terms, beforeLen)
content = maxContent(content, 5120)
markdown := maxContent(sqlBlock.Markdown, 5120)
Expand Down

0 comments on commit a0bb28b

Please sign in to comment.