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

Improve replace mode #14

Merged
merged 6 commits into from May 5, 2018
Merged

Improve replace mode #14

merged 6 commits into from May 5, 2018

Conversation

elpinal
Copy link
Contributor

@elpinal elpinal commented Apr 28, 2018

  1. Now the replace-byte command (r) only replace 1 byte.
  2. r command does nothing for empty windows.
  3. In replace mode backspace does not delete original text.

But there are some issues:

  1. Panic (integer divide by zero) occurs when interleaved with x command.
  2. It is not trivial to determine what should happen when moving a cursor by arrow keys in replace mode.

I guess Buffer.Replace should increment the length when offset for replacing equals length so that in buffer/buffer_test.go, TestBufferReplace's last 3 test cases should set len to 17.

bed/buffer/buffer_test.go

Lines 400 to 402 in 517e02f

{16, 0x31, 9, "9abcdef1", 16},
{15, 0x30, 9, "9abcde01", 16},
{2, 0x39, 0, "87901067", 16},

Related to #12.

* Add a replaceBuf field into the `window` struct to represent
  a "pending" (or yet-to-be-committed) replace buffer.
* Editing bytes in replace mode addresses the pending replace buffer
  instead of treating window.buffer directly.
* When users exit from replace mode, the pending replace buffer is
  "committed" to window.buffer.
* window.state pretends that the pending replace buffer is committed
  by modifying Bytes and Length of WindowState.
@itchyny
Copy link
Owner

itchyny commented Apr 29, 2018

Great, thanks. I'll work on in a few days.

@itchyny itchyny mentioned this pull request May 2, 2018
@itchyny itchyny merged commit 7978571 into itchyny:master May 5, 2018
@itchyny
Copy link
Owner

itchyny commented May 5, 2018

Merged with commits in #15. After all I implemented the temporary bytes in Buffer but I respect your contribution. If there're still some bug (especially panic crash) in the master branch, please let me know. Thanks.

@elpinal
Copy link
Contributor Author

elpinal commented May 7, 2018

Great job 👍 Hooray!

@elpinal elpinal deleted the improve-replace branch May 7, 2018 08:11
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.

None yet

2 participants