Implement --scroll-off=LINES
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #2533
authored by Junegunn Choi · committed by Junegunn Choi · parent e0dd2be · Browse files · 4 files·+72 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+72 added−4 removed
- tests:+33 added−0 removed
- other:+39 added−4 removed
Provenance
- Commit
02cee22- Tree
27e4366- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
e0dd2be
4 files changed+72 added−4 removed
modified:man/man1/fzf.1+6 added-2 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE SOFTWARE.23 ..24-.TH fzf 1 "Oct 2021" "fzf 0.27.3" "fzf - a command-line fuzzy finder"24+.TH fzf 1 "Nov 2021" "fzf 0.27.4" "fzf - a command-line fuzzy finder"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 105 unmodified lines134 .B "--keep-right"135 Keep the right end of the line visible when it's too long. Effective only when136 the query string is empty.137 .TP138+.BI "--scroll-off=" "LINES"139+Number of screen lines to keep above or below when scrolling to the top or to140+the bottom (default: 0).141+.TP142 .B "--no-hscroll"143 Disable horizontal scroll144 .TP141-.BI "--hscroll-off=" "COL"145+.BI "--hscroll-off=" "COLS"146 Number of screen columns to keep to the right of the highlighted substring147 (default: 10). Setting it to a large value will cause the text to be positioned148 on the center of the screen.149 .TP848 unmodified linesmodified:src/options.go+13 added-1 removed
42 unmodified lines43 --no-mouse Disable mouse44 --bind=KEYBINDS Custom key bindings. Refer to the man page.45 --cycle Enable cyclic scroll46 --keep-right Keep the right end of the line visible on overflow47+ --scroll-off=LINES Number of screen lines to keep above or below when48+ scrolling to the top or to the bottom (default: 0)49 --no-hscroll Disable horizontal scroll48- --hscroll-off=COL Number of screen columns to keep to the right of the50+ --hscroll-off=COLS Number of screen columns to keep to the right of the51 highlighted substring (default: 10)52 --filepath-word Make word-wise movements respect path separators53 --jump-labels=CHARS Label characters for jump and jump-accept54 146 unmodified lines201 Cycle bool202 KeepRight bool203 Hscroll bool204 HscrollOff int205+ ScrollOff int206 FileWord bool207 InfoStyle infoStyle208 JumpLabels string209 Prompt string53 unmodified lines263 Cycle: false,264 KeepRight: false,265 Hscroll: true,266 HscrollOff: 10,267+ ScrollOff: 0,268 FileWord: false,269 InfoStyle: infoDefault,270 JumpLabels: defaultJumpLabels,271 Prompt: "> ",1085 unmodified lines1357 case "--no-hscroll":1358 opts.Hscroll = false1359 case "--hscroll-off":1360 opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required")1361+ case "--scroll-off":1362+ opts.ScrollOff = nextInt(allArgs, &i, "scroll offset required")1363 case "--filepath-word":1364 opts.FileWord = true1365 case "--no-filepath-word":1366 opts.FileWord = false168 unmodified lines1535 } else if match, value := optString(arg, "--tabstop="); match {1536 opts.Tabstop = atoi(value)1537 } else if match, value := optString(arg, "--hscroll-off="); match {1538 opts.HscrollOff = atoi(value)1539+ } else if match, value := optString(arg, "--scroll-off="); match {1540+ opts.ScrollOff = atoi(value)1541 } else if match, value := optString(arg, "--jump-labels="); match {1542 opts.JumpLabels = value1543 validateJumpLabels = true1544 } else {9 unmodified lines1554 if opts.HscrollOff < 0 {1555 errorExit("hscroll offset must be a non-negative integer")1556 }1557 1558+ if opts.ScrollOff < 0 {1559+ errorExit("scroll offset must be a non-negative integer")1560+ }1561+1562 if opts.Tabstop < 1 {1563 errorExit("tab stop must be a positive integer")1564 }1565 113 unmodified linesmodified:src/terminal.go+20 added-1 removed
119 unmodified lines120 fullscreen bool121 keepRight bool122 hscroll bool123 hscrollOff int124+ scrollOff int125 wordRubout string126 wordNext string127 cx int128 cy int373 unmodified lines502 fullscreen: fullscreen,503 keepRight: opts.KeepRight,504 hscroll: opts.Hscroll,505 hscrollOff: opts.HscrollOff,506+ scrollOff: opts.ScrollOff,507 wordRubout: wordRubout,508 wordNext: wordNext,509 cx: len(input),510 cy: 0,2239 unmodified lines2750 height := t.maxItems()2751 2752 t.cy = util.Constrain(t.cy, 0, count-1)2753 2752- minOffset := t.cy - height + 12754+ minOffset := util.Max(t.cy-height+1, 0)2755 maxOffset := util.Max(util.Min(count-height, t.cy), 0)2756 t.offset = util.Constrain(t.offset, minOffset, maxOffset)2757+ if t.scrollOff == 0 {2758+ return2759+ }2760+2761+ scrollOff := util.Min(height/2, t.scrollOff)2762+ for {2763+ prevOffset := t.offset2764+ if t.cy-t.offset < scrollOff {2765+ t.offset = util.Max(minOffset, t.offset-1)2766+ }2767+ if t.cy-t.offset >= height-scrollOff {2768+ t.offset = util.Min(maxOffset, t.offset+1)2769+ }2770+ if t.offset == prevOffset {2771+ break2772+ }2773+ }2774 }2775 2776 func (t *Terminal) vmove(o int, allowCycle bool) {2777 if t.layout != layoutDefault {30 unmodified linesmodified:test/test_go.rb+33 added
2074 unmodified lines2075 tmux.until { |lines| assert_includes lines[1], '1' }2076 tmux.send_keys 'C-t'2077 tmux.until { |lines| assert_includes lines[1], '4' }2078 end2079+2080+ def test_scroll_off2081+ tmux.send_keys "seq 1000 | #{FZF} --scroll-off=3 --bind l:last", :Enter2082+ tmux.until { |lines| assert_equal 1000, lines.item_count }2083+ height = tmux.until { |lines| lines }.first.to_i2084+ tmux.send_keys :PgUp2085+ tmux.until do |lines|2086+ assert_equal height + 3, lines.first.to_i2087+ assert_equal "> #{height}", lines[3].strip2088+ end2089+ tmux.send_keys :Up2090+ tmux.until { |lines| assert_equal "> #{height + 1}", lines[3].strip }2091+ tmux.send_keys 'l'2092+ tmux.until { |lines| assert_equal '> 1000', lines.first.strip }2093+ tmux.send_keys :PgDn2094+ tmux.until { |lines| assert_equal "> #{1000 - height + 1}", lines.reverse[5].strip }2095+ tmux.send_keys :Down2096+ tmux.until { |lines| assert_equal "> #{1000 - height}", lines.reverse[5].strip }2097+ end2098+2099+ def test_scroll_off_large2100+ tmux.send_keys "seq 1000 | #{FZF} --scroll-off=9999", :Enter2101+ tmux.until { |lines| assert_equal 1000, lines.item_count }2102+ height = tmux.until { |lines| lines }.first.to_i2103+ tmux.send_keys :PgUp2104+ tmux.until { |lines| assert_equal "> #{height}", lines[height / 2].strip }2105+ tmux.send_keys :Up2106+ tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }2107+ tmux.send_keys :Up2108+ tmux.until { |lines| assert_equal "> #{height + 2}", lines[height / 2].strip }2109+ tmux.send_keys :Down2110+ tmux.until { |lines| assert_equal "> #{height + 1}", lines[height / 2].strip }2111+ end2112 end2113 2114 module TestShell2115 def setup478 unmodified lines