Skip to content

Commit

Permalink
Merge pull request #825 from obgnail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
obgnail authored Oct 29, 2024
2 parents 8b2ce42 + 64f3e78 commit 372b4ac
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,19 @@
| 45 | noImageMode | 无图模式 | |
| 46 | pluginUpdater | 一键升级插件 | |
| 47 | easy_modify | 编辑工具 | |
| 48 | redirectLocalRootUrl | 重定向本地资源根目录 | × |
| 49 | blockSideBySide | 并列显示活动块 | × |
| 50 | scrollBookmarker | 书签管理器 | × |
| 51 | openInTotalCommander | 在 total commander 打开 | × |
| 52 | cipher | 加密文件 | × |
| 53 | ripgrep | 使用 ripgrep 搜索文件 | × |
| 54 | article_uploader | 一键上传博客到支持的所有平台 | × |
| 55 | help | 用户帮助 | |
| 56 | custom | 开放平台,用户自定义插件(高级) | |
| 57 | hotkeyHub | 快捷键注册中心(高级) | |
| 58 | quickButton | 于右下角添加功能按钮(高级) | |
| 59 | json_rpc | 外部操纵 Typora(高级) | × |
| 48 | editor_width_slider | 写作区宽度调整 | |
| 49 | redirectLocalRootUrl | 重定向本地资源根目录 | × |
| 50 | blockSideBySide | 并列显示活动块 | × |
| 51 | scrollBookmarker | 书签管理器 | × |
| 52 | openInTotalCommander | 在 total commander 打开 | × |
| 53 | cipher | 加密文件 | × |
| 54 | ripgrep | 使用 ripgrep 搜索文件 | × |
| 55 | article_uploader | 一键上传博客到支持的所有平台 | × |
| 56 | help | 用户帮助 | |
| 57 | custom | 开放平台,用户自定义插件(高级) | |
| 58 | hotkeyHub | 快捷键注册中心(高级) | |
| 59 | quickButton | 于右下角添加功能按钮(高级) | |
| 60 | json_rpc | 外部操纵 Typora(高级) | × |

**尊重用户的一切选择**。本项目的任何插件、任何功能皆可永久启用 / 禁用。

Expand Down Expand Up @@ -759,6 +760,14 @@ icon = "\\f040"



### editor_width_slider:写作区宽度调整

使用方式:右键菜单 -> 少用插件 -> 写作区宽度调整

功能:调整写作区的宽度



### redirectLocalRootUrl:重定向本地资源根目录

功能:如果你主要使用 obsidian 或 joplin 来管理文件,偶尔用 typora 打开文件。就会遇到一个问题:obsidian 或 joplin 都是将本地资源放在同一个目录中(vault),这导致在 typora 打开后文件由于路径错误,无法访问本地资源。此插件就是为了解决此问题,重定向本地资源根目录。
Expand Down
2 changes: 0 additions & 2 deletions plugin/_obgnail__typora_plugin.url

This file was deleted.

20 changes: 16 additions & 4 deletions plugin/easy_modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class easyModifyPlugin extends BasePlugin {

init = () => {
const arg_hint = "若无选中文段,则调整整篇文档";
this._showWarnDialog = true;
this.callArgs = [
{ arg_name: "复制标题路径", arg_value: "copy_full_path", arg_hotkey: this.config.HOTKEY_COPY_FULL_PATH },
{ arg_name: "提升选中文段的标题等级", arg_value: "increase_headers_level", arg_hotkey: this.config.HOTKEY_INCREASE_HEADERS_LEVEL, arg_hint },
Expand Down Expand Up @@ -52,14 +53,16 @@ class easyModifyPlugin extends BasePlugin {
increase_headers_level: () => this.changeHeadersLevel(true),
decrease_headers_level: () => this.changeHeadersLevel(false),
copy_full_path: () => this.copyFullPath(),
trailing_white_space: () => this.trailingWhiteSpace(),
trailing_white_space: async () => this.trailingWhiteSpace(),
insert_mermaid_mindmap: () => this.insertMindmap("mindmap", meta.insertTarget),
insert_mermaid_graph: () => this.insertMindmap("graph", meta.insertTarget),
extract_rang_to_new_file: async () => this.extractRangeToNewFile(meta.range),
}
const func = funcMap[type];
if (func) {
await func();
if (!func) return;

const dontShow = await func();
if (dontShow !== true) {
this.utils.notification.show("执行成功");
}
}
Expand Down Expand Up @@ -160,7 +163,16 @@ class easyModifyPlugin extends BasePlugin {
this.utils.openFile(filepath);
}

trailingWhiteSpace = () => {
trailingWhiteSpace = async () => {
if (this._showWarnDialog) {
const option = { type: "warning", buttons: ["确定", "取消"], message: "为整篇文档添加结尾空格", checkboxLabel: "不再提示(直到关闭Typora)" };
const { response, checkboxChecked } = await this.utils.showMessageBox(option);
if (response === 1) return true;
if (checkboxChecked) {
this._showWarnDialog = false;
}
}

const replaceFlag = 2;
const tailSpace = " ";
this.utils.entities.querySelectorAllInWrite("p[cid]").forEach(ele => {
Expand Down
36 changes: 36 additions & 0 deletions plugin/editor_width_slider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class editorWidthSliderPlugin extends BasePlugin {
process = async () => {
this.utils.runtime.autoSaveConfig(this);
await this._setWidth();
}

_setWidth = async (width = this.config.WIDTH_RATIO) => {
const { eWrite } = this.utils.entities;
if (width < 0) {
eWrite.style.removeProperty("max-width");
} else {
eWrite.style.setProperty("max-width", `${width}%`, "important");
}
}

setWidth = async () => {
const { eContent, eWrite } = this.utils.entities;
const value = parseInt(eWrite.offsetWidth * 100 / eContent.offsetWidth);
const oninput = ev => this._setWidth(ev.target.value);
const components = [
{ label: "宽度百分比", type: "range", min: 30, max: 100, step: 1, value, oninput },
{ label: "", type: "checkbox", list: [{ label: "还原宽度设置", value: "recover" }] },
];
const { response, submit: [width, [checkbox]] } = await this.utils.dialog.modalAsync({ title: "写作区宽度", components });
if (response === 1) {
this.config.WIDTH_RATIO = checkbox === "recover" ? -1 : width;
}
await this._setWidth();
}

call = async (type, meta) => await this.setWidth()
}

module.exports = {
plugin: editorWidthSliderPlugin,
};
11 changes: 11 additions & 0 deletions plugin/global/settings/settings.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ LIST = [
"pie_menu",
"go_top",
"text_stylize",
"editor_width_slider",
"slash_commands",
"ripgrep",
"article_uploader",
Expand Down Expand Up @@ -1138,6 +1139,16 @@ ENABLE = true
NAME = "帮助"


############### editor_width_slider ###############
[editor_width_slider]
# 启用插件
ENABLE = true
# 插件名称
NAME = "写作区宽度调整"
# 宽度百分比(小于0视为不启用)
WIDTH_RATIO = -1


############### article_uploader ###############
[article_uploader]
# 启用插件
Expand Down

0 comments on commit 372b4ac

Please sign in to comment.