Skip to content

Commit f7edacb

Browse files
committed
refactored open link command
1 parent 133df3b commit f7edacb

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

Default (OSX).sublime-keymap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212

1313
{ "keys": ["enter"], "command": "note_open_url", "context":
14-
[{ "key": "selector", "operator": "equal", "operand": "text.html.markdown.note markup.underline.link.markdown" }]
14+
[{ "key": "selector", "operator": "equal", "operand": "text.html.markdown.note meta.link.inline.markdown | text.html.markdown.note meta.link.inet.markdown" }]
1515
},
1616

1717
// Notes: Jotter keymaps

note_support.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
11
import sublime, sublime_plugin
22
import webbrowser
33

4+
45
class NoteOpenUrlCommand(sublime_plugin.TextCommand):
56

67
def run(self, edit):
7-
s = self.view.sel()[0]
8-
9-
# Expand selection to possible URL
10-
start = s.a
11-
end = s.b
12-
13-
view_size = self.view.size()
14-
terminator = ['\t', ' ', '\"', '\'', '(', ')']
15-
16-
while (start > 0
17-
and not self.view.substr(start - 1) in terminator
18-
and self.view.classify(start) & sublime.CLASS_LINE_START == 0):
19-
start -= 1
20-
21-
while (end < view_size
22-
and not self.view.substr(end) in terminator
23-
and self.view.classify(end) & sublime.CLASS_LINE_END == 0):
24-
end += 1
25-
26-
# Check if this is URL
27-
url = self.view.substr(sublime.Region(start, end))
28-
29-
if url.startswith(('http://', 'https://')):
30-
webbrowser.open_new_tab(url)
8+
v = self.view
9+
s = v.sel()[0]
10+
link_region = v.extract_scope(s.a)
11+
url = v.substr(link_region)
12+
webbrowser.open_new_tab(url)
3113

3214
def is_enabled(self):
33-
is_note = sublime.active_window().active_view().settings().get("is_note")
34-
if is_note:
35-
return is_note
36-
else:
37-
return False
15+
return 'Note.tmLanguage' in self.view.settings().get("syntax")

0 commit comments

Comments
 (0)