phibr0/obsidian-commander

[Bug]: Commander Ribbon Elements Reordering on Changes

Opened this issue · 0 comments

Describe the bug

When adding commands via the Commander Ribbon Tab, or when changing icon, color, name, or mode, the elements get reordered. This requires the user to re-reorder the ribbon elements everytime a new command is added or an already existing one is changed.

Relevant errors (if available)

No response

Steps to reproduce

  • Open the Commander Ribbon Tab
  • Add or modify (icon, color, name, mode) a command
  • Observe that the elements are reordered

Expected Behavior

Changes should be applied without reordering the existing elements. Adding a new command should not trigger an additional reorder operation.

Additional context

Proposed fix:

  1. Implement a new update() method in leftRibbonManager.ts that only adds commands without removing them
  2. Modify the handleRename method in commandViewerComponent.tsx to:
    a. First remove the command using the manager.removeCommand() method
    b. Then make the name change
    c. Finally, add the command again using the manager.addCommand() method
  3. Replace manager.reorder() calls with manager.update() for the following functions in src/ui/components/commandViewerComponent.tsx:
  • handleNewIcon
  • handleModeChange
  • handleColorChange
  1. Modify addCommand() and removeCommand() method to use the id for finding the native action.
  2. Use nativeAction.hidden property to handle mode changes without reordering
  3. Remove the reorder() call in "Add command" button click handler

Attachments:
The following attachments contain the fix which allows adding, renaming, and removing commands via the Commander Ribbon tab, or changing icon, color, name, or mode, without the need to reorder all items:

Limitations:
The Plugin.addRibbonIcon(icon, title) method only permits specifying a name and icon, without an option for specifying a unique identifier. Consequently, changing a name currently causes this element to reorder in ribbon and the Commander Ribbon tab.

Additional notes:
In the current implementation, removing and immediately re-adding the element with a new name results in reordering that command in the ribbon and in the Command Ribbon tab. Another approach would be to assign elements a UID and set the title field of the newly created ribbon item immediately afterward, allowing a name change without reordering. However, this would require changes to the interface and initialization process of the CommandIconPair, affecting multiple files (all instances of CommandIconPair would need to include the UID).

While implementing this field requires changing the initialization process in other parts of the program, as long as this is correctly implemented, it would not impact any of the functionality of the program. In fact, it would be possible to use the UID only on special occasions (e.g., ribbon) where desired.

Operating system

Linux