FR: Add more events to extend context menus

There are some places in the code base where you call onContextMenu but don’t provide events for the plugin developers to extend those menus.

It would be handy to have events for all such places.

e.g. Expose contextual menus for bookmarks natively

A stopgap while this stays open: my plugin More Events publishes context-menu events for menus that have no public event, on app.workspace, shaped like file-menu ((menu, subject)), so a plugin can add items to them without patching anything itself.

I went through every context menu of Obsidian 1.14.5. Leaving aside the native Electron menus, 34 build a menu with no workspace event at all, and 14 fire an event that is not in obsidian.d.ts. The current release, 1.4.0, covers most of both:

  1. Menus with no event, now announced as more-events:*:
    1. Bookmarks: the view’s empty area (more-events:bookmarks-view-menu)
    2. Canvas: the empty background (more-events:canvas-view-menu) and the selection toolbar’s Align, Line direction and group background menus (more-events:canvas-align-menu, more-events:canvas-line-direction-menu, more-events:canvas-group-background-menu)
    3. The ribbon’s empty area, the sidebar toggle buttons, the vault name, the back/forward history list
    4. Properties: a property’s icon, a list or tag value pill, an entry in the All properties view
    5. Live Preview: a table cell, the table drag handle, an external image, a callout
    6. Bases: a table column header, a board column, a view’s “More options” button
    7. PDF: a thumbnail, an outline item, a page, the toolbar’s sidebar and display options menus
    8. Web viewer: a history item
    9. Settings: a CSS snippet row, a community plugin row and its “More options” button, a plugin’s tab in the sidebar
  2. Undocumented events, relayed under stable typed names: bookmarks:bookmarks-menu, leaf-menu, tab-group-menu, search:results-menu, markdown-viewport-menu, markdown-properties-menu, canvas:node-menu, canvas:edge-menu, canvas:selection-menu and canvas:node-connection-drop-menu.

Still uncovered, because the subject is unreachable from a plugin or I cannot test it:

  1. The menu of an unresolved link (handleLinkContextMenu, which offers only “Create file”)
  2. Bases: a property’s and a summary’s “More options” buttons
  3. Publish: a navigation item, a file in the changes list
  4. Sync: the status icon, a multiple selection in the Sync view
  5. Mobile: the tab-management button, and the share sheet (receive-text-menu, receive-files-menu)

The full list with every event’s arguments is in the plugin’s demo vault. Please report bugs and requests on GitHub rather than here.