Allow search query longer than the screen width
Before adoption: this commit came in with the history the project adopted, so no landing records it.
By implementing horizontal scrolling of the prompt line. Maximum length is hard-coded to 300-chars. Close #1312 Fix #1225
authored by Junegunn Choi · committed by Junegunn Choi · parent f0fe79d · Browse files · 2 files·+39 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+39 added−17 removed
- other:+39 added−17 removed
Provenance
- Commit
0edbcbd- Tree
168e677- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
f0fe79d
2 files changed+39 added−17 removed
modified:src/constants.go+4 added-3 removed
20 unmodified lines21 readerPollIntervalStep = 5 * time.Millisecond22 readerPollIntervalMax = 50 * time.Millisecond23 24 // Terminal25- initialDelay = 20 * time.Millisecond26- initialDelayTac = 100 * time.Millisecond27- spinnerDuration = 200 * time.Millisecond25+ initialDelay = 20 * time.Millisecond26+ initialDelayTac = 100 * time.Millisecond27+ spinnerDuration = 200 * time.Millisecond28+ maxPatternLength = 30029 30 // Matcher31 numPartitionsMultiplier = 832 maxPartitions = 3251 unmodified linesmodified:src/terminal.go+35 added-14 removed
57 unmodified lines58 initDelay time.Duration59 inlineInfo bool60 prompt string61 promptLen int62+ queryLen [2]int63 layout layoutType64 fullscreen bool65 hscroll bool66 hscrollOff int1 unmodified line68 wordNext string69 cx int70 cy int71 offset int72+ xoffset int73 yanked []rune74 input []rune75 multi bool76 sort bool288 unmodified lines365 }366 t := Terminal{367 initDelay: delay,368 inlineInfo: opts.InlineInfo,369+ queryLen: [2]int{0, 0},370 layout: opts.Layout,371 fullscreen: fullscreen,372 hscroll: opts.Hscroll,373 hscrollOff: opts.HscrollOff,1 unmodified line375 wordNext: wordNext,376 cx: len(input),377 cy: 0,378 offset: 0,379+ xoffset: 0,380 yanked: []rune{},381 input: input,382 multi: opts.Multi,383 sort: opts.Sort > 0,259 unmodified lines643 }644 for i := 0; i < t.window.Height(); i++ {645 t.window.MoveAndClear(i, 0)646 }643- t.truncateQuery()647 }648 649 func (t *Terminal) move(y int, x int, clear bool) {650 h := t.window.Height()19 unmodified lines670 t.window.Move(y, x)671 }672 }673 674+func (t *Terminal) truncateQuery() {675+ t.input, _ = t.trimRight(t.input, maxPatternLength)676+ t.cx = util.Constrain(t.cx, 0, len(t.input))677+}678+679+func (t *Terminal) updatePromptOffset() ([]rune, []rune) {680+ maxWidth := util.Max(1, t.window.Width()-t.promptLen-1)681+682+ _, overflow := t.trimLeft(t.input[:t.cx], maxWidth)683+ minOffset := int(overflow)684+ maxOffset := util.Min(util.Min(len(t.input), minOffset+maxWidth), t.cx)685+686+ t.xoffset = util.Constrain(t.xoffset, minOffset, maxOffset)687+ before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth)688+ beforeLen := t.displayWidth(before)689+ after, _ := t.trimRight(t.input[t.cx:], maxWidth-beforeLen)690+ afterLen := t.displayWidth(after)691+ t.queryLen = [2]int{beforeLen, afterLen}692+ return before, after693+}694+695 func (t *Terminal) placeCursor() {672- t.move(0, t.promptLen+t.displayWidth(t.input[:t.cx]), false)696+ t.move(0, t.promptLen+t.queryLen[0], false)697 }698 699 func (t *Terminal) printPrompt() {700 t.move(0, 0, true)701 t.window.CPrint(tui.ColPrompt, t.strong, t.prompt)702+703+ before, after := t.updatePromptOffset()678- t.window.CPrint(tui.ColNormal, t.strong, string(t.input))704+ t.window.CPrint(tui.ColNormal, t.strong, string(before))705+ t.window.CPrint(tui.ColNormal, t.strong, string(after))706 }707 708 func (t *Terminal) printInfo() {709 pos := 0710 if t.inlineInfo {684- pos = t.promptLen + t.displayWidth(t.input) + 1711+ pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1712 if pos+len(" < ") > t.window.Width() {713 return714 }715 t.move(0, pos, true)644 unmodified lines1360 }1361 return true, sels1362 }1363 1337-func (t *Terminal) truncateQuery() {1338- maxPatternLength := util.Max(1, t.window.Width()-t.promptLen-1)1339- t.input, _ = t.trimRight(t.input, maxPatternLength)1340- t.cx = util.Constrain(t.cx, 0, len(t.input))1341-}1342-1364 func (t *Terminal) selectItem(item *Item) {1365 t.selected[item.Index()] = selectedItem{time.Now(), item}1366 t.version++1367 }44 unmodified lines1412 t.mutex.Lock()1413 t.initFunc()1414 t.resizeWindows()1415 t.printPrompt()1395- t.placeCursor()1396- t.refresh()1416 t.printInfo()1417 t.printHeader()1418+ t.placeCursor()1419+ t.refresh()1420 t.mutex.Unlock()1421 go func() {1422 timer := time.NewTimer(t.initDelay)1423 <-timer.C125 unmodified lines1549 exit(func() int { return exitInterrupt })1550 }1551 }1552 t.placeCursor()1553+ t.refresh()1554 t.mutex.Unlock()1555 })1534- t.refresh()1556 }1557 }()1558 1559 looping := true312 unmodified lines1872 }1873 } else if me.Down {1874 if my == 0 && mx >= 0 {1875 // Prompt1855- t.cx = mx1876+ t.cx = mx + t.xoffset1877 } else if my >= min {1878 // List1879 if t.vset(t.offset+my-min) && t.multi && me.Mod {1880 toggle()108 unmodified lines