Skip to content

Commit 132684b

Browse files
committed
Fix(redirectLocalRootUrl): Does not take effect during Typora initialization (#1115)
1 parent 516b90a commit 132684b

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

plugin/custom/plugins/redirectLocalRootUrl.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
class RedirectLocalRootUrlPlugin extends BaseCustomPlugin {
2-
beforeProcess = () => {
3-
if (!this.config.root) {
4-
return this.utils.stopLoadPluginError
5-
}
6-
}
2+
beforeProcess = () => this.config.root ? undefined : this.utils.stopLoadPluginError
73

84
init = () => {
9-
const { filter_regexp } = this.config
10-
this.filter = filter_regexp ? new RegExp(filter_regexp) : undefined
5+
this.filterRegex = this.config.filter_regexp ? new RegExp(this.config.filter_regexp) : undefined
116
}
127

13-
needRedirect = (filepath = this.utils.getFilePath()) => {
14-
return this.filter ? this.filter.test(filepath) : true
15-
}
8+
needRedirect = (filePath = this.utils.getFilePath()) => this.filterRegex ? this.filterRegex.test(filePath) : true
169

1710
process = () => {
18-
const redirect = typoraRootUrl => {
19-
const dontRedirect = typoraRootUrl || !this.needRedirect()
20-
return dontRedirect
21-
? typoraRootUrl
22-
: this.utils.Package.Path.resolve(this.utils.getCurrentDirPath(), this.config.root)
11+
const redirect = (rootUrl) => {
12+
const dontRedirect = !!rootUrl || !this.needRedirect()
13+
return dontRedirect ? rootUrl : this.utils.Package.Path.resolve(this.utils.getCurrentDirPath(), this.config.root)
2314
}
2415
this.utils.decorate(() => File?.editor?.docMenu, "getLocalRootUrl", null, redirect, true)
16+
17+
this.utils.eventHub.once(this.utils.eventHub.eventType.fileOpened, () => File.editor.imgEdit.refreshLocalImg(true))
2518
}
2619
}
2720

0 commit comments

Comments
 (0)