<s> from . browser_integration import * <EOL> get_dom_tree_js = """<STR_LIT>""" <EOL> class BrowserIntegrationSelectintCommand ( sublime_plugin . WindowCommand ) : <EOL> plugin_name = "<STR_LIT>" <EOL> plugin_description = "<STR_LIT>" <EOL> @ staticmethod <EOL> def visible ( ) : <EOL> return browser . connected ( ) <EOL> @ async <EOL> @ require_browser <EOL> def run ( self ) : <EOL> with loading ( "<STR_LIT>" ) : <EOL> dom_tree = browser . execute ( get_dom_tree_js ) <EOL> def build_subtree ( tree , path = [ ] , depth = <NUM_LIT:0> , curr = [ ] ) : <EOL> result = [ ] <EOL> node = path . pop ( <NUM_LIT:0> ) if path else None <EOL> for i , t in enumerate ( tree ) : <EOL> result . append ( ( "<STR_LIT:U+0020>" * depth + t [ '<STR_LIT>' ] , <EOL> t [ '<STR_LIT>' ] , curr + [ i ] ) ) <EOL> if i == node or len ( tree ) == <NUM_LIT:1> : <EOL> result . extend ( build_subtree ( t [ '<STR_LIT>' ] , path , <EOL> depth + <NUM_LIT:1> , curr + [ i ] ) ) <EOL> return result <EOL> @ async <EOL> def select ( i ) : <EOL> if i < <NUM_LIT:0> : <EOL> return <EOL> tag , xpath , path = self . items [ i ] <EOL> self . items = build_subtree ( dom_tree , path ) <EOL> self . window . show_quick_panel ( [ x for x , y , z in self . items ] , <EOL> select , <NUM_LIT:0> , i , self . highlight ) <EOL> self . items = build_subtree ( dom_tree ) <EOL> self . window . show_quick_panel ( [ x for x , y , z in self . items ] , <EOL> select , <NUM_LIT:0> , <NUM_LIT:0> , self . highlight ) <EOL> def highlight ( self , i ) : <EOL> selector = self . items [ i ] [ <NUM_LIT:1> ] <EOL> browser . select_xpath ( selector ) </s>
