You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SC_MenuEvent.addTShellCommandToMenu(): Fix accessing a menu item possibly too early.
Not directly related to #70, but this was noticed during it, and as I haven't noticed this glitch causing problems in practise, there's no need to create a separate issue.
The original plan was to create a separate method, but then parsing_results would have become inaccessible.
// Create the menu item as soon as possible. (If it's created after 'await parsing_process.process()' below, it won't be shown in the menu for some reason, at least in Obsidian 0.16.1).
32
-
// No title is set here, it will be set later.
33
-
letmenu_item: MenuItem;
34
-
menu.addItem(item=>menu_item=item
35
-
.setIcon(t_shell_command.getIconId())// Icon id can be null.
36
-
.onClick(async()=>{
37
-
awaitthis.trigger(
38
-
t_shell_command,
39
-
parsing_process,
40
-
);
41
-
}),
42
-
);
43
-
44
-
// Parse shell command variables to get a title
45
-
lettitle=t_shell_command.getAliasOrShellCommand();// May contain unparsed variables.
constaliasParsingResult: ParsingResult=parsing_results["alias"]asParsingResult;// as ParsingResult: Tells TypeScript that the object exists.
54
-
constshellCommandParsingResult: ParsingResult=parsing_results["shell_command"]asParsingResult;// as ParsingResult: Tells TypeScript that the object exists.
55
-
title=aliasParsingResult.parsed_content||shellCommandParsingResult.parsed_contentasstring;// Try to use a parsed alias, but if no alias is available, use a parsed shell command instead. as string = parsed shell command always exist when the parsing itself has succeeded.
29
+
menu.addItem(asyncmenuItem=>{
30
+
// Parse shell command variables to get a title
31
+
lettitle=t_shell_command.getAliasOrShellCommand();// May contain unparsed variables.
constaliasParsingResult: ParsingResult=parsing_results["alias"]asParsingResult;// as ParsingResult: Tells TypeScript that the object exists.
40
+
constshellCommandParsingResult: ParsingResult=parsing_results["shell_command"]asParsingResult;// as ParsingResult: Tells TypeScript that the object exists.
41
+
title=aliasParsingResult.parsed_content||shellCommandParsingResult.parsed_contentasstring;// Try to use a parsed alias, but if no alias is available, use a parsed shell command instead. as string = parsed shell command always exist when the parsing itself has succeeded.
42
+
}
43
+
// If parsing process fails, the failed process can be passed to this.trigger(). The execution will eventually be cancelled and error messages displayed (if displaying is allowed).
44
+
menuItem.setTitle(title);
56
45
}
57
-
// If parsing process fails, the failed process can be passed to this.trigger(). The execution will eventually be cancelled and error messages displayed (if displaying is allowed).
58
-
}
59
46
60
-
// Update menu item title.
61
-
// @ts-ignore. Suppress for now. // FIXME: Fix in a separate commit by moving the whole title generation block to a new method and call that method from the menu.addItem()'s callback function.
62
-
menu_item.setTitle(title);
47
+
// Icon and onClick handler.
48
+
menuItem
49
+
.setIcon(t_shell_command.getIconId())// Icon id can be null.
0 commit comments