git: New enter behaviour (#25986)
Closes #25951 Release Notes: - git: Update "enter" in the list of changed files to preserve focus. If you want the old behaviour, hit enter twice. - git: Follow the cursor, not the scroll anchor, in the list. Although the scroll anchor was nice for passive scrolling, it broke if you had changed the overflow scroll settings.
This commit is contained in:
parent
ffe2bed1e2
commit
1086b282b8
3 changed files with 49 additions and 24 deletions
|
@ -2722,7 +2722,10 @@ impl EditorElement {
|
||||||
.shadow_md()
|
.shadow_md()
|
||||||
.border_1()
|
.border_1()
|
||||||
.map(|div| {
|
.map(|div| {
|
||||||
let border_color = if is_selected && is_folded {
|
let border_color = if is_selected
|
||||||
|
&& is_folded
|
||||||
|
&& focus_handle.contains_focused(window, cx)
|
||||||
|
{
|
||||||
colors.border_focused
|
colors.border_focused
|
||||||
} else {
|
} else {
|
||||||
colors.border
|
colors.border
|
||||||
|
|
|
@ -709,12 +709,31 @@ impl GitPanel {
|
||||||
fn open_diff(&mut self, _: &menu::Confirm, window: &mut Window, cx: &mut Context<Self>) {
|
fn open_diff(&mut self, _: &menu::Confirm, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
maybe!({
|
maybe!({
|
||||||
let entry = self.entries.get(self.selected_entry?)?.status_entry()?;
|
let entry = self.entries.get(self.selected_entry?)?.status_entry()?;
|
||||||
|
let workspace = self.workspace.upgrade()?;
|
||||||
|
let git_repo = self.active_repository.as_ref()?;
|
||||||
|
|
||||||
|
if let Some(project_diff) = workspace.read(cx).active_item_as::<ProjectDiff>(cx) {
|
||||||
|
if let Some(project_path) = project_diff.read(cx).active_path(cx) {
|
||||||
|
if Some(&entry.repo_path)
|
||||||
|
== git_repo
|
||||||
|
.read(cx)
|
||||||
|
.project_path_to_repo_path(&project_path)
|
||||||
|
.as_ref()
|
||||||
|
{
|
||||||
|
project_diff.focus_handle(cx).focus(window);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
self.workspace
|
self.workspace
|
||||||
.update(cx, |workspace, cx| {
|
.update(cx, |workspace, cx| {
|
||||||
ProjectDiff::deploy_at(workspace, Some(entry.clone()), window, cx);
|
ProjectDiff::deploy_at(workspace, Some(entry.clone()), window, cx);
|
||||||
})
|
})
|
||||||
.ok()
|
.ok();
|
||||||
|
self.focus_handle.focus(window);
|
||||||
|
|
||||||
|
Some(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2456,7 +2475,7 @@ impl GitPanel {
|
||||||
ix: usize,
|
ix: usize,
|
||||||
entry: &GitStatusEntry,
|
entry: &GitStatusEntry,
|
||||||
has_write_access: bool,
|
has_write_access: bool,
|
||||||
_: &Window,
|
window: &Window,
|
||||||
cx: &Context<Self>,
|
cx: &Context<Self>,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
let display_name = entry
|
let display_name = entry
|
||||||
|
@ -2548,6 +2567,10 @@ impl GitPanel {
|
||||||
.h(self.list_item_height())
|
.h(self.list_item_height())
|
||||||
.w_full()
|
.w_full()
|
||||||
.items_center()
|
.items_center()
|
||||||
|
.border_1()
|
||||||
|
.when(selected && self.focus_handle.is_focused(window), |el| {
|
||||||
|
el.border_color(cx.theme().colors().border_focused)
|
||||||
|
})
|
||||||
.px(rems(0.75)) // ~12px
|
.px(rems(0.75)) // ~12px
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.flex_none()
|
.flex_none()
|
||||||
|
@ -2563,6 +2586,7 @@ impl GitPanel {
|
||||||
this.open_file(&Default::default(), window, cx)
|
this.open_file(&Default::default(), window, cx)
|
||||||
} else {
|
} else {
|
||||||
this.open_diff(&Default::default(), window, cx);
|
this.open_diff(&Default::default(), window, cx);
|
||||||
|
this.focus_handle.focus(window);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@ use collections::HashSet;
|
||||||
use editor::{
|
use editor::{
|
||||||
actions::{GoToHunk, GoToPreviousHunk},
|
actions::{GoToHunk, GoToPreviousHunk},
|
||||||
scroll::Autoscroll,
|
scroll::Autoscroll,
|
||||||
Editor, EditorEvent, ToPoint,
|
Editor, EditorEvent,
|
||||||
};
|
};
|
||||||
use feature_flags::FeatureFlagViewExt;
|
use feature_flags::FeatureFlagViewExt;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
@ -192,6 +192,19 @@ impl ProjectDiff {
|
||||||
self.move_to_path(path_key, window, cx)
|
self.move_to_path(path_key, window, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn active_path(&self, cx: &App) -> Option<ProjectPath> {
|
||||||
|
let editor = self.editor.read(cx);
|
||||||
|
let position = editor.selections.newest_anchor().head();
|
||||||
|
let multi_buffer = editor.buffer().read(cx);
|
||||||
|
let (_, buffer, _) = multi_buffer.excerpt_containing(position, cx)?;
|
||||||
|
|
||||||
|
let file = buffer.read(cx).file()?;
|
||||||
|
Some(ProjectPath {
|
||||||
|
worktree_id: file.worktree_id(cx),
|
||||||
|
path: file.path().clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn move_to_path(&mut self, path_key: PathKey, window: &mut Window, cx: &mut Context<Self>) {
|
fn move_to_path(&mut self, path_key: PathKey, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if let Some(position) = self.multibuffer.read(cx).location_for_path(&path_key, cx) {
|
if let Some(position) = self.multibuffer.read(cx).location_for_path(&path_key, cx) {
|
||||||
self.editor.update(cx, |editor, cx| {
|
self.editor.update(cx, |editor, cx| {
|
||||||
|
@ -271,41 +284,26 @@ impl ProjectDiff {
|
||||||
|
|
||||||
fn handle_editor_event(
|
fn handle_editor_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
editor: &Entity<Editor>,
|
_: &Entity<Editor>,
|
||||||
event: &EditorEvent,
|
event: &EditorEvent,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
EditorEvent::ScrollPositionChanged { .. } => editor.update(cx, |editor, cx| {
|
EditorEvent::SelectionsChanged { local: true } => {
|
||||||
let anchor = editor.scroll_manager.anchor().anchor;
|
let Some(project_path) = self.active_path(cx) else {
|
||||||
let multibuffer = self.multibuffer.read(cx);
|
|
||||||
let snapshot = multibuffer.snapshot(cx);
|
|
||||||
let mut point = anchor.to_point(&snapshot);
|
|
||||||
point.row = (point.row + 1).min(snapshot.max_row().0);
|
|
||||||
point.column = 0;
|
|
||||||
|
|
||||||
let Some((_, buffer, _)) = self.multibuffer.read(cx).excerpt_containing(point, cx)
|
|
||||||
else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let Some(project_path) = buffer
|
|
||||||
.read(cx)
|
|
||||||
.file()
|
|
||||||
.map(|file| (file.worktree_id(cx), file.path().clone()))
|
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.workspace
|
self.workspace
|
||||||
.update(cx, |workspace, cx| {
|
.update(cx, |workspace, cx| {
|
||||||
if let Some(git_panel) = workspace.panel::<GitPanel>(cx) {
|
if let Some(git_panel) = workspace.panel::<GitPanel>(cx) {
|
||||||
git_panel.update(cx, |git_panel, cx| {
|
git_panel.update(cx, |git_panel, cx| {
|
||||||
git_panel.select_entry_by_path(project_path.into(), window, cx)
|
git_panel.select_entry_by_path(project_path, window, cx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}),
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue