mtxr / SublimeText-SQLTools

SQLTools for Sublime Text 3
https://code.mteixeira.dev/SublimeText-SQLTools/
GNU General Public License v3.0
177 stars 40 forks source link

Fill quick panel with tables with a selection from the active view. #209

Closed ivans closed 5 years ago

ivans commented 5 years ago

Enables a user to get to the desired table easier if table name is selected in the active view.

tkopets commented 5 years ago

Hi @ivans !

This is a neat idea - thank you for taking time and effort to prepare this PR.

The main thing to consider is making the user experience intuitively similar, so the same functionality would be expected and equally useful when a user is trying to select a function in def selectFunction(callback): as well.

Another smart thing that could be done here is checking if the user has selected multiple lines and ignoring such selections. Since the table name and function name identifiers rarely span on multiple lines we can ignore such selections instead of potentially populating whole paragraphs of text into input panel.

For example my workflow with SQLTools involves a lot of text-selecting and executing and occasioanly I would lookup the table definition while still having a whole paragraph of SQL selected.

ivans commented 5 years ago

Hi,

I didn't even know that SQLTools lists functions. Don't know how I missed it. Thanks.

I tried a different implementation now: multiple selections are join with a space and newlines are removed. I don't think that it is a problem if a quick panel is opened with a previously selected query because that text is selected so if you start typing anything that text is gone.

tkopets commented 5 years ago

On multiple selections: I don't see a usecase for joining the multiple selections together and how that might be a helpful input for the filter panel.

On long text in the filter panel: If we know beforehand the selection is not an identifier and is not going to be a meaningful filter - there is no need to put it there. I do want this feature to be helpful but avoid frustration or alienate existing users, so if we introduce it we gotta be careful here. If the filter does not make sense, I do want to see the list of existing tables/functions (to explore or scroll this list) without doing extra work.

tkopets commented 5 years ago

I think something like this should do the trick:

    @staticmethod
    def show_quick_panel_with_selection(arrayOfValues, callback):
        w = Window();
        view = w.active_view()
        selection = view.sel()[0]

        initialText = ''
        # ignore obvious non-identifier selections
        if selection.size() <= 128:
            (row_begin,_) = view.rowcol(selection.begin())
            (row_end,_) = view.rowcol(selection.end())
            # only consider selections within same line
            if row_begin == row_end:
                initialText = view.substr(selection)

        w.show_quick_panel(arrayOfValues, callback)
        w.run_command('insert', {'characters': initialText})
        w.run_command("select_all")
ivans commented 5 years ago

@tkopets I think this is a better solution so I pushed your version of show_quick_panel_with_selection. I did have a usecase for multiple selections: select two words (table names) and quickly find the join table providing that it's name contains both of the tables it joins. Although this is a usecase I don't think that is important enough to complicate code.

tkopets commented 5 years ago

@ivans Thank you for your contributions and feedback! Indeed the use case you provided sounds pretty reasonable.