Skip to content

Commit

Permalink
Namings fixed due to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
anijanyan committed Oct 28, 2022
1 parent d6e15f5 commit 82466a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/commands/default_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,9 @@ exports.commands = [{
scrollIntoView: "cursor",
readOnly: true
}, {
name: "jumptodef",
name: "openlink",
bindKey: bindKey("Ctrl+F3", "F3"),
exec: function(editor) { editor.jumptodef(); }
exec: function(editor) { editor.openLink(); }
}, {
name: "joinlines",
description: "Join lines",
Expand Down
23 changes: 13 additions & 10 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,32 +1733,35 @@ Editor.$uid = 0;
* Finds link at defined {row} and {column}
* @returns {String}
**/
this.findLinkAt = function (row,column) {
this.findLinkAt = function (row, column) {
var line = this.session.getLine(row);
var wordParts = line.split(/((?:https?|ftp):\/\/[\S]+)/);
var delta = column;
if (delta < 0) delta = 0;
var curLength = 0, itLength = 0, match;
wordParts.forEach(function (item) {
itLength = curLength + item.length;
if (delta >= curLength && delta <= itLength) {
var columnPosition = column;
if (columnPosition < 0) columnPosition = 0;
var previousPosition = 0, currentPosition = 0, match;
for (let item of wordParts) {
currentPosition = previousPosition + item.length;
if (columnPosition >= previousPosition && columnPosition <= currentPosition) {
if (item.match(/((?:https?|ftp):\/\/[\S]+)/)) {
match = item.replace(/[\s:.,'";}\]]+$/, "");
break;
}
}
curLength = itLength;
});
previousPosition = currentPosition;
}
return match;
};

/**
* Open valid url under cursor in another tab
* @returns {Boolean}
**/
this.jumptodef = function () {
this.openLink = function () {
var cursor = this.selection.getCursor();
var url = this.findLinkAt(cursor.row, cursor.column);
if (url)
window.open(url, '_blank');
return url != null;
};

/**
Expand Down

0 comments on commit 82466a2

Please sign in to comment.