Skip to content

Commit

Permalink
Merge pull request #62 from obgnail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
obgnail authored Aug 6, 2023
2 parents a95764c + 3c3d0d9 commit de8c5d6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ⭐ 就更好了 : )
Expand Down Expand Up @@ -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 标签``向下拖拽标签`:新窗口打开
- `拖拽`:排序标签
Expand Down Expand Up @@ -243,9 +243,9 @@ const BUILTIN = [

![auto_number](assets/auto_number.png)

支持编号(皆可单独打开/关闭):
支持编号的组件(皆可单独打开/关闭):

1. 章节
1. 标题
2. 大纲
3. TOC
4. 表格
Expand Down
4 changes: 2 additions & 2 deletions plugin/auto_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down
20 changes: 14 additions & 6 deletions plugin/right_click_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
const config = {
// 点击后是否隐藏菜单
DO_NOT_HIDE: false,

NOT_AVAILABLE_VALUE: "__not_available__",
LOOP_DETECT_INTERVAL: 200
}

Expand Down Expand Up @@ -62,7 +64,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 `<li data-key="${arg.arg_name}" arg_value="${arg.arg_value}" ${className}><a role="menuitem" data-lg="Menu">${arg.arg_name}</a></li>`
}

Expand Down Expand Up @@ -117,16 +120,19 @@
const appendDummyThirdLi = menu => {
appendThirdLi(menu, [{
arg_name: "光标于此位置不可用",
arg_value: "not_available",
arg_value: config.NOT_AVAILABLE_VALUE,
arg_disabled: true,
}])
}

const listen = enablePlugins => {
// 在二级菜单中调用插件
$("#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();
}
Expand Down Expand Up @@ -166,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();
}
Expand Down
33 changes: 27 additions & 6 deletions plugin/window_tab/window_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// 新标签页打开
Expand Down Expand Up @@ -295,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;
Expand Down Expand Up @@ -327,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);
Expand Down Expand Up @@ -371,7 +382,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);
}
Expand Down Expand Up @@ -652,15 +663,24 @@
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) {
tabUtil.tabs.push({path: tab.path, scrollTop: tab.scrollTop});
} else {
existTab.scrollTop = tab.scrollTop;
}

if (tab.active) {
activePath = tab.path;
}
})
switchTab(tabUtil.activeIdx);
if (activePath) {
switchTabByPath(activePath);
} else {
switchTab(tabUtil.activeIdx);
}
})
}

Expand All @@ -673,9 +693,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
}
Expand Down

0 comments on commit de8c5d6

Please sign in to comment.