Skip to content
Myr

Go to the closest match when disabling raw mode

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 9ace135 · Browse files · 2 files+53 added−16 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+53 added−16 removed

  • tests:+22 added−0 removed
  • other:+31 added−16 removed

2 files+53 added−16 removed

modified:src/terminal.go+31 added-16 removed
298 unmodified lines
299 subWordRubout string300 subWordNext string301 cx int302 cy int303 lastMatchingIndex int32303 offset int304 xoffset int305 yanked []rune306 input []rune
687 unmodified lines
994 subWordRubout: subWordRubout,995 subWordNext: subWordNext,996 cx: len(input),997 cy: 0,999 lastMatchingIndex: minItem.Index(),998 offset: 0,999 xoffset: 0,1000 yanked: []rune{},1001 input: input,
2220 unmodified lines
3222 for line, itemCount := startLine, 0; line <= maxy; line, itemCount = line+1, itemCount+1 {3223 if itemCount < count {3224 item := t.merger.Get(itemCount + t.offset)3225 current := itemCount == t.cy-t.offset3228 if current && (!t.raw || t.isItemMatch(item.item)) {3229 t.lastMatchingIndex = item.Index()3230 }3226 line = t.printItem(item, line, maxy, itemCount, current, barRange)3227 } else if !t.prevLines[line].empty {3228 t.renderEmptyLine(line, barRange)3229 }
2886 unmodified lines
6116 }6117 req(reqList)6118 case actToggleRaw, actEnableRaw, actDisableRaw:6119 prevRaw := t.raw6120 newRaw := t.raw6121 switch a.t {6122 case actEnableRaw:6127 t.raw = true6123 newRaw = true6124 case actDisableRaw:6129 t.raw = false6125 newRaw = false6126 case actToggleRaw:6131 t.raw = !t.raw6127 newRaw = !t.raw6128 }6133 if prevRaw == t.raw {6129 if prevRaw == newRaw {6130 break6131 }6132 prevPos := t.cy - t.offset6133 prevIndex := t.currentIndex()6138 if t.raw {6134 if newRaw {6135 // Build matchMap if not available6136 if len(t.matchMap) == 0 {6137 t.matchMap = t.resultMerger.ToMap()6138 }6139 t.merger = t.passMerger6140 } else {6141 // Find the closest matching item6142 if !t.isCurrentItemMatch() && t.resultMerger.Length() > 1 {6143 distance := 06144 Loop:6145 for {6146 distance++6147 checks := 06148 for _, cy := range []int{t.cy + distance, t.cy - distance} {6149 if cy >= 0 && cy < t.merger.Length() {6150 checks++6151 item := t.merger.Get(cy).item6152 if t.isItemMatch(item) {6153 prevIndex = item.Index()6154 break Loop6155 }6156 }6157 }6158 if checks == 0 {6159 break6160 }6161 }6162 }61636164 t.merger = t.resultMerger61656166 // Need to remove non-matching items from the selection6167 if t.multi > 0 && len(t.selected) > 0 {6168 t.filterSelected()6169 req(reqInfo)6170 }6171 }6172 t.raw = newRaw61736174 // Try to retain position6175 if prevIndex != minItem.Index() {6156 i := t.merger.FindIndex(prevIndex)6157 if i >= 0 {6158 t.cy = i6159 } else {6160 t.cy = t.merger.FindIndex(t.lastMatchingIndex)6161 }6176 t.cy = util.Max(0, t.merger.FindIndex(prevIndex))6177 t.offset = t.cy - prevPos6178 }61796180 // List needs to be rerendered
1076 unmodified lines
modified:test/test_raw.rb+22 added
77 unmodified lines
78 end7980 tmux.send_keys :Space81 tmux.until { assert_includes it, '[[]] 11' }8283 tmux.send_keys 'C-u', '5'84 tmux.until { assert_includes it, '> 5' }8586 tmux.send_keys 'C-x', 'C-p', 'C-p'87 tmux.until do88 assert_includes it, '> 25'89 assert_includes it, '▖ 24'90 end9192 tmux.send_keys 'C-x'93 tmux.until do94 assert_includes it, '> 25'95 assert_includes it, '▌ 15'96 end9798 # 35 is the closest match in raw mode99 tmux.send_keys 'C-x', :Up, :Up, :Up, :Up, :Up, :Up, 'C-x'100 tmux.until do101 assert_includes it, '> 35'102 assert_includes it, '▌ 25'103 end104 end105end