Fix some Context Menus being broken by regression

This commit is contained in:
V 2023-06-26 00:05:08 +02:00
parent 7f54858b27
commit 4abce9d084
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
2 changed files with 11 additions and 5 deletions

View file

@ -35,7 +35,7 @@ function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) {
listeners.set(cb, path);
o.addChangeListener(path, cb);
};
const removeListener = () => {
const removeAllListeners = () => {
for (const [listener, path] of listeners) {
o.removeChangeListener(path as any, listener);
}
@ -43,7 +43,7 @@ function makeSettingsListenerHelpers<O extends object>(o: SettingsStore<O>) {
listeners.clear();
};
return [addListener, removeListener] as const;
return [addListener, removeAllListeners] as const;
}
const [addSettingsListener, removeSettingsListeners] = makeSettingsListenerHelpers(Settings);

View file

@ -22,14 +22,20 @@ addPatch({
find: ".enableSpellCheck)",
replacement: {
// if (isDesktop) { DiscordNative.onSpellcheck(openMenu(props)) } else { e.preventDefault(); openMenu(props) }
match: /else\{.{1,3}\.preventDefault\(\);(.{1,3}\(.{1,3}\))\}/,
match: /else\{(.{1,3})\.preventDefault\(\);(.{1,3}\(.{1,3}\))\}(?<=:(.{1,3})\.enableSpellCheck\).+?)/,
// ... else { $self.onSlateContext(() => openMenu(props)) }
replace: "else {$self.onSlateContext(() => $1)}"
replace: "else {$self.onSlateContext($1, $3?.enableSpellCheck, () => $2)}"
}
}
],
onSlateContext(openMenu: () => void) {
onSlateContext(e: MouseEvent, hasSpellcheck: boolean | undefined, openMenu: () => void) {
if (!hasSpellcheck) {
e.preventDefault();
openMenu();
return;
}
const cb = (w: string, c: string[]) => {
VencordDesktopNative.spellcheck.offSpellcheckResult(cb);
word = w;