mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-11 12:46:07 +00:00
Implement cmd-k cmd-d to replace selection with next
This commit is contained in:
parent
d249618ee6
commit
fc2ae42f4b
1 changed files with 13 additions and 4 deletions
|
@ -88,7 +88,7 @@ action!(SelectLine);
|
||||||
action!(SplitSelectionIntoLines);
|
action!(SplitSelectionIntoLines);
|
||||||
action!(AddSelectionAbove);
|
action!(AddSelectionAbove);
|
||||||
action!(AddSelectionBelow);
|
action!(AddSelectionBelow);
|
||||||
action!(SelectNext);
|
action!(SelectNext, bool);
|
||||||
action!(ToggleComments);
|
action!(ToggleComments);
|
||||||
action!(SelectLargerSyntaxNode);
|
action!(SelectLargerSyntaxNode);
|
||||||
action!(SelectSmallerSyntaxNode);
|
action!(SelectSmallerSyntaxNode);
|
||||||
|
@ -193,7 +193,8 @@ pub fn init(cx: &mut MutableAppContext, entry_openers: &mut Vec<Box<dyn EntryOpe
|
||||||
Binding::new("cmd-ctrl-p", AddSelectionAbove, Some("Editor")),
|
Binding::new("cmd-ctrl-p", AddSelectionAbove, Some("Editor")),
|
||||||
Binding::new("cmd-alt-down", AddSelectionBelow, Some("Editor")),
|
Binding::new("cmd-alt-down", AddSelectionBelow, Some("Editor")),
|
||||||
Binding::new("cmd-ctrl-n", AddSelectionBelow, Some("Editor")),
|
Binding::new("cmd-ctrl-n", AddSelectionBelow, Some("Editor")),
|
||||||
Binding::new("cmd-d", SelectNext, Some("Editor")),
|
Binding::new("cmd-d", SelectNext(false), Some("Editor")),
|
||||||
|
Binding::new("cmd-k cmd-d", SelectNext(true), Some("Editor")),
|
||||||
Binding::new("cmd-/", ToggleComments, Some("Editor")),
|
Binding::new("cmd-/", ToggleComments, Some("Editor")),
|
||||||
Binding::new("alt-up", SelectLargerSyntaxNode, Some("Editor")),
|
Binding::new("alt-up", SelectLargerSyntaxNode, Some("Editor")),
|
||||||
Binding::new("ctrl-w", SelectLargerSyntaxNode, Some("Editor")),
|
Binding::new("ctrl-w", SelectLargerSyntaxNode, Some("Editor")),
|
||||||
|
@ -2513,7 +2514,8 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
|
pub fn select_next(&mut self, action: &SelectNext, cx: &mut ViewContext<Self>) {
|
||||||
|
let replace_newest = action.0;
|
||||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||||
let buffer = &display_map.buffer_snapshot;
|
let buffer = &display_map.buffer_snapshot;
|
||||||
let mut selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
let mut selections = self.selections::<usize>(cx).collect::<Vec<_>>();
|
||||||
|
@ -2552,6 +2554,13 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(next_selected_range) = next_selected_range {
|
if let Some(next_selected_range) = next_selected_range {
|
||||||
|
if replace_newest {
|
||||||
|
if let Some(newest_id) =
|
||||||
|
selections.iter().max_by_key(|s| s.id).map(|s| s.id)
|
||||||
|
{
|
||||||
|
selections.retain(|s| s.id != newest_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
selections.push(Selection {
|
selections.push(Selection {
|
||||||
id: post_inc(&mut self.next_selection_id),
|
id: post_inc(&mut self.next_selection_id),
|
||||||
start: next_selected_range.start,
|
start: next_selected_range.start,
|
||||||
|
@ -2598,7 +2607,7 @@ impl Editor {
|
||||||
wordwise: false,
|
wordwise: false,
|
||||||
done: false,
|
done: false,
|
||||||
});
|
});
|
||||||
self.select_next(&SelectNext, cx);
|
self.select_next(action, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue