Add workspace::ActivatePaneInDirection (#2757)
This change adds support for choosing a pane based on direction; and adds default keybindings (`cmd+k cmd+{left,right,up,down}`) and vim keybindings. Release Notes: - Add support for navigating to the next pane in a given direction using `cmd+k cmd-{up,down,left,right}` ([#476](https://github.com/zed-industries/community/issues/476), [#478](https://github.com/zed-industries/community/issues/478)) - Vim: adds support for many window related shortcuts: `ctrl-w {h,j,k,l,up,down,left,right,w,W,p}` for navigating around panes, `ctrl-w {q,c}` for closing panes and `ctrl-w {v,s}` for splitting panes.
This commit is contained in:
commit
372f66c88a
9 changed files with 243 additions and 8 deletions
|
@ -563,6 +563,7 @@ pub struct Editor {
|
|||
inlay_hint_cache: InlayHintCache,
|
||||
next_inlay_id: usize,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
pixel_position_of_newest_cursor: Option<Vector2F>,
|
||||
}
|
||||
|
||||
pub struct EditorSnapshot {
|
||||
|
@ -1394,6 +1395,7 @@ impl Editor {
|
|||
copilot_state: Default::default(),
|
||||
inlay_hint_cache: InlayHintCache::new(inlay_hint_settings),
|
||||
gutter_hovered: false,
|
||||
pixel_position_of_newest_cursor: None,
|
||||
_subscriptions: vec![
|
||||
cx.observe(&buffer, Self::on_buffer_changed),
|
||||
cx.subscribe(&buffer, Self::on_buffer_event),
|
||||
|
|
|
@ -61,6 +61,7 @@ enum FoldMarkers {}
|
|||
struct SelectionLayout {
|
||||
head: DisplayPoint,
|
||||
cursor_shape: CursorShape,
|
||||
is_newest: bool,
|
||||
range: Range<DisplayPoint>,
|
||||
}
|
||||
|
||||
|
@ -70,6 +71,7 @@ impl SelectionLayout {
|
|||
line_mode: bool,
|
||||
cursor_shape: CursorShape,
|
||||
map: &DisplaySnapshot,
|
||||
is_newest: bool,
|
||||
) -> Self {
|
||||
if line_mode {
|
||||
let selection = selection.map(|p| p.to_point(&map.buffer_snapshot));
|
||||
|
@ -77,6 +79,7 @@ impl SelectionLayout {
|
|||
Self {
|
||||
head: selection.head().to_display_point(map),
|
||||
cursor_shape,
|
||||
is_newest,
|
||||
range: point_range.start.to_display_point(map)
|
||||
..point_range.end.to_display_point(map),
|
||||
}
|
||||
|
@ -85,6 +88,7 @@ impl SelectionLayout {
|
|||
Self {
|
||||
head: selection.head(),
|
||||
cursor_shape,
|
||||
is_newest,
|
||||
range: selection.range(),
|
||||
}
|
||||
}
|
||||
|
@ -864,6 +868,12 @@ impl EditorElement {
|
|||
let x = cursor_character_x - scroll_left;
|
||||
let y = cursor_position.row() as f32 * layout.position_map.line_height
|
||||
- scroll_top;
|
||||
if selection.is_newest {
|
||||
editor.pixel_position_of_newest_cursor = Some(vec2f(
|
||||
bounds.origin_x() + x + block_width / 2.,
|
||||
bounds.origin_y() + y + layout.position_map.line_height / 2.,
|
||||
));
|
||||
}
|
||||
cursors.push(Cursor {
|
||||
color: selection_style.cursor,
|
||||
block_width,
|
||||
|
@ -2109,6 +2119,7 @@ impl Element<Editor> for EditorElement {
|
|||
line_mode,
|
||||
cursor_shape,
|
||||
&snapshot.display_snapshot,
|
||||
false,
|
||||
));
|
||||
}
|
||||
selections.extend(remote_selections);
|
||||
|
@ -2118,6 +2129,7 @@ impl Element<Editor> for EditorElement {
|
|||
.selections
|
||||
.disjoint_in_range(start_anchor..end_anchor, cx);
|
||||
local_selections.extend(editor.selections.pending(cx));
|
||||
let newest = editor.selections.newest(cx);
|
||||
for selection in &local_selections {
|
||||
let is_empty = selection.start == selection.end;
|
||||
let selection_start = snapshot.prev_line_boundary(selection.start).1;
|
||||
|
@ -2140,11 +2152,13 @@ impl Element<Editor> for EditorElement {
|
|||
local_selections
|
||||
.into_iter()
|
||||
.map(|selection| {
|
||||
let is_newest = selection == newest;
|
||||
SelectionLayout::new(
|
||||
selection,
|
||||
editor.selections.line_mode,
|
||||
editor.cursor_shape,
|
||||
&snapshot.display_snapshot,
|
||||
is_newest,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
|
|
|
@ -7,8 +7,10 @@ use anyhow::{Context, Result};
|
|||
use collections::HashSet;
|
||||
use futures::future::try_join_all;
|
||||
use gpui::{
|
||||
elements::*, geometry::vector::vec2f, AppContext, AsyncAppContext, Entity, ModelHandle,
|
||||
Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
elements::*,
|
||||
geometry::vector::{vec2f, Vector2F},
|
||||
AppContext, AsyncAppContext, Entity, ModelHandle, Subscription, Task, View, ViewContext,
|
||||
ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use language::{
|
||||
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, OffsetRangeExt, Point,
|
||||
|
@ -750,6 +752,10 @@ impl Item for Editor {
|
|||
Some(Box::new(handle.clone()))
|
||||
}
|
||||
|
||||
fn pixel_position_of_cursor(&self) -> Option<Vector2F> {
|
||||
self.pixel_position_of_newest_cursor
|
||||
}
|
||||
|
||||
fn breadcrumb_location(&self) -> ToolbarItemLocation {
|
||||
ToolbarItemLocation::PrimaryLeft { flex: None }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue