feat(vi): support deleting chars backward with X#1067
Conversation
|
Parser side looks right. One correctness issue:
Two editor-level tests would be also good, for pos 0 in single line and start of line 2 in multi-line. If you got that I would be fine to land it. |
|
OK. I got that. Now another thing I just realized with my current implementation is that Do you agree with this addition? |
* Mapping EditorCommand::CutCharLeft to new Editor::cut_char_left with appropriate guard against cutting left of the beginning of a line. * 2 tests cases for beginning of lines with single and multi-line strings.
Verify that X in visual mode cuts entire lines covered by the selection, matching Vim behavior for single-line, multi-line, and spanning selections.
|
@kronberger-droid: I did the addition for visual selection behaviour for |
|
Hmm do you think you have to define a new edit command to achieve the guard? Thanks for the effort! |
|
The issue is that neither I see a few options:
Which approach would you prefer? |
|
Thanks for the rundown. Also I think if you want to make 3X work you will have to use something like option 1 or making MoveLeft guarding anyways right? I am now working on an idea for much stronger primitives in EditCommand which will make these types of problems much easier to handle. But until then for me its just important to be sure about the intent of an EditCommand so its easy to replace them if we have stronger primitives. Until then I am fine with what works best for count prefixes (3X etc.) Still important to have a more complete version as a baseline. Thanks! |
|
Based on your feedback, I'll switch to option 1: adding Note that The remaining open question is visual mode: |
|
Hmm I would avoid a view of the editor in the modes. (against what I mentioned in #960) If you want you can propose a followup to fix the register behavior for multiple actions, but I a can't promise I will merge it, since it seems without some better primitives this will be just hacky. It would be nice to still add tests for the expected behavior we can't implement right now and skip them. |
|
EDIT: This is irrelevant if we keep |
|
After trying the implementation for |
Do I understand that correctly that you would then stay with this implementation? Just tell me when I should take a closer look. |
|
Yes, that is correct. I think that until the better primitives you are working on are integrated, we cannot do without a new primitive |
Summary
Add support for the
Xcommand in vi normal mode, which deletes the character before the cursor and places it in the cut buffer, mirroring the behavior ofXin vim.This partially addresses #621.
Changes
XasCommand::DeleteCharBackwardin the vi command parserMoveLeft+CutCharto delete the character before the cursor and place it in the cut bufferCutSelection(consistent withxbehavior)Xand2XKnown limitation
When used with a multiplier (e.g.
3X), each character is cut individually, so only the last deleted character remains in the cut buffer. This is a pre-existing limitation shared withxand will be addressed in a follow-up PR.