nuttyartist / notes

Fast and beautiful note-taking app written in C++. Write down your thoughts.
https://notes-foss.com
Mozilla Public License 2.0
3.75k stars 329 forks source link

Pressing control changes cursor icon even if the cursor is not hovering on a link #534

Closed nuttyartist closed 1 year ago

nuttyartist commented 1 year ago

The cursor icon should change only upon hovering a link. This bug causes the cursor icon to change every time control is pressed.

test

bjorn commented 1 year ago

It's not really a bug, but a missing feature. ;-)

Thing is, the code currently does not care at all whether you're above a URL. It simply changes the cursor on the press and release of Ctrl:

https://github.com/nuttyartist/notes/blob/d6d4581e0c24f136e42eb69c955e067076555ba7/src/customdocument.cpp#L38-L51

zjeffer commented 1 year ago

Is there no way to do this purely with native Qt stuff?

After a short search, I came across this: https://doc.qt.io/qt-6/qt.html#TextInteractionFlag-enum. Might be worth looking into?

zjeffer commented 1 year ago

https://stackoverflow.com/a/1576894/10180569

bjorn commented 1 year ago

Yes, the challenge with making those links clickable, is to actually make them links rather than just highlighted text. And that without disrupting normal text editing operations. At least, when we'd want to rely on that Qt functionality.

zjeffer commented 1 year ago

Do you mean the markdownhighlighter would interfere with the native Qt functionality for this?

bjorn commented 1 year ago

Do you mean the markdownhighlighter would interfere with the native Qt functionality for this?

No, I mean that the native Qt functionality is based on parsing markup (like HTML or Markdown) to create links that are stored in the document as QTextCharFormat::anchorHref. But since our links are plain text to Qt and just styled as a link through the syntax highlighter, we can't rely on that functionality.

I've tried using QSyntaxHighlighter::setFormat to set a format with an anchor in the highlighter, but couldn't get it to work. I think this functionality is not supported through the syntax highlighter, since it does not modify the document. And actually modifying the document is likely going to interfere with the user's edits, though there may be ways to avoid that.

Personally I expect the easiest thing would be to fix the code that sets the mouse cursor to actually check whether there's a link below the cursor.