Skip to content

Commit

Permalink
fix: don't let control characters mess up the display
Browse files Browse the repository at this point in the history
Before:

    ╭─ CommandT [file] ────────────────────────────────────────────╮
    │>                                                             │
    ╰──────────────────────────────────────────────────────────────╯
    ╭──────────────────────────────────────────────────────────────╮
    │>                                                             │
    │↳ Icon^M                                                      │
    │↳                                                             │
    │  brew.rb                                                     │
    │  ...etc                                                      │
    ╰──────────────────────────────────────────────────────────────╯

After:

    ╭─ CommandT [file] ────────────────────────────────────────────╮
    │>                                                             │
    ╰──────────────────────────────────────────────────────────────╯
    ╭──────────────────────────────────────────────────────────────╮
    │> Icon\r                                                      │
    │  brew.rb                                                     │
    │  ...etc                                                      │
    ╰──────────────────────────────────────────────────────────────╯

Note that this is a display-only thing, to stop undesired wrapping and
other visual distortions. You can't actually type "Icr" and expect it to
match the file (these is no "r" in the name), although you can open it
by accepting the selection.

Closes: wincent/command-t#402
  • Loading branch information
Padmamanickam authored and wincent committed Aug 31, 2022
1 parent eb16652 commit 0cb5008
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lua/wincent/commandt/private/match_listing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ end
local format_line = function(line, width, selected)
local prefix = selected and '> ' or ' '

-- Sanitize some control characters, plus blackslashes.
line = line
:gsub('\\', '\\\\')
:gsub('\b', '\\b')
:gsub('\f', '\\f')
:gsub('\n', '\\n')
:gsub('\r', '\\r')
:gsub('\t', '\\t')
:gsub('\v', '\\v')

-- Right pad so that selection highlighting is shown across full width.
if width < 104 then
if #line > 99 then
Expand Down

0 comments on commit 0cb5008

Please sign in to comment.