Skip to content
Myr

Include match positions in GET / HTTP response

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

Close #4726

authored by Junegunn Choi · committed by Junegunn Choi · parent 259e841 · Browse files · 3 files+38 added−3 removed
This commit

State

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

Diff stats

3 files+38 added−3 removed

  • tests:+25 added−0 removed
  • other:+13 added−3 removed

3 files+38 added−3 removed

modified:src/terminal.go+12 added-3 removed
214 unmodified lines
215 markerBottom216)217218type StatusItem struct {219 Index int `json:"index"`220 Text string `json:"text"`219 Index int `json:"index"`220 Text string `json:"text"`221 Positions []int `json:"positions,omitempty"`222}223224type Status struct {225 Reading bool `json:"reading"`
7643 unmodified lines
7869func (t *Terminal) dumpItem(i *Item) StatusItem {7870 if i == nil {7871 return StatusItem{}7872 }7872 return StatusItem{7873 item := StatusItem{7874 Index: int(i.Index()),7875 Text: i.AsString(t.ansi),7876 }7877 if t.resultMerger.pattern != nil {7878 _, _, pos := t.resultMerger.pattern.MatchItem(i, true, t.slab)7879 if pos != nil {7880 sort.Ints(*pos)7881 item.Positions = *pos7882 }7883 }7884 return item7885}78867887func (t *Terminal) tryLock(timeout time.Duration) bool {7888 sleepDuration := 10 * time.Millisecond
54 unmodified lines
modified:test/test_server.rb+25 added
14 unmodified lines
15 assert_equal 10, state[:matchCount]16 assert_empty state[:query]17 assert_equal({ index: 0, text: '1' }, state[:current])1819 # No positions when query is empty20 state[:matches].each do |m|21 assert_nil m[:positions]22 end23 assert_nil state[:current][:positions] if state[:current]2425 # Positions with a single-character query26 Net::HTTP.post(fn.call, 'change-query(1)')27 tmux.until { |lines| assert_equal 2, lines.match_count }28 state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)29 assert_equal [0], state[:current][:positions]30 state[:matches].each do |m|31 assert_includes m[:text], '1'32 assert_equal [m[:text].index('1')], m[:positions]33 end3435 # Positions with a multi-character query; verify sorted ascending36 Net::HTTP.post(fn.call, 'change-query(10)')37 tmux.until { |lines| assert_equal 1, lines.match_count }38 state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)39 assert_equal '10', state[:current][:text]40 assert_equal [0, 1], state[:current][:positions]41 assert_equal state[:current][:positions], state[:current][:positions].sort4243 # No match — no current item44 Net::HTTP.post(fn.call, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ')45 tmux.until { |lines| assert_equal 100, lines.item_count }46 tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }47 state = JSON.parse(Net::HTTP.get(fn.call), symbolize_names: true)
40 unmodified lines
modified:CHANGELOG.md+1 added
24 unmodified lines
25 ```26 - Improved the cache structure, reducing memory footprint per entry by 86x.27 - With the reduced per-entry cost, the cache now has broader coverage.28- fish: Improved command history (CTRL-R) (#4703) (@bitraid)29- `GET /` HTTP endpoint now includes `positions` field in each match entry, providing the indices of matched characters for external highlighting (#4726)30- Bug fixes31 - `--walker=follow` no longer follows symlinks whose target is an ancestor of the walker root, avoiding severe resource exhaustion when a symlink points outside the tree (e.g. Wine's `z:` → `/`) (#4710)32 - Fixed AWK tokenizer not treating a new line character as whitespace33 - Fixed `--{accept,with}-nth` removing trailing whitespaces with a non-default `--delimiter`
3209 unmodified lines