Recent

Author Topic: [SOLVED] Opening a url from the Lazarus editor  (Read 1941 times)

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #15 on: November 22, 2025, 08:31:23 am »
Domingo, again, thank you!

It's a small detail but, it makes it quicker and easier to activate the link.  Good stuff :)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 380
Re: Opening a url from the Lazarus editor
« Reply #16 on: November 22, 2025, 09:18:17 pm »
Now that I said "exactly", actually, it's almost exactly what I wanted.  Two minor characteristics are missing, they are:

1. it would be really great if the OpenLink(URL) menu item was the first menu item (make it first only when the caret is on a url.)  That would make it faster to select.
2. it would be nice if the url was highlighted in some ways when right clicking on it (feedback that it is "selected")

Note: those are very minor things, just "nice to have".  The feature is great as it is.  I suspect that implementing either one of those might require changes in SynEdit.

@440bx,
I experimented a bit after work. Here's the package (attached).
No context menus required.
1. Press Alt   -> the URL will be underlined (see screenshot).
2. Then, click -> the link will open in the browser.
That's it.

n7800

  • Hero Member
  • *****
  • Posts: 587
  • Lazarus IDE contributor
    • GitLab profile
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #17 on: November 22, 2025, 10:21:46 pm »
Interesting implementation! Just a quick overview without testing...

1. You can use the RegisterChangeEvent events to hook for adding/removing editors:
Code: Pascal  [Select][+][-]
  1. SourceEditorManagerIntf.RegisterChangeEvent(semEditorDestroy, @MyHandlerDestroy);
  2. SourceEditorManagerIntf.RegisterChangeEvent(semEditorCreate, @MyHandlerCreate);
  3. {$if declared(semEditorCloned)} // since Lazarus 4.0
  4. SourceEditorManagerIntf.RegisterChangeEvent(semEditorCloned, @MyHandlerCreate); // also Create event
  5. {$endif}

2. Perhaps its other handlers will also be useful?

3. In the event of an error opening the URL, it's better to simply display a message box instead of raising an exception, which could lead to the loss of unsaved data.

4. It seems this won't work if another plugin also overrides event handlers ((



By the way:
* AltHighlightManager.Free can be called without checking for nil, since it's a class method.
* Instead of "TSynEdit(EditorsList)", it's better to use "EditorsList as TSynEdit", since is checks the type before use (although I see you check it before assignment).

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #18 on: November 22, 2025, 10:34:41 pm »
@LV,

Unfortunately, I am not getting what you described.  Maybe I'm doing something wrong or maybe it is because I don't use the docked IDE ?

Anyway, when I press the Alt key, Lazarus' main window comes to the top.  I can see that the url gets underlined for a split second but once the main window has come to the top, the url is no longer highlighted and clicking on it has no effect.

Attached to this post are screenshots of "before pressing alt" and "after pressing alt".  Notice that the main window is obscured before pressing Alt, after Alt is pressed then what appears is what is in the second screenshot but, the url is not underlined and clicking on it has no effect.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 380
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #19 on: November 22, 2025, 10:46:52 pm »
@440bx,
1. Press Alt -> the link will be highlighted.
2. Hold Alt and left-click.

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #20 on: November 22, 2025, 11:31:08 pm »
@440bx,
1. Press Alt -> the link will be highlighted.
2. Hold Alt and left-click.
Works perfectly!  Short and simple.  Thank you @LV, this is great :)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 380
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #21 on: November 22, 2025, 11:34:54 pm »
You're welcome. Good night. :)

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #22 on: November 23, 2025, 11:36:00 am »
@LV,

There is a problem with the package.  When it is installed, quitting Lazarus results in Lazarus using 100% of the CPU for about 10 seconds before it ends.

This is noticeable if you're running something like Process Hacker or Process Explorer where it is shown one CPU is pegged at 100% for roughly 10 seconds.  It seems to eventually end without leaving anything "bad" but, it shouldn't take that long to end.  When the package is not installed, Lazarus ends in fractions of a second.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 380
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #23 on: November 23, 2025, 03:16:00 pm »
@440bx,
I was unable to reproduce your issue on two computers running Windows 11 with Lazarus 3.4 and trunk. The CPU load was nearly 0%, and in all tested cases, the Lazarus IDE closed "instantly".

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #24 on: November 23, 2025, 04:47:06 pm »
@440bx,
I was unable to reproduce your issue on two computers running Windows 11 with Lazarus 3.4 and trunk.
Just FYI, I am running Lazarus v4.0rc3 (release candidate) on Win 7 SP1 64 bit.

The CPU load was nearly 0%, and in all tested cases, the Lazarus IDE closed "instantly".
That's what should happen but, doesn't happen on my installation when the package is installed.

Attached is a screenshot of CPU consumption when quitting Lazarus when the package is installed.  It took over 10 seconds for Lazarus to end and, noticeably, for some reason Lazarus does a lot of disc I/O when the package is installed (34.78MB/s in the screenshot and stays roughly at that number until Lazarus finally ends.)

The CPU usage is 55.22% because this is a VM installation with 2 cores.  One core at 100% is 50% total CPU utilization.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 380
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #25 on: November 23, 2025, 08:06:22 pm »
@440bx,
Everything works well on Windows 11. To understand why this is happening on Windows 7, I need to borrow a friend's computer or purchase a copy of Windows 7. I will try that next week.

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #26 on: November 23, 2025, 09:02:20 pm »
@440bx,
Everything works well on Windows 11. To understand why this is happening on Windows 7, I need to borrow a friend's computer or purchase a copy of Windows 7. I will try that next week.
I don't want you to go through that much trouble.

The problem might also be that I'm using a different version of Lazarus than you are.

In the meantime, I'm using Domingo's package which works fine.

With hesitation, I'm going to mention that there are a fair number of places that offer free Windows 7 product keys (many of them are genuine, honest to goodness product keys of computers that have long been put "to sleep".)  Original ISOs are available from a fair number of reputable sites.  IOW, you could install it in a Hyper-V VM at no cost.

The one potential problem is that in your hunt for good product keys you'll run into some "less than reputable" sites that could be problematic if you're not _very_ careful.

HTH.
 
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 380
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #27 on: November 25, 2025, 06:58:40 pm »
I find the topic discussed in this post quite interesting. I have worked on the package and am currently using it in my projects with Lazarus on Windows 11. Anyone is welcome to test it, modify it as they wish, and use it for their own purposes.


Ctrl+Click URL Highlighter for Lazarus IDE

This package adds Ctrl+Click URL navigation to the Lazarus IDE, as well as URL highlighting when holding Ctrl.
It works similarly to URL navigation in modern IDEs.

Features

-Detects URLs inside source code:
  - http://…
  - https://…
  - ftp://…
  - file://…
  - www.…

- Underlines the URL when hovering with the mouse while holding Ctrl
- Changes the mouse cursor to a hand when hovering over a link
- Opens the URL in the browser via Ctrl + LeftClick
- Fully supports the first editor tab (handles Lazarus initialization order)

How it Works

The package attaches the following handlers to every TSynEdit inside the source editor:
- OnMouseMove — detects mouse position
- OnPaint — draws the underline under the URL
- OnKeyDown/OnKeyUp — tracks Ctrl key state
- OnMouseDown — handles Ctrl+Click
- semEditorCreate and semEditorActivate — attaches handlers to newly created and already existing editors

When the mouse is over a URL and Ctrl is pressed, the package highlights it; when Ctrl+Click is performed, it calls OpenURL or OpenDocument.

Installation

1. Open Lazarus.
2. Go to Package → Open Package File (.lpk).
3. Select SynEditOpenURL.lpk.
4. Click Compile.
5. Click Use → Install and confirm Lazarus restart.

After Lazarus restarts, the functionality is enabled automatically.

Known Limitations
- Underline appears only while holding Ctrl.
- URL detection is limited to a specific set of characters.

Project Structure
SynEditOpenURL/
 ├─ SynEditOpenURL.pas        — main module
 ├─ SynEditOpenURL.lpk        — Lazarus package
 └─ README.md                 — documentation

License

Free to use. You may include it in your own projects and modify it as needed.

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: [SOLVED] Opening a url from the Lazarus editor
« Reply #28 on: November 25, 2025, 07:26:16 pm »
@LV,

I just tried the package and I'm pleased to report that the delay when closing Lazarus is now gone.  Well done.

Thank you! :)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018