Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit a409f14

Browse files
authored
Merge pull request #209 from ivans/master
Fill quick panel with tables with a selection from the active view
2 parents bcf3d60 + 9ed9287 commit a409f14

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

SQLTools.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,34 @@ def selectTable(callback):
412412
sublime.message_dialog('Your database has no tables.')
413413
return
414414

415-
Window().show_quick_panel(ST.tables, callback)
415+
ST.show_quick_panel_with_selection(ST.tables, callback)
416416

417417
@staticmethod
418418
def selectFunction(callback):
419419
if len(ST.functions) == 0:
420420
sublime.message_dialog('Your database has no functions.')
421421
return
422422

423-
Window().show_quick_panel(ST.functions, callback)
423+
ST.show_quick_panel_with_selection(ST.functions, callback)
424+
425+
@staticmethod
426+
def show_quick_panel_with_selection(arrayOfValues, callback):
427+
w = Window();
428+
view = w.active_view()
429+
selection = view.sel()[0]
430+
431+
initialText = ''
432+
# ignore obvious non-identifier selections
433+
if selection.size() <= 128:
434+
(row_begin,_) = view.rowcol(selection.begin())
435+
(row_end,_) = view.rowcol(selection.end())
436+
# only consider selections within same line
437+
if row_begin == row_end:
438+
initialText = view.substr(selection)
439+
440+
w.show_quick_panel(arrayOfValues, callback)
441+
w.run_command('insert', {'characters': initialText})
442+
w.run_command("select_all")
424443

425444
@staticmethod
426445
def on_query_completions(view, prefix, locations):

0 commit comments

Comments
 (0)