Skip to content
Myr

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

2 files+39 added−17 removed

modified:src/constants.go+4 added-3 removed
20 unmodified lines
21 readerPollIntervalStep = 5 * time.Millisecond22 readerPollIntervalMax = 50 * time.Millisecond2324 // 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 = 3002930 // Matcher31 numPartitionsMultiplier = 832 maxPartitions = 32
51 unmodified lines
modified:src/terminal.go+35 added-14 removed
57 unmodified lines
58 initDelay time.Duration59 inlineInfo bool60 prompt string61 promptLen int62 queryLen [2]int63 layout layoutType64 fullscreen bool65 hscroll bool66 hscrollOff int
1 unmodified line
68 wordNext string69 cx int70 cy int71 offset int72 xoffset int73 yanked []rune74 input []rune75 multi bool76 sort bool
288 unmodified lines
365 }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 line
375 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 lines
643 }644 for i := 0; i < t.window.Height(); i++ {645 t.window.MoveAndClear(i, 0)646 }643 t.truncateQuery()647}648649func (t *Terminal) move(y int, x int, clear bool) {650 h := t.window.Height()
19 unmodified lines
670 t.window.Move(y, x)671 }672}673674func (t *Terminal) truncateQuery() {675 t.input, _ = t.trimRight(t.input, maxPatternLength)676 t.cx = util.Constrain(t.cx, 0, len(t.input))677}678679func (t *Terminal) updatePromptOffset() ([]rune, []rune) {680 maxWidth := util.Max(1, t.window.Width()-t.promptLen-1)681682 _, 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)685686 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}694695func (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}698699func (t *Terminal) printPrompt() {700 t.move(0, 0, true)701 t.window.CPrint(tui.ColPrompt, t.strong, t.prompt)702703 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}707708func (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 lines
1360 }1361 return true, sels1362}13631337func (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}13421364func (t *Terminal) selectItem(item *Item) {1365 t.selected[item.Index()] = selectedItem{time.Now(), item}1366 t.version++1367}
44 unmodified lines
1412 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.C
125 unmodified lines
1549 exit(func() int { return exitInterrupt })1550 }1551 }1552 t.placeCursor()1553 t.refresh()1554 t.mutex.Unlock()1555 })1534 t.refresh()1556 }1557 }()15581559 looping := true
312 unmodified lines
1872 }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