summaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/cursor_move.rs19
-rw-r--r--src/commands/new_directory.rs6
-rw-r--r--src/commands/touch_file.rs6
3 files changed, 30 insertions, 1 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 1f6e5ff..2d7688f 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -1,5 +1,7 @@
+use std::path;
+
use crate::context::AppContext;
-use crate::error::AppResult;
+use crate::error::{AppError, AppErrorKind, AppResult};
use crate::ui::AppBackend;
pub fn lazy_load_directory_size(context: &mut AppContext) {
@@ -54,6 +56,21 @@ pub fn cursor_move(context: &mut AppContext, new_index: usize) {
}
}
+pub fn to_path(context: &mut AppContext, path: &path::Path) -> AppResult {
+ // This error should never happen
+ let err = || AppError::new(AppErrorKind::UnknownError, String::from("Unexpected error"));
+ let ui_context = context.ui_context_ref().clone();
+ let display_options = context.config_ref().display_options_ref().clone();
+ if let Some(curr_list) = context.tab_context_mut().curr_tab_mut().curr_list_mut() {
+ if let path::Component::Normal(name) = path.components().next().ok_or_else(err)? {
+ let index = curr_list.get_index_from_name(name.to_str().ok_or_else(err)?);
+ curr_list.set_index(index, &ui_context, &display_options);
+ }
+ }
+
+ Ok(())
+}
+
pub fn up(context: &mut AppContext, u: usize) -> AppResult {
let movement = context
.tab_context_ref()
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index ec9efd4..32b248e 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -1,5 +1,6 @@
use std::path;
+use crate::commands::cursor_move;
use crate::context::AppContext;
use crate::error::AppResult;
use crate::history::DirectoryHistory;
@@ -13,5 +14,10 @@ pub fn new_directory(context: &mut AppContext, p: &path::Path) -> AppResult {
tab.history_mut()
.reload(&curr_path, &options, &tab_options)?;
}
+
+ if context.config_ref().focus_on_create {
+ cursor_move::to_path(context, p)?;
+ }
+
Ok(())
}
diff --git a/src/commands/touch_file.rs b/src/commands/touch_file.rs
index 27249b1..f36beff 100644
--- a/src/commands/touch_file.rs
+++ b/src/commands/touch_file.rs
@@ -4,6 +4,7 @@ use std::time::SystemTime;
use filetime::FileTime;
+use crate::commands::cursor_move;
use crate::context::AppContext;
use crate::error::AppResult;
use crate::history::create_dirlist_with_history;
@@ -58,5 +59,10 @@ pub fn touch_file(context: &mut AppContext, arg: &str) -> AppResult {
create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
+
+ if context.config_ref().focus_on_create {
+ cursor_move::to_path(context, path::Path::new(arg))?;
+ }
+
Ok(())
}