Skip to content

Commit

Permalink
Fix tab width after ANSI reset code in preview window
Browse files Browse the repository at this point in the history
Close #1423
  • Loading branch information
junegunn committed Dec 22, 2018
1 parent 5624a89 commit 5d16b28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/terminal.go
Expand Up @@ -1036,12 +1036,14 @@ func (t *Terminal) printPreview() {
break
} else if lineNo > 0 {
var fillRet tui.FillReturn
prefixWidth := 0
_, _, ansi = extractColor(line, ansi, func(str string, ansi *ansiState) bool {
trimmed := []rune(str)
if !t.preview.wrap {
trimmed, _ = t.trimRight(trimmed, maxWidth-t.pwindow.X())
}
str, _ = t.processTabs(trimmed, 0)
str, width := t.processTabs(trimmed, prefixWidth)
prefixWidth += width
if t.theme != nil && ansi != nil && ansi.colored() {
fillRet = t.pwindow.CFill(ansi.fg, ansi.bg, ansi.attr, str)
} else {
Expand Down
6 changes: 6 additions & 0 deletions test/test_go.rb
Expand Up @@ -1532,6 +1532,12 @@ def test_inverse_only_search_should_not_sort_the_result
tmux.until { |lines| lines[-4] == ' b' }
tmux.until { |lines| lines[-5] == ' ccc' }
end

def test_preview_correct_tab_width_after_ansi_reset_code
writelines tempname, ["\x1b[31m+\x1b[m\t\x1b[32mgreen"]
tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter
tmux.until { |lines| lines[1].include?('+ green') }
end
end

module TestShell
Expand Down

0 comments on commit 5d16b28

Please sign in to comment.