Skip to content

fix: open fzf in an unclosed quote string - #605

Open
al-bashkir wants to merge 2 commits into
Aloxaf:masterfrom
al-bashkir:fix/open-quote-unambiguous
Open

al-bashkir wants to merge 2 commits into
Aloxaf:masterfrom
al-bashkir:fix/open-quote-unambiguous

Conversation

@al-bashkir

@al-bashkir al-bashkir commented Nov 23, 2026 •

Copy link
Copy Markdown

Stacked on #603. This branch has #603's commit (7689b3b, unchanged, by degnbol) and one commit on top. The two PRs change the same line, so merge #603 first and this PR then shows only its own commit. Or merge this PR, which closes both bugs.

What

Inside a quote that is not closed yet, Tab never opens fzf when the word already equals the common prefix of the matches. Each Tab inserts the same text again and nothing else happens.

_tst() { compadd "foo bar1" "foo bar2" }; compdef _tst tst
tst "foo bar<Tab>      # nothing happens, on every Tab

The usual way to get there is one Tab earlier: tst foo<Tab> with a completer that adds quoted matches writes "foo bar, and the next Tab is stuck.

Why

In this state zsh sets compstate[unambiguous] to "foo bar, with no closing quote. Since #448, the fast-path check compares it with the word plus a closing quote, which is "foo bar". The two differ, so fzf-tab takes the fast path (compstate[insert]=unambiguous), and zsh inserts text that is already on the line.

#448 covers the case where the closing quote is already on the line (tst ".#"<Tab>). Then compstate[unambiguous] has the closing quote too. This PR compares with and without the closing quote, so both cases work. On top of #603 the line is:

&& [[ "$compstate[unambiguous]" != "$compstate[quote]$IPREFIX$PREFIX$SUFFIX$ISUFFIX"(|"$compstate[quote]") ]] \

When the word is not quoted, compstate[quote] is empty and the check is the same as before.

Tests

Two new cases in test/fzftab.ztst, after #603's case:

The full fzftab.ztst passes with zsh 5.9. I did not run the binary-module pass on my machine (no autoconf here), but this change is in -ftb-complete, which is the same code in both passes.

Relation to #597

The first guard in #597 (skip the fast path when the word already starts with compstate[unambiguous]) also makes the first new test pass. #597 changes the lines around this one, so whichever of the two is merged second needs a small rebase. The tests in this PR still apply after #597.

🤖 Generated with Claude Code

With complete_in_word, compstate[unambiguous] holds the whole word,
including the text after the cursor. The early exit compared it with
the text before the cursor only, so it always inserted the unchanged
word and fzf never opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@al-bashkir
al-bashkir force-pushed the fix/open-quote-unambiguous branch from f175cfe to e02dcb6 Compare November 23, 2026 05:22
In `tst "foo bar<Tab>` with matches `foo bar1` and `foo bar2`, zsh
sets compstate[unambiguous] to `"foo bar`, with no closing quote. The
fast-path check compares it with `"foo bar"` (since Aloxaf#448), finds a
difference and inserts the same text again, so fzf never opens.
Compare with and without the closing quote.

Builds on Aloxaf#603: the compared word keeps its $SUFFIX$ISUFFIX, and a
test covers an unclosed quote with text after the cursor.
@al-bashkir
al-bashkir force-pushed the fix/open-quote-unambiguous branch from e02dcb6 to c80cdb1 Compare November 23, 2026 05:23
@al-bashkir
al-bashkir marked this pull request as ready for review November 24, 2026 04:50
njhoffman added a commit to njhoffman/fzf-tab that referenced this pull request Nov 27, 2026
…AUDE.md: gh -R for the fork

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
njhoffman added a commit to njhoffman/fzf-tab that referenced this pull request Nov 27, 2026
…among them (PR Aloxaf#582); fast-path tests that run the checks

- lib/ftb-switch-group: upstream PR Aloxaf#582's per-style loop (bold, underline,
  reverse) with the fork's italic; lib/-ftb-fzf accepts reverse. Any
  combination works; none wins.
- test: the case-twins tests ran under `menu true` from earlier cases, so
  zsh never inserted and the fast path's checks never ran. With menu unset,
  a new case (A/xaaa, a/xaaa) fails without the twins check; the flat twins
  need either it or Aloxaf#576's segment check. PR Aloxaf#605's two unclosed-quote
  cases added (they fail with the fast path forced open).
- TODO: the three items done; the open upstream PRs the fork carries are
  watched in the recurring upstream check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants