sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
803 stars 39 forks source link

[ST4] "tab_completion": false doesn't stop tab_completion #4174

Open ShafinKhadem opened 3 years ago

ShafinKhadem commented 3 years ago

Description

adding "tab_completion": false to preferences doesn't stop tab_completion

Expected behavior

From documentation:

tab_completion (boolean) When enabled, pressing Tab will insert the best matching completion. When disabled, Tab will only trigger snippets or insert a tab character. Shift+Tab can be used to insert an explicit tab when tab_completion is enabled.

Steps to reproduce

Actual behavior

Even if tab_completion is false, pressing tab still triggers completion.

Environment

deathaxe commented 3 years ago

The binding indeed doesn't respect auto_completion setting.

    { "keys": ["tab"], "command": "commit_completion", "context":
        [{ "key": "auto_complete_visible" }]
    },

Maybe due to "Tab will only trigger snippets..."?

ShafinKhadem commented 3 years ago

The binding indeed doesn't respect auto_completion setting.

  { "keys": ["tab"], "command": "commit_completion", "context":
      [{ "key": "auto_complete_visible" }]
  },

Maybe due to "Tab will only trigger snippets..."?

Replacing that to:

    { "keys": ["tab"], "command": "commit_completion", "context":
        [
            { "key": "auto_complete_visible" },
            { "key": "setting.auto_complete_commit_on_tab" }
        ]
    },

makes sublime respect auto_complete_commit_on_tab settings. Behavior of tab_completion has changed from ST3: previously it was used to directly trigger completion, now it's used to show completions.

ShafinKhadem commented 3 years ago

Replacing that to:

  { "keys": ["tab"], "command": "commit_completion", "context":
      [
          { "key": "auto_complete_visible" },
          { "key": "setting.auto_complete_commit_on_tab" }
      ]
  },

makes sublime respect auto_complete_commit_on_tab settings. Behavior of tab_completion has changed from ST3: previously it was used to directly trigger completion, now it's used to show completions.

The problem of this new behavior is, it doesn't respect snippet's has_next_field. Even after aforementioned change: it doesn't respect has_next_field when setting.auto_complete_commit_on_tab is true and it completely disables tab completion when it's false unlike ST3. IMHO, along with aforementioned change, following should be added:

{ "keys": ["tab"], "command": "commit_completion", "context":
        [
            { "key": "has_next_field", "operator": "equal", "operand": false },
            { "key": "auto_complete_visible" },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "setting.tab_completion", "operator": "equal", "operand": true },
            { "key": "preceding_text", "operator": "regex_match", "operand": ".*\\w", "match_all": true },
        ]
},
Manuzor commented 3 years ago

[...] Behavior of tab_completion has changed from ST3: previously it was used to directly trigger completion, now it's used to show completions.

I've run into exactly this. Is there a way to get back instant try-to-complete-now when pressing tab? If not, should I open a new issue for that?

deathaxe commented 3 years ago

AFAIK, insert_best_completion has been removed. It won't be available anymore.

Manuzor commented 3 years ago

So it is no longer possible to use tab completion without ever seeing the popup? I guess I should create a new feature request for that, then? Seems hopeless, though, since it has been explicitly removed...

deathaxe commented 3 years ago

You may want to try "mini_auto_complete": true, setting instead. It is still undocumented feature as it has some rough edge cases, but luckily core devs like this feature and stated to not remove it.

It shows the best completion as phantom right after caret instead of displaying the popup. I personally prefer this feature over the old one from ST3 as it provides some kind of inline preview.

Manuzor commented 3 years ago

Wow, that is amazing! It's the perfect balance between a full auto-complete list popup and still providing a preview of what TAB will complete to. I also prefer this and I really hope this feature stays in. Thank you very much @deathaxe for sharing!

litezzzout commented 3 years ago

"mini_auto_complete" is terribly slow compared to "insert_best_completion"

deathaxe commented 1 year ago

_With regards to the discussion at https://forum.sublimetext.com/t/lorem-ipsum-tab-completion-occurs-even-with-tab-completion-disabled/66038/2 and reading this issue's comments, I have to conclude my suggestions about commit_completion binding being misplaced or even misleading._

The point rather is:

With tab_completion: false the command "auto_complete", "args": {"snippets_only": true} is executed when hitting tab key.

The core bug is that command displaying auto completion panel with available snippets, in case a word was entered which looks like the beginning of but doesn't exactly match any tabTrigger.

Steps to Reproduce

  1. open ST in SAFE MODE
  2. open plain text document
  3. set tab_completion: false in Preferences
  4. enter L
  5. hit tab

Actual Behavior

Pressing tab opens completion panel with "Lorem ipsum" being suggested.

Animation

Expected Behavior

Pressing tab inserts a tab (\t) as it did in ST2 and ST3, if the word in front of the caret doesn't exactly match any snippet's tabTrigger.

Notes:

Completion panel should be displayed when hitting tab, if the word in front of the caret exactly matches multiple snippets' tabTriggers. E.g.: User typed Lorem and several snippets use it as tabTrigger.