diff options
author | Kyohei Uto <im@kyoheiu.dev> | 2024-01-20 06:12:35 +0900 |
---|---|---|
committer | Kyohei Uto <im@kyoheiu.dev> | 2024-01-20 06:12:35 +0900 |
commit | b4458b523605cfd06c04adb7ce16b9f1b7032a1d (patch) | |
tree | 368be8be7fc5dd077d3edb51c0a65ecd5e5df423 | |
parent | b2b97ff56216bfae6c524f40363c4d98745798ae (diff) |
Add linewise choosefiles optionfeature-filechooser
-rw-r--r-- | src/run.rs | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -478,19 +478,49 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { //Open file or change directory KeyCode::Char('l') | KeyCode::Enter | KeyCode::Right => { - //In visual mode, this is disabled. + //In visual mode, if not with the choosefiles option, this is disabled. if state.v_start.is_some() { - continue; + if let Some(target_path) = &state.choosefiles_target { + match std::fs::File::options() + .write(true) + .truncate(true) + .create(true) + .open(target_path) + { + Err(e) => print_warning(e, state.layout.y), + Ok(mut f) => { + let items: Vec<&str> = state + .list + .iter() + .filter(|item| item.selected) + .filter_map(|item| { + item.file_path.as_os_str().to_str() + }) + .collect(); + let file_names = &items.join("\n"); + + if let Err(e) = writeln!(&mut f, "{}", file_names) { + print_warning(e, state.layout.y); + } else { + break 'main; + } + } + } + continue; + } else { + continue; + } } let mut dest: Option<PathBuf> = None; if let Ok(item) = state.get_item() { match item.file_type { FileType::File => { - // choosefiles mode appends the file path + // with choosefiles option, writes the file path // to the target file if let Some(target_path) = &state.choosefiles_target { match std::fs::File::options() - .append(true) + .write(true) + .truncate(true) .create(true) .open(target_path) { |