Skip to content

Completion backspace corrupts current line #31

@Kris-LIBIS

Description

@Kris-LIBIS

Describe the problem

Certain combinations of backspace and tabs cause the line input to get corrupted

Steps to reproduce the problem

Create the simple example below:

COMPLETIONS=%w'abc abc1 abc2'
reader = TTY::Reader.new(
  completion_handler: ->(word) { COMPLETIONS.grep(/^#{Regexp.escape(word)}/) },
  completion_suffix: " "
)
reader.on(:complete) do |event|
  puts "#{event.line}\n#{event.completions.join("\n")}" 
end
reader.read_line('>> ')

And press the following keys:

<TAB><TAB><BACKSPACE><BACKSPACE><TAB><TAB>

Actual behaviour

The following happens:

[key: <TAB>]
>> abc 
abc
abc1
abc2
>> abc _
[key: <TAB>]
>> abc1 
abc
abc1
abc2
>> abc1 _
[key: <BACKSPACE><BACKSPACE><TAB>]
>> abc 
abc
abc1
abc2
>> abc _
[key: <TAB>]
>> aabc1 
abc
abc1
abc2
>> aabc1 _

After the last <TAB>, the input line has prepended an extra 'a' character in front.

Expected behaviour

Line input after last <TAB> should be 'abc1 '

Describe your environment

  • OS version: Linux Ubuntu 24.03
  • Ruby version: 3.2.3
  • TTY::Reader version: github head

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions