QOwnNotes
QOwnNotes copied to clipboard
Feature Request: Scripting Hook for Ctrl + Click
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);
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.
It would be a breaking change for users of just qmarkdowntextedit though...
They would need to connect manually.
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...
And please don't forget to do some documentation in webpage/src/scripting/hooks.md and an example on how to use the script. 😉