Skip to content

Commit

Permalink
v0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Misuzu2027 committed Nov 10, 2024
1 parent 28251f2 commit 6b991cc
Show file tree
Hide file tree
Showing 10 changed files with 418 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
* 代码块支持展开折叠
* 文档树
* 通过关键字过滤笔记本
* 支持匹配笔记本下的子文档来过滤笔记本。


2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "syplugin-misuzu-custom",
"author": "Misuzu2027",
"url": "https://github.com/Misuzu2027/syplugin-misuzu-custom",
"version": "0.0.2",
"version": "0.0.3",
"minAppVersion": "3.0.14",
"backends": [
"all"
Expand Down
4 changes: 4 additions & 0 deletions src/components/code-block/code-block-toggle-button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
if (isNaN(foldHeight) || foldHeight <= 150) {
foldHeight = 150;
}
if (hljsElement.scrollHeight < foldHeight) {
return;
}
// blockExpand = hljsElement.clientHeight >= hljsElement.scrollHeight;
if (blockExpand) {
hljsElement.style.height = foldHeight + "px";
Expand Down
39 changes: 34 additions & 5 deletions src/components/filetree/FileTreeService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { SettingService } from "@/service/SettingService";
import { DocumentQueryCriteria, generateDocumentListSql } from "@/service/SqlService";
import { sql } from "@/utils/api";
import { isArrayNotEmpty } from "@/utils/array-util";
import { clearCssHighlights, highlightContent, highlightElementTextByCss } from "@/utils/html-util";
import Instance from "@/utils/Instance";
import { containsAllKeywords, splitKeywordStringToArray } from "@/utils/string-util";

Expand Down Expand Up @@ -65,26 +69,51 @@ function initFileTreeSearchInput() {

anchorElement.insertAdjacentElement('afterend', searchDivElement);

searchInputElement.addEventListener("input", (event: InputEvent) => {
console.log("searchInputElement input")
searchInputElement.addEventListener("input", async (event: InputEvent) => {
// console.log("searchInputElement input")
if (event.isComposing) {
return;
}
let searchKeyword = searchInputElement.value;
let keywordArray = splitKeywordStringToArray(searchKeyword);
let keywordArray = splitKeywordStringToArray(searchKeyword.toLowerCase());

let matchedSubDocs = SettingService.ins.SettingConfig.fileTreeKeywordFilterWithMatchedSubDocs;
let docFullTextSearch = false;
let includeConcatFields = ["content", "tag", "name", "alias", "memo"];

let validSubdocsNotebookId = []

if (matchedSubDocs && isArrayNotEmpty(keywordArray)) {
let queryCriteria: DocumentQueryCriteria = new DocumentQueryCriteria(
keywordArray, docFullTextSearch, null, null, null, null, includeConcatFields, null, null);

let queryDocListSql = generateDocumentListSql(queryCriteria)
let docBlockList: Block[] = await sql(queryDocListSql);
for (const docBlock of docBlockList) {
validSubdocsNotebookId.push(docBlock.box);
}
}
clearCssHighlights();



let boxUlElementArray = fileTreeDocElement.querySelectorAll("ul[data-url].b3-list.b3-list--background");
for (const ulElement of boxUlElementArray) {

let boxNameElement = ulElement.querySelector("li.b3-list-item > span.b3-list-item__text")
let boxName = boxNameElement.textContent;
if (containsAllKeywords(boxName, keywordArray)) {
let boxName = boxNameElement.textContent.toLowerCase();
let boxId = ulElement.getAttribute("data-url");
if (containsAllKeywords(boxName, keywordArray) || validSubdocsNotebookId.includes(boxId)) {
highlightElementTextByCss(ulElement as HTMLElement, keywordArray)

ulElement.classList.remove("fn__none");
} else {
ulElement.classList.add("fn__none");
}
}



})

}
Expand Down
10 changes: 10 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
::highlight(misuzu-custom-search-result-mark) {
background-color: var(--b3-protyle-inline-mark-background);
color: var(--b3-protyle-inline-mark-color);
}

::highlight(misuzu-custom-search-result-focus) {
background-color: var(--b3-theme-primary-lighter);
color: var(--b3-protyle-inline-mark-color);
}

/* 引用文本样式 */
body.misuzu2027.ref-text__brackets .protyle-wysiwyg [data-node-id] span[data-type*="block-ref"]:not([data-type="virtual-block-ref"]):not([data-type*="sup"]):not([data-type*="sub"]):not(.av__celltext--ref) {
font-weight: inherit;
Expand Down
2 changes: 2 additions & 0 deletions src/models/setting-constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function getDefaultSettingConfig() {
defaultConfig.codeBlockTopLanguages = "";

defaultConfig.fileTreeKeywordFilter = false;
defaultConfig.fileTreeKeywordFilterWithMatchedSubDocs = false;


return defaultConfig;
Expand Down Expand Up @@ -49,6 +50,7 @@ export function getSettingTabArray(): TabProperty[] {
new TabProperty({
key: "file-tree-setting", name: "文档树", iconKey: "iconPlugin", props: [
new ItemProperty({ key: "fileTreeKeywordFilter", type: "switch", name: "关键字过滤笔记本", description: "", tips: "" }),
new ItemProperty({ key: "fileTreeKeywordFilterWithMatchedSubDocs", type: "switch", name: "关键字过滤笔记本-匹配子文档", description: "", tips: "" }),
// new ItemProperty({ key: "documentBottomDisplay", type: "switch", name: "文档底部显示反链面板", description: "", tips: "" }),
// new ItemProperty({ key: "topBarDisplay", type: "switch", name: "桌面端顶栏创建反链页签 Icon", description: "", tips: "" }),
// new ItemProperty({ key: "cacheAfterResponseMs", type: "number", name: "启用缓存门槛(毫秒)", description: "当接口响应时间超过这个数,就会把这次查询结果存入缓存,-1 不开启缓存", tips: "", min: -1 }),
Expand Down
1 change: 1 addition & 0 deletions src/models/setting-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SettingConfig {

// 文档树
fileTreeKeywordFilter: boolean;
fileTreeKeywordFilterWithMatchedSubDocs:boolean;


}
Expand Down
Loading

0 comments on commit 6b991cc

Please sign in to comment.