-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbrowser_integration_navigate.py
More file actions
67 lines (49 loc) · 1.75 KB
/
Copy pathbrowser_integration_navigate.py
File metadata and controls
67 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from .browser_integration import *
get_links_js = """
var links = document.querySelectorAll('a');
var result = []
for(var i=0; i < links.length; i++) {
var link = links[i];
if (link.href) {
result.push([link.text, link.href])
}
}
return result;
"""
class BrowserIntegrationNavigateCommand(sublime_plugin.WindowCommand):
plugin_name = "Navigate To"
plugin_description = "Opens a input panel to enter a URL to load in Chrome."
@staticmethod
def visible():
return browser.connected()
@require_browser
@async
def run(self):
def onDone(str):
from urllib.parse import urlparse
url = urlparse(str)
if not url.netloc:
url = 'http://' + url.geturl()
else:
url = url.geturl()
with loading("Opening %s" % url):
browser.get(url)
status("Loaded %s" % url)
result = browser.execute(get_links_js) or []
def onQuickDone(i):
if i == 0:
view = self.window.show_input_panel('Enter URL',
browser.current_url,
onDone, None, None)
view.sel().add(sublime.Region(0, view.size()))
elif i == 1:
browser.back()
elif i == 2:
browser.forward()
elif i >= 3:
browser.get(result[i-3][1])
self.window.show_quick_panel(
[['Custom URL', 'Enter a custom URL to navigate'],
['Back', 'Navigate to previous location'],
['Forward', 'Navigate to next location']] + result,
onQuickDone)