Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add support for `editor::SwapSelectionEnds` everywhere (emacs exchange-point-and-mark) (#23428)

Peter Tripp3d47f32f0c60
diff --git a/assets/keymaps/linux/emacs.json b/assets/keymaps/linux/emacs.json
index 45d6e77671d..2c1128d8d66 100755
--- a/assets/keymaps/linux/emacs.json
+++ b/assets/keymaps/linux/emacs.json
@@ -17,7 +17,7 @@
"alt-g alt-g": "go_to_line::Toggle", // goto-line
"ctrl-space": "editor::SetMark", // set-mark
"ctrl-@": "editor::SetMark", // set-mark
- "ctrl-x ctrl-x": "editor::ExchangeMark", // exchange-point-and-mark
+ "ctrl-x ctrl-x": "editor::SwapSelectionEnds", // exchange-point-and-mark
"ctrl-f": "editor::MoveRight", // forward-char
"ctrl-b": "editor::MoveLeft", // backward-char
"ctrl-n": "editor::MoveDown", // next-line
diff --git a/assets/keymaps/macos/emacs.json b/assets/keymaps/macos/emacs.json
index 45d6e77671d..2c1128d8d66 100755
--- a/assets/keymaps/macos/emacs.json
+++ b/assets/keymaps/macos/emacs.json
@@ -17,7 +17,7 @@
"alt-g alt-g": "go_to_line::Toggle", // goto-line
"ctrl-space": "editor::SetMark", // set-mark
"ctrl-@": "editor::SetMark", // set-mark
- "ctrl-x ctrl-x": "editor::ExchangeMark", // exchange-point-and-mark
+ "ctrl-x ctrl-x": "editor::SwapSelectionEnds", // exchange-point-and-mark
"ctrl-f": "editor::MoveRight", // forward-char
"ctrl-b": "editor::MoveLeft", // backward-char
"ctrl-n": "editor::MoveDown", // next-line
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs
index e728a72dce3..c71c69f8b05 100644
--- a/crates/editor/src/actions.rs
+++ b/crates/editor/src/actions.rs
@@ -377,7 +377,7 @@ gpui::actions!(
ToggleInlayHints,
ToggleInlineCompletions,
ToggleLineNumbers,
- ExchangeMark,
+ SwapSelectionEnds,
SetMark,
ToggleRelativeLineNumbers,
ToggleSelectionMenu,
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 6f036958fbf..fbc74b3d060 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -10633,17 +10633,18 @@ impl Editor {
cx.notify();
}
- pub fn exchange_mark(&mut self, _: &actions::ExchangeMark, cx: &mut ViewContext<Self>) {
- if self.selection_mark_mode {
- self.change_selections(None, cx, |s| {
- s.move_with(|_, sel| {
- if sel.start != sel.end {
- sel.reversed = !sel.reversed
- }
- });
- })
- }
- self.selection_mark_mode = true;
+ pub fn swap_selection_ends(
+ &mut self,
+ _: &actions::SwapSelectionEnds,
+ cx: &mut ViewContext<Self>,
+ ) {
+ self.change_selections(None, cx, |s| {
+ s.move_with(|_, sel| {
+ if sel.start != sel.end {
+ sel.reversed = !sel.reversed
+ }
+ });
+ });
cx.notify();
}
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index eab2bf3798e..e9485aa447f 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -357,7 +357,7 @@ impl EditorElement {
register_action(view, cx, Editor::unfold_at);
register_action(view, cx, Editor::fold_selected_ranges);
register_action(view, cx, Editor::set_mark);
- register_action(view, cx, Editor::exchange_mark);
+ register_action(view, cx, Editor::swap_selection_ends);
register_action(view, cx, Editor::show_completions);
register_action(view, cx, Editor::toggle_code_actions);
register_action(view, cx, Editor::open_excerpts);