Start on joining lines
Co-Authored-By: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
5860b7b143
commit
c48bd394c1
2 changed files with 46 additions and 3 deletions
|
@ -206,6 +206,7 @@ actions!(
|
|||
DuplicateLine,
|
||||
MoveLineUp,
|
||||
MoveLineDown,
|
||||
JoinLines,
|
||||
Transpose,
|
||||
Cut,
|
||||
Copy,
|
||||
|
@ -321,6 +322,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
cx.add_action(Editor::indent);
|
||||
cx.add_action(Editor::outdent);
|
||||
cx.add_action(Editor::delete_line);
|
||||
cx.add_action(Editor::join_lines);
|
||||
cx.add_action(Editor::delete_to_previous_word_start);
|
||||
cx.add_action(Editor::delete_to_previous_subword_start);
|
||||
cx.add_action(Editor::delete_to_next_word_end);
|
||||
|
@ -3952,6 +3954,17 @@ impl Editor {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn join_lines(&mut self, _: &JoinLines, cx: &mut ViewContext<Self>) {
|
||||
let cursor_position = self.selections.newest::<Point>(cx).head();
|
||||
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||
let end_of_line = Point::new(cursor_position.row, snapshot.line_len(cursor_position.row));
|
||||
let start_of_next_line = end_of_line + Point::new(1, 0);
|
||||
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit([(end_of_line..start_of_next_line, " ")], None, cx)
|
||||
});
|
||||
}
|
||||
|
||||
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = &display_map.buffer_snapshot;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue