From 866585c6cec1e4fa5f81a6021701056cd770d522 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 7 Apr 2024 09:51:45 +0200 Subject: [PATCH] Fix accidental truncation of raw sequences For numpad 1 with nulock, Alacritty sends escape,[,5,7,4,0,0,u which is codepoint \x31, key "1". We have a terminfo mapping for "sright" which translates to escape,[,1,;,2,C The first two characters, escape and [ match. Then we accidentally match the "1" from the mapping against the entire sequence, because that sequence is canonicalized to codepoint "1" . The most blatant problem is that we discard the rest of the sequence. Fix that. This allows us to re-enable raw CSI u mappings like "bind \e[1u ..." which is what kitty uses for shell integration. --- src/input.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/input.rs b/src/input.rs index 116618f2b..bb6f9e2ea 100644 --- a/src/input.rs +++ b/src/input.rs @@ -616,6 +616,7 @@ fn new(event_queue: &mut Inputter) -> EventQueuePeeker { /// \return the next event. fn next(&mut self) -> CharEvent { + assert!(self.subidx == 0); assert!( self.idx <= self.peeked.len(), "Index must not be larger than dequeued event count" @@ -660,16 +661,12 @@ fn next_is_char(&mut self, key: Key, escaped: bool) -> bool { let Some(kevt) = evt.get_key() else { return false; }; - if kevt.key == key { + if self.subidx == 0 && kevt.key == key { self.idx += 1; - self.subidx = 0; return true; } let actual_seq = kevt.seq.as_char_slice(); - let is_csi_u = actual_seq.get(0) == Some(&'\x1b') - && actual_seq.get(1) == Some(&'[') - && actual_seq.last() == Some(&'u'); - if !actual_seq.is_empty() && !is_csi_u { + if !actual_seq.is_empty() { let seq_char = actual_seq[self.subidx]; if Key::from_single_char(seq_char) == key { self.subidx += 1;