Recent

Author Topic: Lazarus editor feature request/suggestion  (Read 1404 times)

440bx

  • Hero Member
  • *****
  • Posts: 5068
Lazarus editor feature request/suggestion
« on: February 07, 2025, 11:55:10 pm »
Hello,

Sometimes it is convenient to refer to a url in a comment, presumably because there is additional relevant information about the code.

For instance, the GetComboBoxInfo definition could be followed by a comment such as:
{ https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcomboboxinfo }

It would be very nice if it were possible to click anywhere on that url and have Lazarus open the default browser or a new tab in the browser if it is already running with that page (just as the browser that is displaying this post does if the url is clicked on.)

This would be particularly useful when the code is relying on obscure, i.e., not well known, information that is fully elaborated in some url.

Comments welcome.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

hukka

  • New Member
  • *
  • Posts: 44
    • Github
Re: Lazarus editor feature request/suggestion
« Reply #1 on: February 08, 2025, 12:30:16 am »
The basic functionality is basically just a simple API call on most platforms, but the implementation requires certain decisions:
- What constitutes a valid enough URL for this case? Does it have to be fully qualified, or should it also accept www.foobar.com, just foobar.com? And what protocols? Should we also accept FTP? Gopher? Anything with :// ?
- UI considerations: should opening an URL be its own mouse action in the IDE Options->Editor->Mouse dialog? Like Notepad++ requires a ctrl-click IIRC, and I certainly don't want Lazarus opening URLs when I just want to select the text for copying.
- URL highlighting is an obvious thing that should to be implemented then too. You'd probably also want hovered URLs to be highlighted differently as that's the norm in UIs. That'd be two more settings in the highlighters.

I'm not at all against such a feature but I can understand how seemingly simple things like this end up not getting implemented due to the work required. I would personally be happy with just having URL highlighting. (EDIT: on second thought just having the URL highlighting would be confusing to users if the URLs aren't clickable.)
Just my two euro cents.
« Last Edit: February 08, 2025, 12:53:02 am by hukka »

Tony Stone

  • Sr. Member
  • ****
  • Posts: 268
Re: Lazarus editor feature request/suggestion
« Reply #2 on: February 08, 2025, 01:31:57 am »

I am going to try to implement it this weekend!  On first thought I wouldn't think I like needing to use a key+click combination.  I feel like it should highlight like a normal URL and underline and change the mouse cursor to a hand but only when in a comment.  Because I can see where I want to have a URL as a string value and there I think I would prefer needing a key+mouse click combination.  But even a Ctrl+Click could be acceptable on a URL in a string value because you wouldn't expect for it to make you jump to anything in the source editor anyway.  I don't know... I really like this idea!

But man... the simplest ideas always end up with a ton of cases I never consider.  Either way this is my project this weekend, if I do a decent job i'll post a patch here.

First I need to get the latest trunk to build properly, my last bright idea seems to be the source of a failed build now.  It is probably time for me to stop using FPCUpDeluxe as my crutch anyway. lol
This would be particularly useful when the code is relying on obscure, i.e., not well known, information that is fully elaborated in some url.

Comments welcome.

440bx

  • Hero Member
  • *****
  • Posts: 5068
Re: Lazarus editor feature request/suggestion
« Reply #3 on: February 08, 2025, 07:33:27 am »
Thank you for the comments.

I envisioned something really simple.  I would be perfectly satisfied if values were limited to those starting with "http://" and "https://", that makes it a bit simpler to determine the address may be _usable_, which means it isn't necessarily valid.

As far as it being valid, I'd personally put the burden entirely on the programmer, none at all on the editor, IOW, aside from establishing the text starts with "http://" or "https://" in order to change the cursor to the one the system normally uses to indicate a url, nothing else.  IOW, the editor would not concern itself with validity at all, i.e, no fancy url parsing.

There is one thing that, on second thought, might be appropriate if this feature is implemented and that is, it should be an "opt-in" feature because it is conceivable for it to be used maliciously.  Because of this, I believe it should be inactive by default and activated only by the programmer when he/she is willing to accept full responsibility for whatever actions a link may cause.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

TRon

  • Hero Member
  • *****
  • Posts: 4133
