-
Notifications
You must be signed in to change notification settings - Fork 156
Open links when shift-click on link or url #203
Conversation
According to the documentation about
So I think if the URL doesn't start with the protocol then the shell module can not guess how to open it. Why not adding it when it misses? |
app/renderer/abr-document.js
Outdated
} | ||
|
||
var url = open.nextUntil(".cm-formatting-link-string").text(); | ||
if (url !== "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (url === "") return;
var hasProtocol = /^[a-z]+:\/\//.test(url);
if (!hasProtocol) {
url = "http://" + url;
}
shell.openExternal(url);
Few comments about this PR: Raw URL It obviously doesn't work with raw URL: This is working: [Test](http://google.com)
But clicking this does nothing: http://google.com Pointer I don't see the pointer when Alt key is pressed on a link, but a crosshair (I tried it on Windows 10). Probably related to https://github.com/codemirror/CodeMirror/blob/dda5d7220f0e3cbf8c203223ee4e7dc2d5c04bec/src/edit/key_events.js#L119 Alt key I would not use Alt key because 1) on Windows and some Linux DE the Alt key also triggers the menu if it's hidden, making the editor contents move with possible confusion about what is clicked, 2) Alt is already used by CodeMirror for column selection. Control/command is already used for multiple cursors and Shift is used for extending the current selection. My suggestion would be to:
This would also solve the pointer issue. What do you think? |
Also become robust against clicks on any part of the link for when CodeMirror breaks it up.
Ok, this is dealt with. The following cases work: http://google.com (raw url)
http://github.com ("github" is seen as a spelling error, so it breaks the link into `spans`)
[Facebook](facebook.com) (standard MD link without protocol)
[Facebook](https://facebook.com) (standard MD link)
Ok, using Shift key now, when nothing is selected. CodeMirror doesn't seem to emit a |
Selection is not updated yet when
You don't need to use CodeMirror events, you can simply do: document.addEventListener("mouseup", function () {
// Do stuff
}); |
app/renderer/abr-document.js
Outdated
var linkIsClickable = !that.cm.somethingSelected() && | ||
e.type === "keydown" && | ||
e.shiftKey; | ||
document.body.classList.toggle("shift-pressed", linkIsClickable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is smart, but I had to read it twice to understand why you did it this way. Could you rename the class name in something less confusing (maybe "link-clickable")?
I now open the link on |
Thanks! |
No problem! This is a great app! Do you have an ETA on the next release? |
As soon as possible! (I'm too busy right now 😕) |
Related to: #198
Caveats:
The links only open when they're in the form
https://github.com
. Simplegithub.com
orwww.github.com
won't do anything. I'm unsure if this is something electron does on purpose. @brrd Any ideas?