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

Fix history navigation in vi_insert mode #55

Merged
merged 2 commits into from
Sep 15, 2019

Conversation

acammack-r7
Copy link
Contributor

Previously, :vi_insert mode did not match any of the cursor-reset cases when navigating history. This could allow the cursor to go passed the end of the line, for example when going to a previous line, moving the cursor, and then going back to the current empty line. Trying to move the cursor left or right afterwards results in an exception. I couldn't get the arrow key codes working in the tests or I would have added one like:

  def test_insert_mode_history
    Reline::HISTORY.concat(%w{abcd 123 AAA})
    assert_line('')
    assert_byte_pointer_size('')
    assert_cursor(0)
    assert_cursor_max(0)
    input_keys("\C-[[A")
    assert_line('AAA')
    assert_byte_pointer_size('')
    assert_cursor(3)
    assert_cursor_max(3)
    input_keys("\C-[[A\C-[[A")
    assert_line('abc')
    assert_byte_pointer_size('')
    assert_cursor(4)
    assert_cursor_max(4)
    input_keys("\C-[[B")
    assert_line('123')
    assert_byte_pointer_size('')
    assert_cursor(3)
    assert_cursor_max(3)
    input_keys("\C-[[D\C-[[B\C-[[B")
    assert_line('')
    assert_byte_pointer_size('')
    assert_cursor(0)
    assert_cursor_max(0)
  end

Unverified

The committer email address is not verified.
Copy link
Member

@aycabta aycabta left a comment

Choose a reason for hiding this comment

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

Good catch! I want to merge it, but I think ed_prev_history should be changed too. I'll merge this after you add it.

After I merged, I'll add a test for the new behaviors.

Unverified

The committer email address is not verified.
@acammack-r7
Copy link
Contributor Author

Good point! I have added the check to ed_prev_history.

@acammack-r7 acammack-r7 requested a review from aycabta September 13, 2019 21:08
@aycabta aycabta merged commit f4e7e40 into ruby:master Sep 15, 2019
@aycabta
Copy link
Member

aycabta commented Sep 15, 2019

Thank you!

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.

None yet

2 participants