Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
添加中键缩放图片功能
  • Loading branch information
Misuzu2027 committed Nov 16, 2024
1 parent 3536efa commit f64e3f8
Show file tree
Hide file tree
Showing 12 changed files with 416 additions and 63 deletions.
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.4",
"version": "0.0.5",
"minAppVersion": "3.0.14",
"backends": [
"all"
Expand Down
8 changes: 5 additions & 3 deletions public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"AdjustCodeBlockHeightTips": "If the maximum height is set, the drag range will not exceed it.",
"DisplayCollapseExpandCodeBlockButton": "Display Collapse/Expand Button for Code Block",
"CollapsedCodeBlockHeight": "Collapsed Code Block Height",
"FileTree":"Doc Tree",
"FileTree": "Doc Tree",
"KeywordFilterNotebooks": "Keyword Filter for Notebooks",
"KeywordFilterNotebooksMatchSubdocuments": "Keyword Filter for Notebooks - Match Subdocuments"

"KeywordFilterNotebooksMatchSubdocuments": "Keyword Filter for Notebooks - Match Subdocuments",
"MiddleClickToggleDocTree": "Middle-click to expand/collapse notebooks or documents",
"Image": "Image",
"MiddleClickResizeImageWidth": "Middle-click to resize image width"
}
6 changes: 4 additions & 2 deletions public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"CollapsedCodeBlockHeight": "代码块折叠后高度",
"FileTree":"文档树",
"KeywordFilterNotebooks": "关键字过滤笔记本",
"KeywordFilterNotebooksMatchSubdocuments": "关键字过滤笔记本-匹配子文档"

"KeywordFilterNotebooksMatchSubdocuments": "关键字过滤笔记本-匹配子文档",
"MiddleClickToggleDocTree":"中键展开/折叠笔记本或文档",
"Image":"图片",
"MiddleClickResizeImageWidth":"中键图片缩放宽度"
}
127 changes: 73 additions & 54 deletions src/components/filetree/FileTreeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import Instance from "@/utils/Instance";
import { containsAllKeywords, isStrBlank, isValidStr, splitKeywordStringToArray } from "@/utils/string-util";

