diff options
author | Canop <cano.petrole@gmail.com> | 2020-09-27 16:32:04 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-09-27 16:32:04 +0200 |
commit | 59b8f5174505bef2cb96ad1c3a67010c03131f83 (patch) | |
tree | 00ba319b59b645a50d6dc0d7781b5de5fcb84b3d /src/browser/browser_state.rs | |
parent | a2ecff8d1ec2b983d2794586b11becdc9defa47c (diff) |
fix opening of link of link
Fix #280
Diffstat (limited to 'src/browser/browser_state.rs')
-rw-r--r-- | src/browser/browser_state.rs | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index 591d2d6..a94ed7c 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -108,46 +108,37 @@ impl BrowserState { ) -> Result<AppStateCmdResult, ProgramError> { let tree = self.displayed_tree(); let line = tree.selected_line(); - match &line.line_type { - TreeLineType::File => match open::that(&line.path) { + let mut target = line.target().to_path_buf(); + if line.is_dir() { + if tree.selection == 0 { + // opening the root would be going to where we already are. + // We go up one level instead + if let Some(parent) = target.parent() { + target = PathBuf::from(parent); + } + } + let dam = Dam::unlimited(); + Ok(AppStateCmdResult::from_optional_state( + BrowserState::new( + target, + if keep_pattern { + tree.options.clone() + } else { + tree.options.without_pattern() + }, + screen, + con, + &dam, + ), + in_new_panel, + )) + } else { + match open::that(&target) { Ok(exit_status) => { info!("open returned with exit_status {:?}", exit_status); Ok(AppStateCmdResult::Keep) } Err(e) => Ok(AppStateCmdResult::DisplayError(format!("{:?}", e))), - }, - TreeLineType::Dir | TreeLineType::SymLinkToDir(_) => { - let mut target = line.target(); - if tree.selection == 0 { - // opening the root would be going to where we already are. - // We go up one level instead - if let Some(parent) = target.parent() { - target = PathBuf::from(parent); - } - } - let dam = Dam::unlimited(); - Ok(AppStateCmdResult::from_optional_state( - BrowserState::new( - target, - if keep_pattern { - tree.options.clone() - } else { - tree.options.without_pattern() - }, - screen, - con, - &dam, - ), - in_new_panel, - )) - } - TreeLineType::SymLinkToFile(target) => { - let path = PathBuf::from(target); - open::that(&path)?; - Ok(AppStateCmdResult::Keep) - } - _ => { - unreachable!(); } } } |