Re: Lazarus editor feature request/suggestion
« Reply #4 on: February 08, 2025, 08:11:36 am »
fwiw: most editors that I use and also the terminal 'lights up by underlining sometimes changing the colour of" the url when hovering over it with the mouse to indicate that an action can be performed and a right mouse click when active a popup-menu that has an action listed as "open url" as (first) item. Some use/allow also to use the ctrl-mouse-click (as fast action).
Today is tomorrow's yesterday.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10900
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus editor feature request/suggestion
« Reply #5 on: February 08, 2025, 09:07:25 am »
1) About the list of url types. I think ultimately to be configurable, possible including user specified. Or retrieved from OS.
But for starters, hardcoded, just http https is ok

2) underline => bound to the modifier key configured for the click (see existing code for code jumping)>
But can have config to underline either:
- modifier key + hover only
- hover
- always

Maybe / or maybe not, bound to highlighter and comment/string only???

3) click config
For advanced option must be own mouse command
But mouse commands can have fallbacks, so it can use same key as code jump
 
For normal config can be in the drop down as "code jump AND url", and as 2 entries, one for each.




Bonus
configurable pattern to match issue numbers
E.g.: Issue *\#(\d+)

And link(s) what page to open.
Challenge: Allow user to select fpc or Lazarus bugs.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4565
  • I like bugs.
Re: Lazarus editor feature request/suggestion
« Reply #6 on: February 08, 2025, 10:12:29 am »
The basic functionality is basically just a simple API call on most platforms, but the implementation requires certain decisions:
A cross-platform function already exists, namely OpenURL().

First I need to get the latest trunk to build properly, my last bright idea seems to be the source of a failed build now.  It is probably time for me to stop using FPCUpDeluxe as my crutch anyway.
Exactly! FPCUpDeluxe is not needed for building Lazarus trunk for the native system. It only complicates things. FPCUpDeluxe is good for other things.

fwiw: most editors that I use and also the terminal 'lights up by underlining sometimes changing the colour of" the url when hovering over it with the mouse to indicate that an action can be performed and a right mouse click when active a popup-menu that has an action listed as "open url" as (first) item. Some use/allow also to use the ctrl-mouse-click (as fast action).
+1
A right mouse click or ctrl-click must be required. We are dealing with a text editor. Just clicking somewhere must move the cursor, nothing else.
« Last Edit: February 08, 2025, 10:42:11 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Tony Stone

  • Sr. Member
  • ****
  • Posts: 268
Re: Lazarus editor feature request/suggestion
« Reply #7 on: February 08, 2025, 01:57:07 pm »
I think a Ctrl+Click being required makes the most sense as well.  But I think it should also at least underline or maybe use italics and possibly show a hint whenever hovering over a URL WHILE CTRL key is down.. 

If you require a Ctrl+Click do we still want the cursor to change the the system cursor you see on hyperlinks (the hand cursor). 

I feel JuhaManninen is 100% correct though and it must require a key+click and the existing key we use to jump in the code is most logical.

So in my opinion it should only appear different when a control key is Down.

It should offer a hint when mouse is over it "Ctrl+Click to open URL" WITHOUT control key down.

Mouse cursor should change to hand when hovering with control key is down.

Beyond that I think a normal click in a URL must set the caret in that positions as normal.

A right click over a URL that offers an Open URL menu item is very logical to me as well.  But if that is implemented I think it is important to make sure a right click ANYWHERE in the URL will give the Open URL option.  I have another program I use and you have to perfectly highlight a URL then it gives you the Open URL menu item.  Actually they recently improved it so now you can right click anywhere in a URL and get the menu so that was a nice improvement.
« Last Edit: February 08, 2025, 03:29:06 pm by Tony Stone »

440bx

  • Hero Member
  • *****
  • Posts: 5068
Re: Lazarus editor feature request/suggestion
« Reply #8 on: February 08, 2025, 04:04:12 pm »
I tend to favor a solution that places as little burden on the editor as possible.

This means that normally, when the mouse is not on the url or the caret is not somewhere in the url string then the url should be treated just like a normal comment.  However, when either one of those conditions are true (mouse or caret on the url) then underlining the url as feedback that something is afoot would be nice.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10900
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus editor feature request/suggestion
« Reply #9 on: February 08, 2025, 04:13:57 pm »
Well, it should be doable 100% as add-on (though the code of the addon can (partly) reside in the SynEdit package.

The code-link is not implemented in the core of SynEdit, nor does the core know about it (except for a forwarder to set the colors/events / because of backward compatibility for when it was in the core).

There is a "Markup" that can be added to SynEdit and handles the highlight.
It also registers mouse actions (though that should be done in a plugin, not in the markup). So when click occurs an event can be triggered.

The rest of course would go into the IDE, if the event is triggered calling the open url API of the OS must be IDE.

 

TinyPortal © 2005-2018