diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 3200308..768d0c2 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -11,7 +11,7 @@ }, { "keys": ["enter"], "command": "note_open_url", "context": - [{ "key": "selector", "operator": "equal", "operand": "text.html.markdown.note markup.underline.link.markdown" }] + [{ "key": "selector", "operator": "equal", "operand": "text.html.markdown.note meta.link.inline.markdown | text.html.markdown.note meta.link.inet.markdown" }] }, // Notes: Jotter keymaps diff --git a/note_support.py b/note_support.py index 2f6e7a2..4e7771f 100644 --- a/note_support.py +++ b/note_support.py @@ -1,37 +1,15 @@ import sublime, sublime_plugin import webbrowser + class NoteOpenUrlCommand(sublime_plugin.TextCommand): def run(self, edit): - s = self.view.sel()[0] - - # Expand selection to possible URL - start = s.a - end = s.b - - view_size = self.view.size() - terminator = ['\t', ' ', '\"', '\'', '(', ')'] - - while (start > 0 - and not self.view.substr(start - 1) in terminator - and self.view.classify(start) & sublime.CLASS_LINE_START == 0): - start -= 1 - - while (end < view_size - and not self.view.substr(end) in terminator - and self.view.classify(end) & sublime.CLASS_LINE_END == 0): - end += 1 - - # Check if this is URL - url = self.view.substr(sublime.Region(start, end)) - - if url.startswith(('http://', 'https://')): - webbrowser.open_new_tab(url) + v = self.view + s = v.sel()[0] + link_region = v.extract_scope(s.a) + url = v.substr(link_region) + webbrowser.open_new_tab(url) def is_enabled(self): - is_note = sublime.active_window().active_view().settings().get("is_note") - if is_note: - return is_note - else: - return False + return 'Note.tmLanguage' in self.view.settings().get("syntax")