obsidian-divide-and-conquer icon indicating copy to clipboard operation
obsidian-divide-and-conquer copied to clipboard

[Bug]: Does not show commands for bisecting plugins, only snippets

Open claremacrae opened this issue 2 years ago • 9 comments

Bug Description

In a clean install of the plugin, with default settings, only the Snippet commands are shown, and not the plugin ones.

Relevant Screenshot

Here is a search of the command palette for div - to show Divide & Conquer commands:

Notice how only the Snippet commands are shown, and not the Plugin ones:

image

In case it was an issue with the number of suggestions that the palette shows, I tried again, this time searching for plugin:

image

To Reproduce

  1. Start a new, empty Obsidian vault
  2. Install and enable Divide & Conquer 1.0.0 - do not change the settings
  3. Open the Command palette
  4. Type plugin

Observe how the plugin commands listed in the source code are absent:

https://github.com/chrisgrieser/obsidian-divide-and-conquer/blob/56f464c261f3d071cfe5dcc1904fc911b35346a9/main.ts#L20-L26

Only the snippet commands are available:

https://github.com/chrisgrieser/obsidian-divide-and-conquer/blob/56f464c261f3d071cfe5dcc1904fc911b35346a9/main.ts#L28-L34C3

Obsidian Version

1.3.7

Which editor are you using?

  • [X] New Editor
  • [ ] Legacy Editor

Checklist

  • [X] I updated to the latest version of the plugin.

claremacrae avatar Jul 11 '23 10:07 claremacrae

I wondered whether the issue was that the Plugin and Snippet commands share the same ID.

So I made these changes to the code, to not register the snippet commands (my IDE insisted on removing a stray trailing space as will - ignore that change):

diff --git a/main.ts b/main.ts
index 53da256..073978c 100644
--- a/main.ts
+++ b/main.ts
@@ -25,14 +25,6 @@ const pluginCommands: DACCommand[] = [
 	{ id: "reBisect", 	name: "Plugin Re-Bisect - Undo the last bisection, then disable the other half" },
 ];
 
-const snippetCommands: DACCommand[] = [
-	{ id: "reset", 		name: "Snippet Reset - forget the original state and set the current state as the new original state" },
-	{ id: "restore", 	name: "Snippet Restore - return to the original state" },
-	{ id: "unBisect", 	name: "Snippet Un-Bisect - Undo the last bisection, or enable all snippets if in the original state" },
-	{ id: "bisect", 	name: "Snippet Bisect - Disable half of the active snippets, or return to the original state if all snippets are active" },
-	{ id: "reBisect", 	name: "Snippet Re-Bisect - Undo the last bisection, then disable the other half" },
-];
-
 // the ordering of these determines the order in the settings tab
 const UIButtons: DACButton[] = [
 	{ id: "reset", 		tooltip: "Reset - Snapshot the current state" },
@@ -171,7 +163,7 @@ export default class divideAndConquer extends Plugin {
 		this.getEnabledFromObsidian = () => {
 			switch (this.mode) {
 				case 'plugins': return this.app.plugins.enabledPlugins;
-				// enabledSnippets can sometimes annoyingly include snippets that were removed without disabling 
+				// enabledSnippets can sometimes annoyingly include snippets that were removed without disabling
 				case 'snippets': return new Set(this.app.customCss.snippets.filter((snippet) => this.app.customCss.enabledSnippets.has(snippet)));
 			}
 		};
@@ -263,9 +255,6 @@ export default class divideAndConquer extends Plugin {
 		pluginCommands.forEach(command => this.addCommand(
 			Object.assign(command, { callback: this.mode2Call.get('plugins')(this[command.id] as Func) } as PC)
 		));
-		snippetCommands.forEach(command => this.addCommand(
-			Object.assign(command, { callback: this.mode2Call.get('snippets')(this[command.id] as Func) } as PC)
-		));
 	}
 
 	async bisect() {

Sure enough, the Plugin commands are now shown:

image

claremacrae avatar Jul 11 '23 11:07 claremacrae

I then tried a different edit in the code, to register both sets of commands as before, but to do the Plugin commands after the Snippet ones:

diff --git a/main.ts b/main.ts
index 53da256..efa3edc 100644
--- a/main.ts
+++ b/main.ts
@@ -171,7 +171,7 @@ export default class divideAndConquer extends Plugin {
 		this.getEnabledFromObsidian = () => {
 			switch (this.mode) {
 				case 'plugins': return this.app.plugins.enabledPlugins;
-				// enabledSnippets can sometimes annoyingly include snippets that were removed without disabling 
+				// enabledSnippets can sometimes annoyingly include snippets that were removed without disabling
 				case 'snippets': return new Set(this.app.customCss.snippets.filter((snippet) => this.app.customCss.enabledSnippets.has(snippet)));
 			}
 		};
@@ -260,12 +260,12 @@ export default class divideAndConquer extends Plugin {
 
 	private addCommands() {
 		type PC = Partial<Command>;
-		pluginCommands.forEach(command => this.addCommand(
-			Object.assign(command, { callback: this.mode2Call.get('plugins')(this[command.id] as Func) } as PC)
-		));
 		snippetCommands.forEach(command => this.addCommand(
 			Object.assign(command, { callback: this.mode2Call.get('snippets')(this[command.id] as Func) } as PC)
 		));
+		pluginCommands.forEach(command => this.addCommand(
+			Object.assign(command, { callback: this.mode2Call.get('plugins')(this[command.id] as Func) } as PC)
+		));
 	}
 
 	async bisect() {

And again, only the Plugin ones are visible.

image

claremacrae avatar Jul 11 '23 11:07 claremacrae

I believe that my experiments above confirm that where there are commands with duplicate IDs, the last-registered commands are the ones that 'stick' and are available to users.

What I don't understand is that DAC 1.0.0 was released on Nov 14, 2022...

How come I am, as far as I can tell, the first person to report this?

Has something changed in Obsidian to prevent duplicate command IDs?

Or am I just more likely to the the time to log bugs than others...

claremacrae avatar Jul 11 '23 11:07 claremacrae

I am barely familiar with the rewritten codebase by @geoffreysflaminglasersword, but I think you are pretty much right, this appears to be a copypaste mistake regarding the command IDs.

What I don't understand is that DAC 1.0.0 was released on Nov 14, 2022... How come I am, as far as I can tell, the first person to report this?

I think that's because with the 1.0 version, you have buttons for bisecting directly in the community plugin settings page. Since you toggle plugins there anyway, I (and probably most users) have simply triggered the bisecting actions there.


If you can make a PR which fixes the command ids, I can merge them right away, if you like? Even though I am not familiar with the codebase, just changing the command ids should be a pretty straightforward fix without much potential of breaking anything else

chrisgrieser avatar Jul 11 '23 13:07 chrisgrieser

Cool. How do I find the buttons? I am not seeing them.

claremacrae avatar Jul 11 '23 13:07 claremacrae

Oh... you have to have watched the video on the README.

I read the README and saw about commands... Didn't see any words in the README about going to Plugin settings...

Or you can get lucky and have your Community plugins list be scrolled to the top, and notice the extra buttons there...

image

claremacrae avatar Jul 11 '23 13:07 claremacrae

OK, this is SOOO much easier using the buttons.

Thanks very much for pointing them out.

claremacrae avatar Jul 11 '23 13:07 claremacrae

Note : The button doesn't appear if Obsidian is not in english, see #18

Mara-Li avatar Jul 17 '23 17:07 Mara-Li