Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable blame and history popup for untracked files #2489

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 58 additions & 27 deletions src/components/status_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,27 @@ impl Component for StatusTreeComponent {
out: &mut Vec<CommandInfo>,
force_all: bool,
) -> CommandBlocking {
let available = self.focused || force_all;
let selection = self.selection_file();
let selected_is_file = selection.is_some();
let tracked = selection.is_some_and(|s| {
!matches!(s.status, StatusItemType::New)
});

out.push(
CommandInfo::new(
strings::commands::navigate_tree(&self.key_config),
!self.is_empty(),
self.focused || force_all,
available,
)
.order(order::NAV),
);

out.push(
CommandInfo::new(
strings::commands::blame_file(&self.key_config),
self.selection_file().is_some(),
self.focused || force_all,
selected_is_file && tracked,
available,
)
.order(order::RARE_ACTION),
);
Expand All @@ -417,61 +424,85 @@ impl Component for StatusTreeComponent {
strings::commands::open_file_history(
&self.key_config,
),
self.selection_file().is_some(),
self.focused || force_all,
selected_is_file && tracked,
available,
)
.order(order::RARE_ACTION),
);

out.push(
CommandInfo::new(
strings::commands::edit_item(&self.key_config),
self.selection_file().is_some(),
self.focused || force_all,
selected_is_file,
available,
)
.order(order::RARE_ACTION),
);

out.push(
CommandInfo::new(
strings::commands::copy_path(&self.key_config),
self.selection_file().is_some(),
self.focused || force_all,
selected_is_file,
available,
)
.order(order::RARE_ACTION),
);

CommandBlocking::PassingOn
}

#[expect(clippy::cognitive_complexity)]
fn event(&mut self, ev: &Event) -> Result<EventState> {
if self.focused {
if let Event::Key(e) = ev {
return if key_match(e, self.key_config.keys.blame) {
if let Some(status_item) = self.selection_file() {
self.hide();
self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::BlameFile(
BlameFileOpen {
file_path: status_item.path,
commit_id: self.revision,
selection: None,
},
),
));
match self.selection_file() {
Some(status_item)
if !matches!(
status_item.status,
StatusItemType::New
) =>
{
self.hide();
self.queue.push(
InternalEvent::OpenPopup(
StackablePopupOpen::BlameFile(
BlameFileOpen {
file_path: status_item
.path,
commit_id: self.revision,
selection: None,
},
),
),
);
}
_ => {}
}
Ok(EventState::Consumed)
} else if key_match(
e,
self.key_config.keys.file_history,
) {
if let Some(status_item) = self.selection_file() {
self.hide();
self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::FileRevlog(
FileRevOpen::new(status_item.path),
),
));
match self.selection_file() {
Some(status_item)
if !matches!(
status_item.status,
StatusItemType::New
) =>
{
self.hide();
self.queue.push(
InternalEvent::OpenPopup(
StackablePopupOpen::FileRevlog(
FileRevOpen::new(
status_item.path,
),
),
),
);
}
_ => {}
}
Ok(EventState::Consumed)
} else if key_match(e, self.key_config.keys.edit_file)
Expand Down