You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Scripting Hook for Ctrl + Click #2523
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 */functionhandleCtrlClick(note,cursorPosition);
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.
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...
Activity
louwers commentedon May 1, 2022
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
openLinkAtCursorPositionin qmarkdowntextedit, I'd need to emit something in qmarkdowntextedit, and handle it in QOWnNotes by calling out to the scripting service.louwers commentedon May 1, 2022
It would be a breaking change for users of just qmarkdowntextedit though...
They would need to
connectmanually.pbek commentedon May 1, 2022
You could catch the Ctrl + Click first in
QOwnNotesMarkdownTextEdit::eventFilterand check there if some script uses the hook and then delegate toQMarkdownTextEdit::eventFilteragain if no hook was implemented or the hook returned false.Better use something like
handleNoteTextEditCtrlClickor someone might think this is about the note list or the preview or something else...pbek commentedon May 1, 2022
And please don't forget to do some documentation in
webpage/src/scripting/hooks.mdand an example on how to use the script. 😉