diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index 5a9169e..4850ba5 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -11,5 +11,6 @@ { "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" }, { "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" }, { "keys": ["ctrl+e", "ctrl+l"], "command": "st_list_queries"}, - { "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}} + { "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}}, + { "keys": ["ctrl+e", "ctrl+i"], "command": "st_list_queries", "args": {"mode" : "insert"}} ] diff --git a/Default.sublime-commands b/Default.sublime-commands index 1e2e4f9..f47285a 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -53,6 +53,11 @@ "command": "st_list_queries", "args" : {"mode": "open"} }, + { + "caption": "ST: List and Insert Saved Queries", + "command": "st_list_queries", + "args" : {"mode": "insert"} + }, { "caption": "ST: Format Current SQL File", "command": "st_format" diff --git a/SQLTools.py b/SQLTools.py index 83869bd..632bb24 100644 --- a/SQLTools.py +++ b/SQLTools.py @@ -139,6 +139,20 @@ def toNewTab(content, name="", suffix="SQLTools Saved Query"): resultContainer.run_command('append', {'characters': content}) +def insertContent(content): + view = View() + # getting the settings local to this view/tab + settings = view.settings() + # saving the original settings for "auto_indent", or True if none set + autoIndent = settings.get('auto_indent', True) + # turn off automatic indenting otherwise the tabbing of the original + # string is not respected after a newline is encountered + settings.set('auto_indent', False) + view.run_command('insert', {'characters': content}) + # restore "auto_indent" setting + settings.set('auto_indent', autoIndent) + + def getOutputPlace(syntax=None, name="SQLTools Result"): if not settings.get('show_result_on_window', True): resultContainer = Window().find_output_panel(name) @@ -559,6 +573,8 @@ def cb(index): if mode == "run": ST.conn.execute(query, createOutput(), stream=settings.get('use_streams', False)) + elif mode == "insert": + insertContent(query) else: toNewTab(query, alias)