Repository navigation
Implement the undo command - #701
Merged
Merged
Conversation
ima1zumi
marked this pull request as ready for review
May 10, 2024 18:05
tompng
reviewed
May 11, 2024
| @resized = false | ||
| @cache = {} | ||
| @rendered_screen = RenderedScreen.new(base_y: 0, lines: [], cursor_y: 0) | ||
| @past_lines = [["", 0, 0]] |
Member
There was a problem hiding this comment.
maybe [[[""], 0, 0]].
IRB crash when first key input is undo.
tompng
reviewed
May 11, 2024
tompng
reviewed
May 11, 2024
tompng
reviewed
May 11, 2024
tompng
reviewed
May 13, 2024
| def save_past_lines | ||
| if @old_buffer_of_lines != @buffer_of_lines | ||
| if !@past_lines.empty? && @undoing | ||
| @past_lines.pop |
Member
There was a problem hiding this comment.
How about moving this step to def undo?
The current implementation looks like undo logic (== revert buffer_of_lines and revert past_lines) is separated into two parts.
In def input_key, this method can be used like this:
save_past_lines unless @undoing # or maybe rename it to push_past_lines
@undoing = false
Member
Author
There was a problem hiding this comment.
Sounds good! I've fixed it.
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
May 14, 2024
(ruby/reline#701) * Refactor send * Implement the undo command * Fix @past_lines initialization * Improve assertion * Hide to save buffer in insert_pasted_text * Replace @using_delete_command with @undoing * Refactor `@past_lines` ruby/reline@4ab72f9cbd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Implemented the undo method to enable undoing actions on a per-action basis.
Implementation Approach
Executing undo allows reverting to the previous action. The behavior slightly differs from GNU Readline's undo. While GNU Readline groups character insertions within a certain timeframe, I found this to be unintuitive. Inspired by Zsh Line Editor, I made it so that continuous character inputs can be undone one character at a time.
To decide whether to save an operation history, it was necessary to know whether the action was an insertion or a deletion, as the conditions for saving differ between the two. Hence, I added
DELETE_COMMANDS. Additionally, I refactored so that keys with anymethod_symbolwould pass throughwrap_method_call.