Skip to content

Commit b3e6262

Browse files
committed
Merge branch 'feature-url'
2 parents 584951c + 7b053e2 commit b3e6262

5 files changed

+59
-0
lines changed

Default (Linux).sublime-mousemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"button": "button1", "count": 1, "modifiers": ["alt"],
4+
"press_command": "note_open_url"
5+
}
6+
]

Default (OSX).sublime-mousemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"button": "button1", "count": 1, "modifiers": ["alt"],
4+
"press_command": "note_open_url"
5+
}
6+
]

Default (Windows).sublime-mousemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"button": "button1", "count": 1, "modifiers": ["alt"],
4+
"press_command": "note_open_url"
5+
}
6+
]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ To add more yaml items you can add them to the settings by modifying `note_yaml:
9797
{ "note_yaml" : ["categories"] }
9898
```
9999

100+
#### Other features
101+
- open urls: place cursor on the link then `alt + click` to open a url in the browser.
102+
100103
## Per-project notes
101104

102105
To have a different notes directory for a project, add the following in your `.sublime-project` file:

notes.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
from gzip import GzipFile
77
from pickle import load, dump
8+
import webbrowser
89

910
ST3 = int(sublime.version()) >= 3000
1011

@@ -360,6 +361,43 @@ def is_enabled(self):
360361
else:
361362
return False
362363

364+
365+
class NoteOpenUrlCommand(sublime_plugin.TextCommand):
366+
367+
def run(self, edit):
368+
s = self.view.sel()[0]
369+
370+
# Expand selection to possible URL
371+
start = s.a
372+
end = s.b
373+
374+
view_size = self.view.size()
375+
terminator = ['\t', ' ', '\"', '\'', '(', ')']
376+
377+
while (start > 0
378+
and not self.view.substr(start - 1) in terminator
379+
and self.view.classify(start) & sublime.CLASS_LINE_START == 0):
380+
start -= 1
381+
382+
while (end < view_size
383+
and not self.view.substr(end) in terminator
384+
and self.view.classify(end) & sublime.CLASS_LINE_END == 0):
385+
end += 1
386+
387+
# Check if this is URL
388+
url = self.view.substr(sublime.Region(start, end))
389+
390+
if url.startswith(('http://', 'https://')):
391+
webbrowser.open_new_tab(url)
392+
393+
def is_enabled(self):
394+
is_note = sublime.active_window().active_view().settings().get("is_note")
395+
if is_note:
396+
return is_note
397+
else:
398+
return False
399+
400+
363401
def save_to_brain():
364402
# print("SAVING TO DISK-----------------")
365403
# print(db)

0 commit comments

Comments
 (0)