Skip to content

Commit 74f1c57

Browse files
committed
Feat(quickButton): add options button_icon_size, button_box_shadow_on_hover
1 parent 0ab4768 commit 74f1c57

17 files changed

Lines changed: 184 additions & 180 deletions

README-cn.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,24 @@
5959
| 40 | export_enhance | 导出 HTML 时避免图片丢失 | |
6060
| 41 | sidebar_enhance | 显示其他扩展名文件、记忆折叠状态、拖拽排序 | |
6161
| 42 | markdownLint | markdown 格式检查 | |
62-
| 43 | go_top | 一键到文章顶部、底部 | |
63-
| 44 | truncate_text | 暂时隐藏内容,提高大文件渲染性能 | × |
64-
| 45 | dark | 夜间模式 | |
65-
| 46 | no_image | 无图模式 | |
66-
| 47 | myopic_defocus | 离焦视力舒缓 | |
67-
| 48 | updater | 一键升级插件 | |
68-
| 49 | easy_modify | 编辑工具 | |
69-
| 50 | editor_width_slider | 写作区宽度调整 | |
70-
| 51 | redirectLocalRootUrl | 重定向本地资源根目录 | × |
71-
| 52 | scrollBookmarker | 书签管理器 | × |
72-
| 53 | cipher | 加密文件 | × |
73-
| 54 | ripgrep | 使用 ripgrep 搜索文件 | × |
74-
| 55 | article_uploader | 一键上传博客到支持的所有平台 | × |
75-
| 56 | cursor_history | 光标跳转 | × |
76-
| 57 | static_markers | Markdown 标记常显 | × |
77-
| 58 | custom | 开放平台,用户自定义插件(高级) | |
78-
| 59 | hotkeys | 快捷键注册中心(高级) | |
79-
| 60 | quickButton | 于右下角添加功能按钮(高级) | |
80-
| 61 | json_rpc | 外部操纵 Typora(高级) | × |
62+
| 43 | truncate_text | 暂时隐藏内容,提高大文件渲染性能 | × |
63+
| 44 | dark | 夜间模式 | |
64+
| 45 | no_image | 无图模式 | |
65+
| 46 | myopic_defocus | 离焦视力舒缓 | |
66+
| 47 | updater | 一键升级插件 | |
67+
| 48 | easy_modify | 编辑工具 | |
68+
| 49 | editor_width_slider | 写作区宽度调整 | |
69+
| 50 | redirectLocalRootUrl | 重定向本地资源根目录 | × |
70+
| 51 | scrollBookmarker | 书签管理器 | × |
71+
| 52 | cipher | 加密文件 | × |
72+
| 53 | ripgrep | 使用 ripgrep 搜索文件 | × |
73+
| 54 | article_uploader | 一键上传博客到支持的所有平台 | × |
74+
| 55 | cursor_history | 光标跳转 | × |
75+
| 56 | static_markers | Markdown 标记常显 | × |
76+
| 57 | custom | 开放平台,用户自定义插件(高级) | |
77+
| 58 | hotkeys | 快捷键注册中心(高级) | |
78+
| 59 | quickButton | 于右下角添加功能按钮(高级) | |
79+
| 60 | json_rpc | 外部操纵 Typora(高级) | × |
8180

