From 92b7efafcacfa5c5de2a8f22abd859b8fc994748 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 2 Aug 2020 10:02:11 +0900 Subject: [PATCH] Ignore punctuation characters before and after preview offset column This is to allow line numbers in a ctags output (e.g. 123;") --- src/terminal.go | 8 +++++++- test/test_go.rb | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 87703d3..a7e9e9b 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -23,12 +23,14 @@ import ( // import "github.com/pkg/profile" var placeholder *regexp.Regexp +var numericPrefix *regexp.Regexp var activeTempFiles []string const ellipsis string = ".." func init() { placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`) + numericPrefix = regexp.MustCompile(`^[[:punct:]]*([0-9]+)`) activeTempFiles = []string{} } @@ -1361,7 +1363,11 @@ func (t *Terminal) replacePlaceholder(template string, forcePlus bool, input str // Ascii to positive integer func atopi(s string) int { - n, e := strconv.Atoi(strings.ReplaceAll(s, "'", "")) + matches := numericPrefix.FindStringSubmatch(s) + if len(matches) < 2 { + return 0 + } + n, e := strconv.Atoi(matches[1]) if e != nil || n < 1 { return 0 } diff --git a/test/test_go.rb b/test/test_go.rb index 2afb5b8..bb5eb45 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1801,9 +1801,12 @@ class TestGoFZF < TestBase end def test_preview_scroll_begin_and_offset - tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter - tmux.until { |lines| lines.item_count == 1 } - tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] } + ['echo foo 123 321', 'echo foo :123: 321'].each do |input| + tmux.send_keys "#{input} | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter + tmux.until { |lines| lines.item_count == 1 } + tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] } + tmux.send_keys 'C-c' + end end def test_normalized_match