Skip to content

Commit

Permalink
Merge branch 'feature-url'
Browse files Browse the repository at this point in the history
  • Loading branch information
fk128 committed Jul 25, 2015
2 parents 584951c + 7b053e2 commit b3e6262
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Default (Linux).sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"button": "button1", "count": 1, "modifiers": ["alt"],
"press_command": "note_open_url"
}
]
6 changes: 6 additions & 0 deletions Default (OSX).sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"button": "button1", "count": 1, "modifiers": ["alt"],
"press_command": "note_open_url"
}
]
6 changes: 6 additions & 0 deletions Default (Windows).sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"button": "button1", "count": 1, "modifiers": ["alt"],
"press_command": "note_open_url"
}
]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ To add more yaml items you can add them to the settings by modifying `note_yaml:
{ "note_yaml" : ["categories"] }
```

#### Other features
- open urls: place cursor on the link then `alt + click` to open a url in the browser.

## Per-project notes

To have a different notes directory for a project, add the following in your `.sublime-project` file:
Expand Down
38 changes: 38 additions & 0 deletions notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
from gzip import GzipFile
from pickle import load, dump
import webbrowser

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

Expand Down Expand Up @@ -360,6 +361,43 @@ def is_enabled(self):
else:
return False


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)

def is_enabled(self):
is_note = sublime.active_window().active_view().settings().get("is_note")
if is_note:
return is_note
else:
return False


def save_to_brain():
# print("SAVING TO DISK-----------------")
# print(db)
Expand Down

0 comments on commit b3e6262

Please sign in to comment.