8281
> 如果有需求或发现 BUG,欢迎 [提 issue](https://github.com/obgnail/typora_plugin/issues/new),欢迎 PR。如果觉得本项目对您有帮助,请不吝点亮一个 Star ⭐!
8382
@@ -575,12 +574,6 @@ docker run -d --name plantuml-server -p 8080:8080 plantuml/plantuml-server:jetty
575574

576575

577576

578-
### go_top: 一键到顶
579-
580-
功能:在右下角添加一个一键到顶的按钮。
581-
582-
583-
584577
### dark:夜间模式
585578

586579
使用方式:右键菜单 -> 常用插件 -> 夜间模式

README.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,24 @@ English | [简体中文](https://github.com/obgnail/typora_plugin/blob/master/RE
5959
| 40 | export_enhance | Avoid image loss when exporting to HTML | |
6060
| 41 | sidebar_enhance | Drag & drop to rearrange、Display non-Markdown files、Keep Fold State | |
6161
| 42 | markdownLint | Markdown Lint Check | |
62-
| 43 | go_top | One-click to top of the article | |
63-
| 44 | truncate_text | Hide content to improve performance for large files | × |
64-
| 45 | dark | Dark mode | |
65-
| 46 | no_image | No image mode | |
66-
| 47 | myopic_defocus | Defocus Comfort Mode | |
67-
| 48 | updater | One-click plugin update | |
68-
| 49 | easy_modify | Editing tools | |
69-
| 50 | editor_width_slider | Adjust writing area width | |
70-
| 51 | redirectLocalRootUrl | Redirect local resource root directory | × |
71-
| 52 | scrollBookmarker | Bookmark manager | × |
72-
| 53 | cipher | Encrypt files | × |
73-
| 54 | ripgrep | Search files using ripgrep | × |
74-
| 55 | article_uploader | One-click upload blog to supported platforms | × |
75-
| 56 | cursor_history | Cursor History | × |
76-
| 57 | static_markers | Static Markers | × |
77-
| 58 | custom | Open platform for user-defined plugins (advanced) | |
78-
| 59 | hotkeys | Hotkey registration center (advanced) | |
79-
| 60 | quickButton | Add function buttons in the lower right corner (advanced) | |
80-
| 61 | json_rpc | External control of Typora (advanced) | × |
62+
| 43 | truncate_text | Hide content to improve performance for large files | × |
63+
| 44 | dark | Dark mode | |
64+
| 45 | no_image | No image mode | |
65+
| 46 | myopic_defocus | Defocus Comfort Mode | |
66+
| 47 | updater | One-click plugin update | |
67+
| 48 | easy_modify | Editing tools | |
68+
| 49 | editor_width_slider | Adjust writing area width | |
69+
| 50 | redirectLocalRootUrl | Redirect local resource root directory | × |
70+
| 51 | scrollBookmarker | Bookmark manager | × |
71+
| 52 | cipher | Encrypt files | × |
72+
| 53 | ripgrep | Search files using ripgrep | × |
73+
| 54 | article_uploader | One-click upload blog to supported platforms | × |
74+
| 55 | cursor_history | Cursor History | × |
75+
| 56 | static_markers | Static Markers | × |
76+
| 57 | custom | Open platform for user-defined plugins (advanced) | |
77+
| 58 | hotkeys | Hotkey registration center (advanced) | |
78+
| 59 | quickButton | Add function buttons in the lower right corner (advanced) | |
79+
| 60 | json_rpc | External control of Typora (advanced) | × |
8180

8281
> If you have other needs or find bugs, feel free to [open an issue](https://github.com/obgnail/typora_plugin/issues/new). PRs are also welcome. If you find this project helpful, please give me a star ⭐
8382
@@ -509,10 +508,6 @@ Function:
509508
- Keep Fold Outline State
510509
- Customize Sidebar File Icons
511510

512-
### go_top
513-
514-
Function: Add a "Go to Top" button at the bottom right corner.
515-
516511
### dark: Dark Mode
517512

518513
Usage: Right-click menu -> Often Used Plugins -> Night Mode

plugin/custom/plugins/chineseSymbolAutoPairer.js

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,88 @@ class ChineseSymbolAutoPairerPlugin extends BaseCustomPlugin {
99
selector = () => this.utils.disableForeverSelector
1010

1111
init = () => {
12-
const reverseMap = map => {
13-
const result = new Map();
14-
map.forEach((v, k) => result.set(v, k));
15-
return result
16-
}
12+
this.rangyText = ""
1713

18-
this.rangyText = "";
19-
this.pairMap = new Map(this.config.auto_pair_symbols)
2014
this.swapMap = new Map(this.config.auto_swap_symbols)
15+
this.pairMap = new Map(this.config.auto_pair_symbols)
16+
this.reversePairMap = new Map(this.config.auto_pair_symbols.map(([k, v]) => [v, k]))
2117
this.codeSet = new Set([
2218
"Digit1", "Digit2", "Digit3", "Digit4", "Digit5", "Digit6", "Digit7", "Digit8", "Digit9", "Digit0",
2319
"Backquote", "BracketLeft", "BracketRight", "Backslash", "Semicolon", "Quote", "Comma", "Period", "Slash",
2420
])
25-
this.reversePairMap = reverseMap(this.pairMap)
21+
2622
const until = () => File?.editor?.undo?.UndoManager?.SnapFlag
2723
const after = () => this.undoSnapType = File.editor.undo.UndoManager.SnapFlag
2824
this.utils.pollUntil(until, after)
2925
}
3026

3127
process = () => {
3228
this.utils.entities.eWrite.addEventListener("input", this.utils.throttle(ev => {
33-
if (File.option.noPairingMatch || document.activeElement.tagName === "TEXTAREA") return;
29+
if (File.option.noPairingMatch || document.activeElement.tagName === "TEXTAREA") return
3430

35-
const inputSymbol = ev.data;
36-
const pairSymbol = this.pairMap.get(inputSymbol);
31+
const inputSymbol = ev.data
32+
const pairSymbol = this.pairMap.get(inputSymbol)
3733
if (pairSymbol) {
38-
this.insertText(this.rangyText + pairSymbol);
39-
setTimeout(this.selectText, 50);
34+
this.insertText(this.rangyText + pairSymbol)
35+
setTimeout(this.selectText, 50)
4036
} else if (this.config.auto_skip && this.reversePairMap.get(inputSymbol)) {
41-
this.skipSymbol(inputSymbol);
37+
this.skipSymbol(inputSymbol)
4238
}
4339
if (this.config.auto_swap && this.swapMap.has(inputSymbol)) {
4440
this.swapSymbol(inputSymbol)
4541
}
46-
}, 30));
42+
}, 30))
4743

4844
if (this.config.auto_delete_pair || this.config.auto_surround_pair) {
4945
this.utils.entities.eWrite.addEventListener("keydown", ev => {
50-
if (File.option.noPairingMatch || document.activeElement.tagName === "TEXTAREA") return;
46+
if (File.option.noPairingMatch || document.activeElement.tagName === "TEXTAREA") return
5147

5248
if (this.config.auto_surround_pair && this.utils.isIMEActivated(ev) && this.codeSet.has(ev.code)) {
53-
this.rangyText = this.utils.getRangyText();
49+
this.rangyText = this.utils.getRangyText()
5450
}
5551
if (this.config.auto_delete_pair && ev.key === "Backspace" && !ev.shiftKey && !ev.altKey && !this.utils.metaKeyPressed(ev)) {
56-
this.deletePair();
52+
this.deletePair()
5753
}
58-
}, true);
54+
}, true)
5955
}
6056
}
6157

6258
selectText = () => {
6359
if (this.config.auto_select_after_surround || this.rangyText) {
64-
const { range, bookmark } = this.utils.getRangy();
65-
bookmark.end += this.rangyText.length;
66-
range.moveToBookmark(bookmark);
67-
range.select();
60+
const { range, bookmark } = this.utils.getRangy()
61+
bookmark.end += this.rangyText.length
62+
range.moveToBookmark(bookmark)
63+
range.select()
6864
}
69-
this.rangyText = "";
65+
this.rangyText = ""
7066
}
7167

7268
insertText = symbol => {
73-
const { range, node } = this.utils.getRangy();
74-
const textNode = document.createTextNode(symbol);
75-
range.insertNode(textNode);
76-
File.editor.undo.addSnap(node.cid, this.undoSnapType.REPLACE);
69+
const { range, node } = this.utils.getRangy()
70+
const textNode = document.createTextNode(symbol)
71+
range.insertNode(textNode)
72+
File.editor.undo.addSnap(node.cid, this.undoSnapType.REPLACE)
7773
}
7874

7975
_getRange = () => {
80-
const { node, bookmark } = this.utils.getRangy();
81-
if (!node) return {};
76+
const { node, bookmark } = this.utils.getRangy()
77+
if (!node) return {}
8278

83-
File.editor.undo.endSnap();
84-
File.editor.undo.addSnap(node.cid, this.undoSnapType.NONE);
85-
const ele = File.editor.findElemById(node.cid);
86-
if (ele.hasClass("md-fences")) return {};
79+
File.editor.undo.endSnap()
80+
File.editor.undo.addSnap(node.cid, this.undoSnapType.NONE)
81+
const ele = File.editor.findElemById(node.cid)
82+
if (ele.hasClass("md-fences")) return {}
8783

88-
const rawText = ele.rawText();
89-
return { rawText, bookmark };
84+
const rawText = ele.rawText()
85+
return { rawText, bookmark }
9086
}
9187

