From 3ba82b6d87348b119f9a7fd168ad8a597a18b4b2 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 27 Feb 2025 15:49:15 +0900 Subject: [PATCH] Make truncateQuery faster https://github.com/junegunn/fzf/issues/4292#issuecomment-2687051731 --- src/terminal.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/terminal.go b/src/terminal.go index 2f00a398..19230a9d 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2286,7 +2286,11 @@ func (t *Terminal) move(y int, x int, clear bool) { } func (t *Terminal) truncateQuery() { - t.input, _ = t.trimRight(t.input, maxPatternLength) + // We're limiting the length of the query not to make fzf unresponsive when + // the user accidentally pastes a huge chunk of text. Therefore, we're not + // interested in the exact display width of the query. We just limit the + // number of runes. + t.input = t.input[:util.Min(len(t.input), maxPatternLength)] t.cx = util.Constrain(t.cx, 0, len(t.input)) }