From 89848ad7793ea4ed0c07ec19ea847db6dec6cc33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Tue, 16 Jan 2024 08:16:45 +0800 Subject: [PATCH] fix: renaming may cause a crash when encountering Unicode characters (#519) --- yazi-core/src/manager/commands/rename.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/yazi-core/src/manager/commands/rename.rs b/yazi-core/src/manager/commands/rename.rs index fd517127..41ede85a 100644 --- a/yazi-core/src/manager/commands/rename.rs +++ b/yazi-core/src/manager/commands/rename.rs @@ -64,7 +64,12 @@ impl Manager { let name = Self::empty_url_part(&hovered, opt.empty); let cursor = match opt.cursor { "start" => Some(0), - "before_ext" => name.rfind('.').filter(|&n| n != 0), + "before_ext" => name + .chars() + .rev() + .position(|c| c == '.') + .map(|i| name.chars().count() - i - 1) + .filter(|&i| i != 0), _ => None, };