summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-09-18 04:20:29 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-09-18 14:34:48 +0900
commit1854922f0cca9959838b73938f10d6d8c968d4c9 (patch)
tree4272caecdd2d8e76cf9f575d86c9372247eb01f9
parent2fc7c18747250ebf8adf68d2057ec22af6976f29 (diff)
Truncate the query string if it's too long
Use hard-coded limit to keep it simple. An alternative is to dynamically calculate the width of the visible area and use it as the limit, but it can cause unwanted truncation of the query on screen resize/split.
-rw-r--r--src/constants.go7
-rw-r--r--src/terminal.go5
2 files changed, 9 insertions, 3 deletions
diff --git a/src/constants.go b/src/constants.go
index 04b10903..acb3b4cc 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -19,9 +19,10 @@ const (
readerBufferSize = 64 * 1024
// Terminal
- initialDelay = 20 * time.Millisecond
- initialDelayTac = 100 * time.Millisecond
- spinnerDuration = 200 * time.Millisecond
+ initialDelay = 20 * time.Millisecond
+ initialDelayTac = 100 * time.Millisecond
+ spinnerDuration = 200 * time.Millisecond
+ maxPatternLength = 100
// Matcher
numPartitionsMultiplier = 8
diff --git a/src/terminal.go b/src/terminal.go
index 5b26eebe..fa758e93 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -1337,6 +1337,11 @@ func (t *Terminal) Loop() {
if !doAction(action, mapkey) {
continue
}
+ // Truncate the query if it's too long
+ if len(t.input) > maxPatternLength {
+ t.input = t.input[:maxPatternLength]
+ t.cx = util.Constrain(t.cx, 0, maxPatternLength)
+ }
changed = string(previousInput) != string(t.input)
} else {
if mapkey == C.Rune {