From 977b97a23616fdbed97314eea7729b06c1f42563 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 21 Jan 2024 23:10:01 -0600 Subject: [PATCH] Fix assertion failure in FZF keybindings It seems the logic for calculating the cursor position was not ported correctly, because the correct place to insert it is at the cursor_pos regardless of range.start, going by the parameters submitted to the function and the expected result. --- src/builtins/commandline.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index f826ecda4..a5011d12a 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -54,7 +54,6 @@ fn replace_part( cursor_pos: usize, ) { let mut out_pos = cursor_pos; - let mut out = buff[..range.start].to_owned(); match insert_mode { @@ -67,11 +66,11 @@ fn replace_part( out.push_utfstr(insert); } AppendMode::Insert => { - let cursor = cursor_pos - range.start; - assert!(range.start <= cursor); - out.push_utfstr(&buff[range.start..cursor]); + assert!(cursor_pos >= range.start); + assert!(cursor_pos <= range.end); + out.push_utfstr(&buff[range.start..cursor_pos]); out.push_utfstr(&insert); - out.push_utfstr(&buff[cursor..range.end]); + out.push_utfstr(&buff[cursor_pos..range.end]); out_pos += insert.len(); } }