Skip to content

Commit

Permalink
update templater: add auto_open config
Browse files Browse the repository at this point in the history
  • Loading branch information
obgnail committed Aug 23, 2023
1 parent 897b7d0 commit 6fd8efd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions plugin/custom/custom_plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ name = "复制标题路径"
enable = true
plugin = "fullPathCopy"
[plugins.config]
# 跳过空白的标题
ignore_empty_header = false
# 标题和提示之前添加空格
add_space = true
# 使用绝对路径
full_file_path = false

[[plugins]]
name = "提取选区文字到新文件"
enable = true
plugin = "extractRangeToNewFile"
[plugins.config]
# 展示模态框
show_modal = true
# 自动打开新文件
auto_open = true

[[plugins]]
name = "文件模板"
enable = true
plugin = "templater"
[plugins.config]
# 自动打开新文件
auto_open = true
[[plugins.template]]
name = "标准模板"
text = """
Expand Down
7 changes: 6 additions & 1 deletion plugin/custom/plugins/extractRangeToNewFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ class extractRangeToNewFile extends BaseCustomPlugin {

extract = filepath => {
filepath = this.utils.newFilePath(filepath);
this.promise.then(text => this.utils.Package.Fs.writeFileSync(filepath, text, "utf8"));
this.promise.then(text => {
this.utils.Package.Fs.writeFileSync(filepath, text, "utf8");
if (this.config.auto_open) {
this.utils.openFile(filepath);
}
});
}
}

Expand Down
3 changes: 3 additions & 0 deletions plugin/custom/plugins/templater.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class templater extends BaseCustomPlugin {
const content = helper.convert(template.text);
this.utils.Package.Fs.writeFileSync(filepath, content, "utf8");
this.rangeText = "";
if (this.config.auto_open) {
this.utils.openFile(filepath);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions plugin/global/core/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ class utils {
return fileName
}

static openFile = filepath => {
if (this.getPlugin("window_tab")) {
File.editor.library.openFile(filepath);
} else {
File.editor.library.openFileInNewWindow(filepath, false);
}
}

static toHotkeyFunc = hotkeyString => {
const keyList = hotkeyString.toLowerCase().split("+").map(k => k.trim());
const ctrl = keyList.indexOf("ctrl") !== -1;
Expand Down

0 comments on commit 6fd8efd

Please sign in to comment.