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

Insert mode MotionRight can't reach end of line? #69

Closed
meshula opened this issue May 13, 2021 · 1 comment
Closed

Insert mode MotionRight can't reach end of line? #69

meshula opened this issue May 13, 2021 · 1 comment

Comments

@meshula
Copy link

meshula commented May 13, 2021

Describe the bug

can't move cursor to end of line in insert mode, cursor sticks prior to end of line instead of moving to end of line

To Reproduce

enter insert mode, enter text 1234. press escape to enter normal mode. move cursor left and right. It works as expected; i.e. 12[3]4 when moving left, 123[4] when moving right. Pressing right again does nothing.

enter insert mode with cursor on 4. Per vim usual the result is 123|4. Cursor left is 12|34, cursor right is 123|4. A further cursor right stays at 123|4

Expected behavior

a further cursor right in insert mode yields 1234| further right arrows stay at the end of the line

If I make the following patch, insert mode allows the cursor to move to the end of the line, but also allows the cursor to wrap to the next line, so not the same as vim. I was wondering if this rings any bells? I'm not sure what I might be doing wrong. I tried other solutions, but they had side effects, like allowing the cursor in normal mode to go beyond the end of the line. I started to think maybe there needs to be MotionInsertRight to exactly implement a vim behavior; at which point I thought I must be doing something wrong...

--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -2491,10 +2491,10 @@ void ZepMode::AddNavigationKeyMaps(bool allowInVisualMode)
     keymap_add(navigationMaps, { "<C-h>" }, id_MotionLeftSplit);

     // Arrows always navigate in insert mode
-    keymap_add({ &m_insertMap }, { "<Down>" }, id_MotionDown);
-    keymap_add({ &m_insertMap }, { "<Up>" }, id_MotionUp);
-    keymap_add({ &m_insertMap }, { "<Right>" }, id_MotionRight);
-    keymap_add({ &m_insertMap }, { "<Left>" }, id_MotionLeft);
+    keymap_add({ &m_insertMap }, { "<Down>" }, id_MotionStandardDown);
+    keymap_add({ &m_insertMap }, { "<Up>" }, id_MotionStandardUp);
+    keymap_add({ &m_insertMap }, { "<Right>" }, id_MotionStandardRight);
+    keymap_add({ &m_insertMap }, { "<Left>" }, id_MotionStandardLeft);
 }

 void ZepMode::AddSearchKeyMaps()

My key handler is very straightforward, basically lifted straight from the sample, I assume I'm using it correctly? I'm not sure where else to look for a bug in my code. I have verified that zep is definitely in insert mode, and it's definitely invoking MotionRight, so I'm feeling a bit stuck at the moment. MotionStandardRight lets me get to the end of the line for now, but I'd like to know where I've gone off the rails...

    // returns true if the event was consumed
    bool HandleKeyInput(const ZepBuffer& buffer,
        uint32_t key, bool ctrl, bool shift)
    {
        bool handled = false;
        uint32_t mod = (ctrl ? Zep::ModifierKey::Ctrl : 0) |
                       (shift ? Zep::ModifierKey::Shift : 0);

        switch (key)
        {
        case Zep::ExtKeys::TAB:
        case Zep::ExtKeys::ESCAPE:
        case Zep::ExtKeys::RETURN:
        case Zep::ExtKeys::DEL:
        case Zep::ExtKeys::HOME:
        case Zep::ExtKeys::END:
        case Zep::ExtKeys::BACKSPACE:
        case Zep::ExtKeys::RIGHT:
        case Zep::ExtKeys::LEFT:
        case Zep::ExtKeys::UP:
        case Zep::ExtKeys::DOWN:
        case Zep::ExtKeys::PAGEDOWN:
        case Zep::ExtKeys::PAGEUP:
            buffer.GetMode()->AddKeyPress(key, mod);
            return true;
        }

        if (ctrl)
        {
            if (key == '1')
            {
                SetGlobalMode(ZepMode_Standard::StaticName());
                handled = true;
            }
            else if (key == '2')
            {
                SetGlobalMode(ZepMode_Vim::StaticName());
                handled = true;
            }
            else if (key >= 'A' && key <= 'Z')
            {
                buffer.GetMode()->AddKeyPress(key - 'A' + 'a', mod);
                handled = true;
            }
            else if (key == ' ')
            {
                buffer.GetMode()->AddKeyPress(' ', mod);
                handled = true;
            }
        }

        if (!handled)
        {
            handled = true;
            if (key != '\r')
            {
                buffer.GetMode()->AddKeyPress(key, mod);
            }
        }

        return handled;
    }
@meshula
Copy link
Author

meshula commented May 24, 2021

Ah, bug at my end. I have not properly initialized Vim Mode.

@meshula meshula closed this as completed May 24, 2021
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

No branches or pull requests

1 participant