Skip to content

Commit b9811b7

Browse files
Fixed properties search
1 parent 929d262 commit b9811b7

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/patchers/patcher.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,27 @@ export default abstract class Patcher {
6767
plugin: Plugin,
6868
object: T | undefined,
6969
patches: FunctionPatchObject<T>,
70+
uninstallers?: Array<() => void>
7071
): T | null {
71-
Patcher.patch(plugin, object, patches)
72-
return Patcher.patchPrototype(plugin, object, patches)
72+
Patcher.patch(plugin, object, patches, false, uninstallers)
73+
return Patcher.patchPrototype(plugin, object, patches, uninstallers)
7374
}
7475

7576
static patchPrototype<T>(
7677
plugin: Plugin,
7778
target: T | undefined,
78-
patches: FunctionPatchObject<T>
79+
patches: FunctionPatchObject<T>,
80+
uninstallers?: Array<() => void>
7981
): T | null {
80-
return Patcher.patch(plugin, target, patches, true)
82+
return Patcher.patch(plugin, target, patches, true, uninstallers)
8183
}
8284

8385
static patch<T>(
8486
plugin: Plugin,
8587
object: T | undefined,
8688
patches: FunctionPatchObject<T>,
87-
prototype: boolean = false
89+
prototype: boolean = false,
90+
uninstallers?: Array<() => void>
8891
): T | null {
8992
if (!object) return null
9093
const target = prototype ? object.constructor.prototype : object
@@ -99,6 +102,7 @@ export default abstract class Patcher {
99102
}
100103

101104
const uninstaller = around(target as any, patches)
105+
if (uninstallers) uninstallers.push(uninstaller)
102106
plugin.register(uninstaller)
103107

104108
return object
@@ -107,17 +111,18 @@ export default abstract class Patcher {
107111
static tryPatchWorkspacePrototype<T>(
108112
plugin: Plugin,
109113
getTarget: () => T | undefined,
110-
patches: FunctionPatchObject<T>
114+
patches: FunctionPatchObject<T>,
115+
uninstallers?: Array<() => void>
111116
): Promise<T> {
112117
return new Promise((resolve) => {
113-
const result = Patcher.patchPrototype(plugin, getTarget(), patches)
118+
const result = Patcher.patchPrototype(plugin, getTarget(), patches, uninstallers)
114119
if (result) {
115120
resolve(result)
116121
return
117122
}
118123

119124
const listener = plugin.app.workspace.on('layout-change', () => {
120-
const result = Patcher.patchPrototype(plugin, getTarget(), patches)
125+
const result = Patcher.patchPrototype(plugin, getTarget(), patches, uninstallers)
121126

122127
if (result) {
123128
plugin.app.workspace.offref(listener)

src/patchers/search-patcher.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ export default class SearchPatcher extends Patcher {
99
const that = this
1010
await Patcher.waitForViewRequest<SearchView>(this.plugin, "search", view => {
1111
// Patch the search view until the searchQuery is set or the plugin is unloaded
12-
const uninstaller = around(view, {
12+
const uninstallers: Array<() => void> = []
13+
Patcher.patchThisAndPrototype(this.plugin, view, {
1314
startSearch: (next: any) => function (...args: any): any {
1415
const result = next.call(this, ...args)
1516

1617
// Patch the searchQuery and revert the search view patch
1718
if (this.searchQuery) {
1819
that.patchSearchQuery(this.searchQuery)
19-
uninstaller()
20+
uninstallers.forEach(uninstall => uninstall())
2021
}
2122

2223
return result
2324
}
24-
})
25-
26-
// Uninstall the patcher when the plugin is unloaded
27-
that.plugin.register(uninstaller)
25+
}, uninstallers)
2826
})
2927
}
3028

0 commit comments

Comments
 (0)