-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
8 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |