Skip to content

Feature Request: Scripting Hook for Ctrl + Click #2523

Open

Description

@louwers

I wrote a script for opening Dokuwiki style links, that I bound to Alt + L. I would love it if I could make it work with Ctrl + click as well.

I think in general a hook like this would offer a lot of flexibility. See my suggested API below.

@pbek If you think it is a good idea, you could also give me some pointers if you would like me to try to implement it.

/**
 * This function is called when the user Ctrl + clicks inside a note.
 * It receives the note that was clicked as well as the cursor position
 * of the click.
 * 
 * Return false if the default action on Ctrl + click should be taken
 * return true if the hook handled the click.
 * 
 * @param {NoteApi} note - the note that was clicked on
 * @param {number} cursorPosition - cursor position that was clicked
 * @return {boolean} if the click should be considered handled
 */
function handleCtrlClick(note, cursorPosition);

Activity

  1. louwers commented on May 1, 2022

    @louwers
    ContributorAuthor

    I found the line in qmarkdowntextedit: https://github.com/pbek/qmarkdowntextedit/blob/84ef933786daf88a13f3a9dc9eb6f96182ce3b91/qmarkdowntextedit.cpp#L406

    So I guess to implement this, instead of hard-cording openLinkAtCursorPosition in qmarkdowntextedit, I'd need to emit something in qmarkdowntextedit, and handle it in QOWnNotes by calling out to the scripting service.

  2. louwers commented on May 1, 2022

    @louwers
    ContributorAuthor

    It would be a breaking change for users of just qmarkdowntextedit though...

    They would need to connect manually.

  3. pbek commented on May 1, 2022

    @pbek
    Owner

    You could catch the Ctrl + Click first in QOwnNotesMarkdownTextEdit::eventFilter and check there if some script uses the hook and then delegate to QMarkdownTextEdit::eventFilter again if no hook was implemented or the hook returned false.

    function handleCtrlClick(note, cursorPosition);

    Better use something like handleNoteTextEditCtrlClick or someone might think this is about the note list or the preview or something else...

  4. pbek commented on May 1, 2022

    @pbek
    Owner

    And please don't forget to do some documentation in webpage/src/scripting/hooks.md and an example on how to use the script. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions