aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor')
-rw-r--r--crates/libeditor/src/code_actions.rs4
-rw-r--r--crates/libeditor/src/typing.rs17
2 files changed, 10 insertions, 11 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs
index e6ba83d2e..cd5146d87 100644
--- a/crates/libeditor/src/code_actions.rs
+++ b/crates/libeditor/src/code_actions.rs
@@ -29,8 +29,8 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce()
29 let right = non_trivia_sibling(comma, Direction::Forward)?; 29 let right = non_trivia_sibling(comma, Direction::Forward)?;
30 Some(move || { 30 Some(move || {
31 let mut edit = EditBuilder::new(); 31 let mut edit = EditBuilder::new();
32 edit.replace(left.range(), right.text()); 32 edit.replace(left.range(), right.text().to_string());
33 edit.replace(right.range(), left.text()); 33 edit.replace(right.range(), left.text().to_string());
34 ActionResult { 34 ActionResult {
35 edit: edit.finish(), 35 edit: edit.finish(),
36 cursor_position: None, 36 cursor_position: None,
diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs
index 2cff96b34..3a3776c26 100644
--- a/crates/libeditor/src/typing.rs
+++ b/crates/libeditor/src/typing.rs
@@ -15,16 +15,15 @@ use {ActionResult, EditBuilder, find_node_at_offset};
15 15
16pub fn join_lines(file: &File, range: TextRange) -> ActionResult { 16pub fn join_lines(file: &File, range: TextRange) -> ActionResult {
17 let range = if range.is_empty() { 17 let range = if range.is_empty() {
18 let text = file.syntax().text(); 18 let syntax = file.syntax();
19 let text = &text[TextRange::from_to(range.start(), TextUnit::of_str(&text))]; 19 let text = syntax.text().slice(range.start()..);
20 let pos = text.bytes().take_while(|&b| b != b'\n').count(); 20 let pos = match text.find('\n') {
21 if pos == text.len() { 21 None => return ActionResult {
22 return ActionResult {
23 edit: EditBuilder::new().finish(), 22 edit: EditBuilder::new().finish(),
24 cursor_position: None 23 cursor_position: None
25 }; 24 },
26 } 25 Some(pos) => pos
27 let pos: TextUnit = (pos as u32).into(); 26 };
28 TextRange::offset_len( 27 TextRange::offset_len(
29 range.start() + pos, 28 range.start() + pos,
30 TextUnit::of_char('\n'), 29 TextUnit::of_char('\n'),
@@ -129,7 +128,7 @@ fn join_lambda_body(
129 let expr = single_expr(block)?; 128 let expr = single_expr(block)?;
130 edit.replace( 129 edit.replace(
131 block_expr.syntax().range(), 130 block_expr.syntax().range(),
132 expr.syntax().text(), 131 expr.syntax().text().to_string(),
133 ); 132 );
134 Some(()) 133 Some(())
135} 134}