From f1e88d95c14000a1dcdb4f446e06023decb6cb21 Mon Sep 17 00:00:00 2001 From: nibon7 Date: Mon, 14 Aug 2023 18:58:39 +0800 Subject: [PATCH] Fix a crash when moving the cursor after accepting a suggestion from the help menu (#9784) # Description Fixes #9627 Related nushell/reedline#602 nushell/reedline#612 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-cli/src/menus/description_menu.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/menus/description_menu.rs b/crates/nu-cli/src/menus/description_menu.rs index 5f7434bb0c..26db0afb7e 100644 --- a/crates/nu-cli/src/menus/description_menu.rs +++ b/crates/nu-cli/src/menus/description_menu.rs @@ -646,7 +646,10 @@ impl Menu for DescriptionMenu { |lb| { lb.replace_range(start..end, replacement); let mut offset = lb.insertion_point(); - offset += lb.len().saturating_sub(end.saturating_sub(start)); + offset += lb + .len() + .saturating_sub(end.saturating_sub(start)) + .saturating_sub(start); lb.set_insertion_point(offset); }, UndoBehavior::CreateUndoPoint,