export class FileTreeService {
private intervalId;
private intervalInitFileTreeSearchInputId;
private intervalInitFileTreeMiddleClickToggleId;


public static get ins(): FileTreeService {
Expand All @@ -20,16 +21,31 @@ export class FileTreeService {

if (fileTreeKeywordFilter) {
initFileTreeSearchInput();
this.intervalId = setInterval(initFileTreeSearchInput, 1000)
this.intervalInitFileTreeSearchInputId = setInterval(initFileTreeSearchInput, 2000)
} else {
this.destroy();
this.destoryFileTreeKeywordFilter();
}
let fileTreeMiddleClickToggle = SettingService.ins.SettingConfig.fileTreeMiddleClickToggle;
if (fileTreeMiddleClickToggle) {
addFileTreeMiddleClickToggle();
this.intervalInitFileTreeMiddleClickToggleId = setInterval(addFileTreeMiddleClickToggle, 2000)
} else {
this.destoryFileTreeMiddleClickToggle();
}



}

public destroy() {
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;
this.destoryFileTreeKeywordFilter();
this.destoryFileTreeMiddleClickToggle();
}

public destoryFileTreeKeywordFilter() {
if (this.intervalInitFileTreeSearchInputId) {
clearInterval(this.intervalInitFileTreeSearchInputId);
this.intervalInitFileTreeSearchInputId = null;
}

let inputElement = document.querySelector("div.file-tree.sy__file div.misuzu2027__search-div");
Expand All @@ -43,6 +59,15 @@ export class FileTreeService {
removeNotebookOrDocHide();
}

public destoryFileTreeMiddleClickToggle() {
document.querySelector('.sy__file').removeEventListener('mousedown', handleDocToggle);
if (this.intervalInitFileTreeMiddleClickToggleId) {
clearInterval(this.intervalInitFileTreeMiddleClickToggleId);
this.intervalInitFileTreeMiddleClickToggleId = null;
}
}


}
let searchKeywordArray: string[] = [];
let hideNotebookIdArray: string[] = [];
Expand Down Expand Up @@ -221,51 +246,45 @@ function removeNotebookOrDocHide() {

}

// let lastNoteBookMap;
// function initFileTreeElement() {
// let fileTreeElement = document.querySelector("#layouts div.layout-tab-container div.file-tree.sy__file > div.fn__flex-1");
// if (!fileTreeElement) {
// return
// }
// let notebookMap = getNotebookMap();
// if (areMapsEqual(lastNoteBookMap, notebookMap)) {
// return;
// }
// lastNoteBookMap = notebookMap;
// console.log(`FileTreeService notebookMap `, notebookMap)
// let boxGroupElement = document.createElement("div");
// boxGroupElement.classList.add("b3-list", "b3-list--background");
// boxGroupElement.innerHTML = `
// <div class="b3-list-item b3-list-item--hide-action" style="margin:1px 0px">
// <span class="b3-list-item__toggle b3-list-item__arrow--open">
// <svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg>
// </span>
// <span class="b3-list-item__icon b3-tooltips b3-tooltips__e">🗃</span>
// <span class="b3-list-item__text" style="font-weight: bold;">测试文档分组</span>
// </div>
// `;


// let boxUlElement = fileTreeElement.querySelector(`ul[data-url="${notebookMap.keys().next().value}"].b3-list.b3-list--background`);

// boxUlElement.before(boxGroupElement);
// boxGroupElement.append(boxUlElement);
// boxGroupElement.style.margin = "1px 0px"
// }


// function getNotebookMap(): Map<string, string> {
// let fileTreeElement = document.querySelector("#layouts div.layout-tab-container div.file-tree.sy__file > div.fn__flex-1");
// let idNameMap = new Map<string, string>();
// let boxUlElementArray = fileTreeElement.querySelectorAll("ul[data-url].b3-list.b3-list--background");
// for (const ulElement of boxUlElementArray) {
// let boxId = ulElement.getAttribute("data-url");
// let boxNameElement = ulElement.querySelector("li.b3-list-item > span.b3-list-item__text")
// let boxName = boxNameElement.textContent;
// if (isValidStr(boxId) && isValidStr(boxName)) {
// idNameMap.set(boxId, boxName);
// }
// }

// return idNameMap;
// }

function addFileTreeMiddleClickToggle() {
let fileTreeDocElement = document.querySelector("#layouts div.layout-tab-container div.file-tree.sy__file");
if (!fileTreeDocElement) {
return;
}
FileTreeService.ins.destoryFileTreeMiddleClickToggle();

document.querySelector('.sy__file').addEventListener('mousedown', handleDocToggle);
}

function handleDocToggle(event: MouseEvent) {
if (event.button != 1) return;
let clickTarget = event.target as HTMLElement;
let fileTreeMiddleClickToggle = SettingService.ins.SettingConfig.fileTreeMiddleClickToggle;
if (!fileTreeMiddleClickToggle) {
return;
}

let liElement = clickTarget.parentElement;
let temp = event.target as HTMLElement;
for (let i = 0; i < 4 && temp; i++) {
if (temp?.getAttribute("data-type") == "navigation-file"
|| temp?.getAttribute("data-type") == "navigation-root") {
liElement = temp;
break;
}
temp = temp?.parentElement;
}

if (liElement?.getAttribute("data-type") == "navigation-file"
|| liElement?.getAttribute("data-type") == "navigation-root") {
const b3ListItemToggleElement = liElement.querySelector('.b3-list-item__toggle') as HTMLElement;
const titleElement = liElement.querySelector('.b3-list-item__text') as HTMLElement;
if (b3ListItemToggleElement.classList.contains('fn__hidden')) return;
event.preventDefault();
b3ListItemToggleElement.click();
if (event.ctrlKey) {
titleElement.click();
}
}
}
Loading

0 comments on commit f64e3f8

Please sign in to comment.