<commit_before>from .browser_integration import *


get_links_js = """
    var links = document.links;
    var result = []

    for(var i=0; i < links.length; i++) {
        var link = links[i];

        if (link.href) {
            result.push([link.innerText, 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."

    @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)

        def onQuickDone(i):
            if i == 0:
                self.window.show_input_panel('Enter URL',
                                             browser.current_url,
                                             onDone, None, None)
            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)
<commit_msg>Improved navigate to custom URL to automatically select URL<commit_after>from .browser_integration import *


get_links_js = """
    var links = document.links;
    var result = []

    for(var i=0; i < links.length; i++) {
        var link = links[i];

        if (link.href) {
            result.push([link.innerText, 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."

    @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)

        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)

{'fraction_non_alphanumeric': 0.10844079718640094, 'fraction_numerical': 0.004396248534583822, 'mean_word_length': 1.478576615831518, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1054970', 'n_tokens_mistral': 960, 'n_tokens_neox': 903, 'n_words': 243}