Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change quoted_insert and bracketed_paste to a single key input #792

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented Dec 9, 2024

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.

@@ -1004,7 +1005,7 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
method_obj = method(method_symbol)
end
if @vi_arg
if key.match?(/\A\d\z/)
Copy link
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.

lib/reline.rb Outdated
Comment on lines 347 to 349
when :bracketed_paste_start
key = Reline::Key.new(io_gate.read_bracketed_paste, :insert_multiline_text)
Copy link
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
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
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
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
Copy link
Member

@ima1zumi ima1zumi left a comment

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
40 checks passed
@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
Development

Successfully merging this pull request may close these issues.

2 participants