Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Open links on click #198

Closed
kossmoboleat opened this issue Aug 20, 2017 · 7 comments
Closed

Open links on click #198

kossmoboleat opened this issue Aug 20, 2017 · 7 comments

Comments

@kossmoboleat
Copy link

Hello,

excuse me if this functionality is already possible, but I wasn't able to find it. In some editors http-links become clickable when they're valid URLs. Other editors use a key modifier to trigger this like ctrl/cmd on Windows,Linux/macOs. Perhaps even the multi-cursor feature could be kept in combination with ctrl/cmd?

Best regards,
Tim

@ayaankazerouni
Copy link
Contributor

@brrd How's it going? I'd like this feature too and am interested in working on it. Any pointers on where to start poking around?

@brrd
Copy link
Owner

brrd commented Sep 22, 2017

I would try to do this:

1. To get the cursor: pointer on a link when Ctrl is pressed

Set event handler (probably in abrDocument):

function ctrlKeyHandler (e) {
    if (!e.metaKey) return;
    var isKeydown = e.type === keydown;
    $(document.body).toggleClass("ctrl-pressed", isKeydown);
}

$(window).keydown(ctrlKeyHandler).keyup(ctrlKeyHandler);

LESS rule:

.ctrl-pressed .cm-link:hover, .ctrl-pressed .cm-url:hover {
    cursor: pointer;
}

2. To open the link when clicked

Set event handler (probably in abrDocument):

function openLinkHandler (e) {
    if (!document.body.hasClass("ctrl-pressed")) return;
    // Get the URL of the clicked link 
    // TODO: Here you will have to handle more specific situations where the url is actually stored in a sibbling element, e.g. [test](http://test.com)
    var url =  $(this).text();
    // Then open url in browser
    shell.openExternal(url);
}

$(window).on("click", ".cm-link, .cm-url", openLinkHandler);

I didn't test this code, it is just an idea. PR is welcome.

@ayaankazerouni
Copy link
Contributor

Ok, cool. PR should be incoming in a few days. Thanks!

@lascapi
Copy link

lascapi commented Dec 13, 2019

Hi! :) Is this feature on the 0.7.0 version ? I would like to use it.
Thanks for your work and your response.

@brrd
Copy link
Owner

brrd commented Dec 13, 2019

Normally you can open the link by clicking on it while pressing shift. But this feature look broken in 0.7.0. I will open a new issue.

@lascapi
Copy link

lascapi commented Dec 13, 2019

Ho! Thanks :) It's working for me with Windows 7. I tried just with Ctrl, that's why.
Can we improve it with a tip when the mouse is over the link like [Maj+Click to open the link]?
And it's working for the scheme (title)[url] only. Is it possible to active it for a simple url ?
Thanks!

@brrd
Copy link
Owner

brrd commented Dec 13, 2019

Can we improve it with a tip when the mouse is over the link like [Maj+Click to open the link]?
And it's working for the scheme (title)[url] only. Is it possible to active it for a simple url ?

Please create new issues for those requests if you want them to be took into account.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

4 participants