From a22ad2f0251600547d17ba985c9de592f2da4051 Mon Sep 17 00:00:00 2001 From: obgnail Date: Sat, 5 Aug 2023 14:02:05 +0800 Subject: [PATCH 1/6] =?UTF-8?q?update=20window=5Ftab.js=EF=BC=8C=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E6=A0=87=E7=AD=BE=E4=B8=8D=E5=85=81=E8=AE=B8=E5=9C=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=A0=87=E7=AD=BE=E6=89=93=E5=BC=80=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/window_tab/window_tab.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugin/window_tab/window_tab.js b/plugin/window_tab/window_tab.js index a9357766..ffcaa14f 100644 --- a/plugin/window_tab/window_tab.js +++ b/plugin/window_tab/window_tab.js @@ -224,6 +224,8 @@ const metaKeyPressed = ev => File.isMac ? ev.metaKey : ev.ctrlKey; + const getFilePath = () => File.filePath || File.bundle && File.bundle.filePath; + // 新窗口打开 const openFileNewWindow = (path, isFolder) => File.editor.library.openFileInNewWindow(path, isFolder) // 新标签页打开 @@ -673,9 +675,10 @@ args.push({arg_name: "打开保存的标签页", arg_value: "open_save_tabs"}); } if (config.LOCAL_OPEN) { - args.push({arg_name: "新标签打开文件", arg_value: "new_tab_open"}); - } else { - args.push({arg_name: "当前标签打开文件", arg_value: "local_open"}); + args.push({arg_name: "在新标签打开文件", arg_value: "new_tab_open"}); + // 空白标签不允许当前标签打开 + } else if (getFilePath()) { + args.push({arg_name: "在当前标签打开文件", arg_value: "local_open"}); } return args } From 3981514c6c460e7f2c30d4a0793e31bf4623f549 Mon Sep 17 00:00:00 2001 From: obgnail Date: Sat, 5 Aug 2023 16:31:13 +0800 Subject: [PATCH 2/6] update readme --- README.md | 8 ++++---- plugin/auto_number.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 636918d8..a3e58b95 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ | 17 | mermaid_replace | 替换 mermaid 组件 | × | | 18 | old_window_tab | 标签页管理(已废弃) | × | -1. 每个功能都对应源码的 plugin 文件夹下的一个同名文件(index.js 除外),**如若不需要某些功能,按需删除文件即可**。 +1. 每个功能都对应源码的 plugin 文件夹下的一个同名文件(index.js 除外),**如若不需要某些功能,按需删除/改名文件即可**。 2. 每个功能都有对应的配置,且配置选项都有注释说明。可以按需修改对应 JS 文件里的 config。 > 如果各位有其他的需求,或发现 BUG,欢迎提 issue。如果能给我颗 star ⭐ 就更好了 : ) @@ -117,7 +117,7 @@ JSBridge.invoke('executeJavaScript', 1, "_myValue=123; JSBridge.invoke('executeJ ### window_tab:标签页管理 -- `鼠标置于标签页处,ctrl+鼠标滚轮`、`ctrl+shift+tab`、`ctrl+tab`:切换标签 +- `鼠标置于标签页处,ctrl+滚轮`、`ctrl+shift+tab`、`ctrl+tab`、`ctrl+PgUp`、`ctrl+PgDn`:切换标签 - `ctrl+w`:关闭标签 - `ctrl+click 标签`、`向下拖拽标签`:新窗口打开 - `拖拽`:排序标签 @@ -243,9 +243,9 @@ const BUILTIN = [ ![auto_number](assets/auto_number.png) -支持编号(皆可单独打开/关闭): +支持编号的组件(皆可单独打开/关闭): -1. 章节 +1. 标题 2. 大纲 3. TOC 4. 表格 diff --git a/plugin/auto_number.js b/plugin/auto_number.js index 24ea0f3c..c1b0024a 100644 --- a/plugin/auto_number.js +++ b/plugin/auto_number.js @@ -249,10 +249,10 @@ const ele = document.getElementById("plugin-auto-number-style"); let arg_name, arg_value; if (ele) { - arg_name = "临时禁用"; + arg_name = "禁用"; arg_value = "disable"; } else { - arg_name = "重新启用"; + arg_name = "启用"; arg_value = "enable"; } return [{arg_name, arg_value}] From a14bfe528311c58a6d0d9c1549ba19aae213c712 Mon Sep 17 00:00:00 2001 From: obgnail Date: Sat, 5 Aug 2023 17:50:01 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/window_tab/window_tab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/window_tab/window_tab.js b/plugin/window_tab/window_tab.js index ffcaa14f..65ec9eba 100644 --- a/plugin/window_tab/window_tab.js +++ b/plugin/window_tab/window_tab.js @@ -297,7 +297,7 @@ const stopCount = 3; const scrollTop = activeTab.scrollTop; const _timer = setInterval(() => { - const filePath = File && File.filePath || File && File.bundle && File.bundle.filePath; + const filePath = getFilePath(); if (filePath === activeTab.path && entities.content.scrollTop !== scrollTop) { entities.content.scrollTop = scrollTop; count = 0; @@ -373,7 +373,7 @@ File.editor.library.openFile = decorator(File.editor.library.openFile, after); - const filePath = File.filePath || File.bundle && File.bundle.filePath; + const filePath = getFilePath(); if (filePath) { openTab(filePath); } From f6db434e6458318c6d4b487fc81d04d433e7a3ac Mon Sep 17 00:00:00 2001 From: obgnail Date: Sun, 6 Aug 2023 11:59:17 +0800 Subject: [PATCH 4/6] =?UTF-8?q?update=20window=5Ftab.js=EF=BC=8Cauto=20dum?= =?UTF-8?q?p=20to=20save=20file=20activePath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/window_tab/window_tab.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugin/window_tab/window_tab.js b/plugin/window_tab/window_tab.js index 65ec9eba..d8112e84 100644 --- a/plugin/window_tab/window_tab.js +++ b/plugin/window_tab/window_tab.js @@ -329,6 +329,15 @@ openFile(tabUtil.tabs[tabUtil.activeIdx].path); } + const switchTabByPath = path => { + for (let idx = 0; idx < tabUtil.tabs.length; idx++) { + if (tabUtil.tabs[idx].path === path) { + switchTab(idx); + return + } + } + } + const previousTab = () => { const idx = (tabUtil.activeIdx === 0) ? tabUtil.tabs.length - 1 : tabUtil.activeIdx - 1; switchTab(idx); @@ -654,6 +663,7 @@ const dataset = JSON.parse(data); const tabs = dataset["save_tabs"]; + let activePath; tabs.forEach(tab => { const existTab = tabUtil.tabs.filter(t => t.path === tab.path)[0]; if (!existTab) { @@ -661,8 +671,16 @@ } else { existTab.scrollTop = tab.scrollTop; } + + if (tab.active) { + activePath = tab.path; + } }) - switchTab(tabUtil.activeIdx); + if (activePath) { + switchTabByPath(activePath); + } else { + switchTab(tabUtil.activeIdx); + } }) } From a0095f9a0e8a15d90f7eb18c7375f59a7c7b34fb Mon Sep 17 00:00:00 2001 From: obgnail Date: Sun, 6 Aug 2023 12:24:21 +0800 Subject: [PATCH 5/6] update right click mune, add disabled class --- plugin/right_click_menu.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/right_click_menu.js b/plugin/right_click_menu.js index 3abb95c2..c32cb06d 100644 --- a/plugin/right_click_menu.js +++ b/plugin/right_click_menu.js @@ -62,7 +62,8 @@ } const createThirdLi = (arg, dynamic) => { - const className = (dynamic) ? `class="plugin-dynamic-arg"` : ""; + const disabled = (arg.arg_disabled) ? " disabled" : ""; + const className = (dynamic) ? `class="plugin-dynamic-arg${disabled}"` : ""; return `
  • ${arg.arg_name}
  • ` } @@ -118,6 +119,7 @@ appendThirdLi(menu, [{ arg_name: "光标于此位置不可用", arg_value: "not_available", + arg_disabled: true, }]) } From 3c3d0d9f6cb546ad290fb71e27b24249038b4357 Mon Sep 17 00:00:00 2001 From: obgnail Date: Sun, 6 Aug 2023 12:40:06 +0800 Subject: [PATCH 6/6] =?UTF-8?q?right=20click=20menu,=E7=BB=86=E5=B0=8F?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/right_click_menu.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugin/right_click_menu.js b/plugin/right_click_menu.js index c32cb06d..92fe70dc 100644 --- a/plugin/right_click_menu.js +++ b/plugin/right_click_menu.js @@ -2,6 +2,8 @@ const config = { // 点击后是否隐藏菜单 DO_NOT_HIDE: false, + + NOT_AVAILABLE_VALUE: "__not_available__", LOOP_DETECT_INTERVAL: 200 } @@ -118,7 +120,7 @@ const appendDummyThirdLi = menu => { appendThirdLi(menu, [{ arg_name: "光标于此位置不可用", - arg_value: "not_available", + arg_value: config.NOT_AVAILABLE_VALUE, arg_disabled: true, }]) } @@ -127,8 +129,10 @@ // 在二级菜单中调用插件 $("#plugin-menu").on("click", "[data-key]", function () { const fixed_name = this.getAttribute("data-key"); - const plugins = enablePlugins.filter(plugin => plugin.fixed_name === fixed_name); - plugins && plugins[0] && plugins[0].call && plugins[0].call(); + const plugin = enablePlugins.filter(plugin => plugin.fixed_name === fixed_name)[0]; + if (plugin && plugin.call) { + plugin.call(); + } if (!config.DO_NOT_HIDE) { File.editor.contextMenu.hide(); } @@ -168,8 +172,10 @@ $(".plugin-menu-third").on("click", "[data-key]", function () { const fixedName = this.parentElement.getAttribute("fixed_name"); const argValue = this.getAttribute("arg_value"); - const plugins = enablePlugins.filter(plugin => plugin.fixed_name === fixedName); - (argValue !== "not_available") && plugins && plugins[0] && plugins[0].call && plugins[0].call(argValue); + const plugin = enablePlugins.filter(plugin => plugin.fixed_name === fixedName)[0]; + if (argValue !== config.NOT_AVAILABLE_VALUE && plugin && plugin.call) { + plugin.call(argValue); + } if (!config.DO_NOT_HIDE) { File.editor.contextMenu.hide(); }