From efc13b4148d1d01b28efd54118e3666b018cfc03 Mon Sep 17 00:00:00 2001 From: Kyohei Uto Date: Sun, 28 Jan 2024 06:22:15 +0900 Subject: [PATCH] Add insertion from register to rename mode --- src/run.rs | 67 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/src/run.rs b/src/run.rs index 4e49053..14030e4 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1258,30 +1258,53 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { }) = event::read()? { match (code, modifiers) { - //rename item - (KeyCode::Enter, KeyModifiers::NONE) => { - let rename = rename.iter().collect::(); - let mut to = state.current_dir.clone(); - to.push(rename); - if let Err(e) = - std::fs::rename(&item.file_path, &to) + // to put the item name(s) from register + (KeyCode::Char('r'), KeyModifiers::CONTROL) => { + if let Event::Key(KeyEvent { + code, + kind: KeyEventKind::Press, + .. + }) = event::read()? { - hide_cursor(); - print_warning(e, state.layout.y); - break; + if let Some(reg) = + state.registers.check_reg(&code) + { + if !reg.is_empty() { + let to_be_inserted = reg + .iter() + .map(|x| x.file_name.clone()) + .collect::>() + .join(" "); + for c in to_be_inserted.chars() { + if let Some(to_be_added) = + unicode_width::UnicodeWidthChar::width(c) + { + if current_pos + to_be_added as u16 + > state.layout.terminal_column + { + continue; + } + rename.insert(current_char_pos, c); + current_char_pos += 1; + current_pos += to_be_added as u16; + } + } + go_to_info_line_and_reset(); + print!( + "{}{}", + PROMPT_RENAME, + &rename.iter().collect::() + ); + move_to(current_pos + 1, 2); + screen.flush()?; + continue; + } else { + continue; + } + } else { + continue; + } } - - state.operations.branch(); - state.operations.push(OpKind::Rename( - RenamedFile { - original_name: item.file_path.clone(), - new_name: to, - }, - )); - - hide_cursor(); - state.reload(state.layout.y)?; - break; } (KeyCode::Esc, KeyModifiers::NONE) => {