Skip to content

Change quoted_insert and bracketed_paste to a single key input - #792

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
tompng:quoted_insert_bracketed_paste_insert
Dec 16, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
tompng:quoted_insert_bracketed_paste_insert

Conversation

@tompng

@tompng tompng commented Dec 9, 2024 •

Copy link
Copy Markdown
Member

Bracketed paste will be changed to Reline::Key.new(pasted_content, :insert_multiline_text).
This will simplify handling undo/redo of bracketed paste.

Quoted insert will be changed to Reline::Key.new(char_to_be_inserted, :insert_raw_char).
def ed_quoted_insert(renamed to insert_raw_char) does not need to use waiting_proc anymore.

Comment thread lib/reline/line_editor.rb
method_obj = method(method_symbol)
end
if @vi_arg
if key.match?(/\A\d\z/)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change in this pull request, inserting number with quoted_insert(\C-v9) and bracketed paste(\e[200~9\e[201~) has key="9" that wrongly match to /\A\d\z/.
We need to use method_symbol instead of this regexp.

Comment thread lib/reline.rb
Comment on lines +347 to +349
when :bracketed_paste_start
key = Reline::Key.new(io_gate.read_bracketed_paste, :insert_multiline_text)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 io_gate.read_bracketed_paste is defined only ansi.rb, so it cannot be invoked on Windows or other unsupported environments. But :bracketed_paste_start is also defined only ansi.rb, this code will never be reached on Windows or other environments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I added a comment about it

Comment on lines +141 to +146
def test_bracketed_paste_insert
input_keys("d\C-aa")
input_key_by_symbol(:insert_multiline_text, char: "abc\n\C-abc")
assert_line_around_cursor("\C-abc", 'd')
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why does this code serve as a test for bracketed_paste_insert?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_key_actor_emacs.rg is testing the behavior of LineEditor with key input mainly registered by key_actor/emacs.rb.
Bracketed paste (start_escape_sequence, content, end_escape_sequence) is converted into Key.new(content, :insert_multiline_text) in reline and passed to LineEditor.
As a test for LineEditor, we need to input this key to LineEditor.

Test of handling "\e[200~content\e[201~" is done in test_rendering.rb

I also added small tweak to the test:

input_keys("d\C-aa")
# ↓
set_line_around_cursor('a', 'd') # (and change it to 'A', 'Z')

@tompng
tompng force-pushed the quoted_insert_bracketed_paste_insert branch from 1d3b6bd to 0dc0109 Compare December 15, 2024 13:40

@ima1zumi ima1zumi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ima1zumi
ima1zumi merged commit 8f331ed into ruby:master Dec 16, 2024
@tompng
tompng deleted the quoted_insert_bracketed_paste_insert branch December 16, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants