From e88a5319454c4981cb7ef1ca9992bcabb12bdc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20B=C3=BCsch?= Date: Sat, 13 Jan 2024 11:24:14 +1100 Subject: [PATCH] Fix `commandline --cursor-end` (#11504) # Description In `commandline --cursor-end`, set `repl.cursor_pos` to the number of bytes in the buffer, not the number of graphemes. fixes: #11503 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-cli/src/commands/commandline.rs | 2 +- src/tests/test_commandline.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/commands/commandline.rs b/crates/nu-cli/src/commands/commandline.rs index 4c39d10e44..52b8020632 100644 --- a/crates/nu-cli/src/commands/commandline.rs +++ b/crates/nu-cli/src/commands/commandline.rs @@ -111,7 +111,7 @@ impl Command for Commandline { } else { let mut repl = engine_state.repl_state.lock().expect("repl state mutex"); if call.has_flag(engine_state, stack, "cursor-end")? { - repl.cursor_pos = repl.buffer.graphemes(true).count(); + repl.cursor_pos = repl.buffer.len(); Ok(Value::nothing(call.head).into_pipeline_data()) } else if call.has_flag(engine_state, stack, "cursor")? { let char_pos = repl diff --git a/src/tests/test_commandline.rs b/src/tests/test_commandline.rs index 169dde11c9..9f3eb07ed7 100644 --- a/src/tests/test_commandline.rs +++ b/src/tests/test_commandline.rs @@ -127,3 +127,11 @@ fn commandline_test_cursor_invalid() -> TestResult { r#"string "abc" does not represent a valid int"#, ) } + +#[test] +fn commandline_test_cursor_end() -> TestResult { + run_test( + "commandline --insert '🤔🤔'; commandline --cursor-end; commandline --cursor", + "2", // 2 graphemes + ) +}