QOwnNotes icon indicating copy to clipboard operation
QOwnNotes copied to clipboard

Feature Request: Scripting Hook for Ctrl + Click

Open louwers opened this issue 3 years ago • 4 comments

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);

louwers avatar May 01 '22 09:05 louwers

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.

louwers avatar May 01 '22 10:05 louwers

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

They would need to connect manually.

louwers avatar May 01 '22 11:05 louwers

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...

pbek avatar May 01 '22 11:05 pbek

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

pbek avatar May 01 '22 11:05 pbek