summaryrefslogtreecommitdiffstats
path: root/src/tab.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-10-22 23:15:31 +0200
committerqkzk <qu3nt1n@gmail.com>2023-10-22 23:15:31 +0200
commit920adf620455274bee7b7e39c46223c44749a825 (patch)
treed1d314e72690f9b8b96213e2c705aaf365e9ce5e /src/tab.rs
parent22ee632f9da1cd7a3f535abafe09256f4bd401bf (diff)
Move cursor 1 char right in input. Use unicode segmentation when replacing input
Diffstat (limited to 'src/tab.rs')
-rw-r--r--src/tab.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/tab.rs b/src/tab.rs
index 064412e..0fe3eb3 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -12,12 +12,12 @@ use crate::fileinfo::{FileInfo, FileKind, PathContent};
use crate::filter::FilterKind;
use crate::history::History;
use crate::input::Input;
-use crate::mode::Mode;
+use crate::mode::{InputSimple, Mode};
use crate::opener::execute_in_child;
use crate::preview::{Directory, Preview};
use crate::selectable_content::SelectableContent;
use crate::shortcut::Shortcut;
-use crate::utils::{row_to_window_index, set_clipboard};
+use crate::utils::{filename_from_path, row_to_window_index, set_clipboard};
/// Holds every thing about the current tab of the application.
/// Most of the mutation is done externally.
@@ -707,4 +707,23 @@ impl Tab {
execute_in_child(command, &args)?;
Ok(true)
}
+
+ pub fn rename(&mut self) -> Result<()> {
+ if self.selected().is_some() {
+ let old_name = match self.mode {
+ Mode::Tree => self.directory.tree.current_node.filename(),
+ _ => filename_from_path(
+ &self
+ .path_content
+ .selected()
+ .context("Event rename: no file in current directory")?
+ .path,
+ )?
+ .to_owned(),
+ };
+ self.input.replace(&old_name);
+ self.set_mode(Mode::InputSimple(InputSimple::Rename));
+ }
+ Ok(())
+ }
}