9288
skipSymbol = inputSymbol => {
93-
const { rawText, bookmark } = this._getRange();
94-
if (!rawText || !bookmark) return;
89+
const { rawText, bookmark } = this._getRange()
90+
if (!rawText || !bookmark) return
9591
if (inputSymbol === rawText.substring(bookmark.start, bookmark.start + 1)) {
96-
bookmark.end += 1;
97-
this.deleteContent(bookmark);
92+
bookmark.end += 1
93+
this.deleteContent(bookmark)
9894
}
9995
}
10096

@@ -144,22 +140,22 @@ class ChineseSymbolAutoPairerPlugin extends BaseCustomPlugin {
144140
}
145141

146142
deletePair = () => {
147-
const { rawText, bookmark } = this._getRange();
148-
if (!rawText || !bookmark) return;
149-
const pair = rawText.substring(bookmark.start - 1, bookmark.start + 1);
143+
const { rawText, bookmark } = this._getRange()
144+
if (!rawText || !bookmark) return
145+
const pair = rawText.substring(bookmark.start - 1, bookmark.start + 1)
150146
if (pair.length === 2) {
151-
const [left, right] = pair;
147+
const [left, right] = pair
152148
if (this.reversePairMap.get(right) === left && this.pairMap.get(left) === right) {
153-
bookmark.end += 1;
154-
this.deleteContent(bookmark);
149+
bookmark.end += 1
150+
this.deleteContent(bookmark)
155151
}
156152
}
157153
}
158154

159155
deleteContent = bookmark => {
160-
const newRange = File.editor.selection.rangy.createRange();
161-
newRange.moveToBookmark(bookmark);
162-
newRange.deleteContents();
156+
const range = File.editor.selection.rangy.createRange()
157+
range.moveToBookmark(bookmark)
158+
range.deleteContents()
163159
}
164160
}
165161

plugin/custom/plugins/quickButton.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ class QuickButtonPlugin extends BaseCustomPlugin {
1717
if (buttons.size) {
1818
const maxX = Math.max(-1, ...[...buttons.values()].map(c => c.x))
1919
const maxY = Math.max(-1, ...[...buttons.values()].map(c => c.y))
20-
await this.utils.styleTemplater.register(this.fixedName, { rowCount: maxX + 1, colCount: maxY + 1, this: this })
20+
await this.utils.styleTemplater.register(this.fixedName, {
21+
rowCount: maxX + 1,
22+
colCount: maxY + 1,
23+
this: this,
24+
buttonColor: "var(--text-color)",
25+
buttonBgColor: "initial",
26+
})
2127
this.buttonGroup.append(...this.genButtons(maxX, maxY))
2228
}
2329
})

plugin/custom/plugins/scrollBookmarker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,18 @@ class ScrollBookmarkerPlugin extends BaseCustomPlugin {
117117
for (const [filepath, idxList] of map.entries()) {
118118
for (const idx of idxList.keys()) {
119119
const fileName = this.utils.getFileName(filepath)
120+
const itemText = this._itemText(fileName, idx)
120121
if (item) {
121122
const content = item.querySelector(".bookmark-item-content")
122123
if (content) {
123-
content.textContent = `${fileName} - ${idx}`
124+
content.textContent = itemText
124125
content.dataset.file = filepath
125126
content.dataset.idx = idx
126127
}
127128
} else {
128129
this.entities.list.insertAdjacentHTML("beforeend", `
129130
<div class="bookmark-item">
130-
<div class="bookmark-item-content" data-file="${filepath}" data-idx="${idx}">${fileName} - ${idx}</div>
131+
<div class="bookmark-item-content" data-file="${filepath}" data-idx="${idx}">${itemText}</div>
131132
<div class="bookmark-btn fa fa-trash-o"></div>
132133
</div>`)
133134
item = this.entities.list.lastElementChild
@@ -141,6 +142,8 @@ class ScrollBookmarkerPlugin extends BaseCustomPlugin {
141142
item = next
142143
}
143144
}
145+
146+
_itemText = (fileName, idx) => `${fileName} - ${idx}`
144147
}
145148

146149
module.exports = {

0 commit comments

Comments
 (0)