Skip to content

Feature: Hotkey to open “Add Comment” dialog for current text selection #22

@worldlyjohn

Description

@worldlyjohn

Summary

Add a configurable hotkey/command that opens the comment dialog immediately for the user’s current text selection. This makes commenting faster than using the mouse/menus.

User story

As a user, when I highlight text in the editor, I want to press a hotkey to open the SideNote comment dialog with that selection pre-filled, so I can add a comment without leaving the keyboard.

Proposed UX

  • User selects text in the active editor.
  • User presses a hotkey (default suggestion: none, user-configurable via Obsidian hotkeys).
  • SideNote opens the “Add Comment” dialog:
    • selection is pre-populated / stored as the anchor (same as current selection-based workflow, if any)
    • cursor focus goes to the comment input field
  • If no text is selected:
    • either show a Notice like “Select text to add a comment” (recommended), or
    • open dialog but require the user to select text first.

Implementation notes

  • Add a command in onload():
    • e.g. this.addCommand({ id: 'sidenote-add-comment-from-selection', name: 'Add comment from selection', ... })
  • In the callback:
    • get the active MarkdownView and editor: this.app.workspace.getActiveViewOfType(MarkdownView)?.editor
    • read selection: editor.getSelection()
    • validate non-empty selection
    • open the same modal/dialog used elsewhere for adding comments, passing the selection + location metadata as needed
  • Ensure it works for:
    • Reading view vs source/live preview (if applicable)
    • Multiple cursors (take primary selection or first range)

Acceptance criteria

  • Command “Add comment from selection” appears in command palette.
  • User can bind a hotkey in Obsidian settings.
  • With non-empty selection, hotkey opens comment dialog and focuses input.
  • With empty selection, a Notice is shown (or documented alternate behavior).
  • Works in the active editor for Markdown files.

Optional enhancements

  • Setting to optionally allow “comment at cursor” when no selection.
  • Add a ribbon icon / context menu item that triggers the same command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions