kakoune: [BUG] Backspace occasionally behaves like Delete

Version of Kakoune

v2023.08.05

Reproducer

I’m using kitty, version 0.33.1

Might have something to do with suspending and resuming (<c-z>). It does not happen in a client that has never been suspended.

Outcome

Occasionally backspace would show up as delete in the debug buffer (when the debug option has the keys flag) and behave as delete rather than backspace in any mode. The behaviour is present within anything done via this client. A typed <c-h> turns out to not be received. Any other client connected to the same server is unaffected. When I suspend the client and type something in the shell, the backspace key works.

Expectations

required text

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 24 (17 by maintainers)

Commits related to this issue

Most upvoted comments

@krobelus , will you open a PR for this fix?

BTW: @Abraxas-Knister , could you verify if this works for you too?

weird. Maybe print the address of m_original_termios, maybe it changes for some reason. If that (or a spurious copy) is the problem, the fix might be:

diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc
index ca512ef89..d59073b9d 100644
--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -705,7 +705,7 @@ Optional<Key> TerminalUI::get_next_key()
 
     static constexpr auto control = [](char c) { return c & 037; };
 
-    static auto convert = [this](Codepoint c) -> Codepoint {
+    auto convert = [this](Codepoint c) -> Codepoint {
         if (c == control('m') or c == control('j'))
             return Key::Return;
         if (c == control('i'))
@@ -720,7 +720,7 @@ Optional<Key> TerminalUI::get_next_key()
             return Key::Escape;
         return c;
     };
-    static auto parse_key = [](unsigned char c) -> Key {
+    auto parse_key = [&convert](unsigned char c) -> Key {
         if (Codepoint cp = convert(c); cp > 255)
             return Key{cp};
         // Special case: you can type NUL with Ctrl-2 or Ctrl-Shift-2 or
@@ -759,7 +759,7 @@ Optional<Key> TerminalUI::get_next_key()
         return mod;
     };
 
-    auto parse_csi = [this]() -> Optional<Key> {
+    auto parse_csi = [this, &convert]() -> Optional<Key> {
         auto next_char = [] { return get_char().value_or((unsigned char)0xff); };
         int params[16][4] = {};
         auto c = next_char();

@krobelus , you are correct, c_cc[VERASE] was changed to 0 somehow. I made below patch, the two places have different c_cc[VERASE] values.

diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc
index 3ad95e40..99f38809 100644
--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -700,6 +700,7 @@ Optional<Key> TerminalUI::get_next_key()
     if (not c)
         return {};
 
+    write_to_debug_buffer(format("1 c: {} VERASE: {}", *c, m_original_termios.c_cc[VERASE]));
     static constexpr auto control = [](char c) { return c & 037; };
 
     static auto convert = [this](Codepoint c) -> Codepoint {
@@ -709,6 +710,7 @@ Optional<Key> TerminalUI::get_next_key()
             return Key::Tab;
         if (c == ' ')
             return Key::Space;
+        write_to_debug_buffer(format("c: {} VERASE: {}", c, m_original_termios.c_cc[VERASE]));
         if (c == m_original_termios.c_cc[VERASE])
             return Key::Backspace;
         if (c == 127) // when it's not backspace

is it possible that it’s related with some copy or clone in c++?

did you try write_to_debug_buffer as explained in https://github.com/mawww/kakoune/issues/5155#issuecomment-2076586109 ?