Skip to content

Commit 4338ff6

Browse files
authored
terminal: Add ability to open file from Git diff (#17446)
- strip "a/" and "b/" prefix for potential paths. Release Notes: - Allow clicking on filepaths when using `git diff` inside the built-in terminal
1 parent 23e1faa commit 4338ff6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/terminal_view/src/terminal_view.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const REGEX_SPECIAL_CHARS: &[char] = &[
5858

5959
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
6060

61+
const GIT_DIFF_PATH_PREFIXES: &[char] = &['a', 'b'];
62+
6163
///Event to transmit the scroll from the element to the view
6264
#[derive(Clone, Debug, PartialEq)]
6365
pub struct ScrollTerminal(pub i32);
@@ -826,6 +828,19 @@ fn possible_open_targets(
826828
{
827829
potential_cwd_and_workspace_paths.insert(potential_worktree_path);
828830
}
831+
832+
for prefix in GIT_DIFF_PATH_PREFIXES {
833+
let prefix_str = &prefix.to_string();
834+
if maybe_path.starts_with(prefix_str) {
835+
let stripped = maybe_path.strip_prefix(prefix_str).unwrap_or(&maybe_path);
836+
for potential_worktree_path in workspace
837+
.worktrees(cx)
838+
.map(|worktree| worktree.read(cx).abs_path().join(&stripped))
839+
{
840+
potential_cwd_and_workspace_paths.insert(potential_worktree_path);
841+
}
842+
}
843+
}
829844
});
830845
}
831846

0 commit comments

Comments
 (0)