on master help sign in
Refactor push_jump so we're not needlessly fetching doc twice
26dbdb7Blaž Hrastnik
helix-term/src/commands.rs+10−11
@@ -965,19 +965,18 @@ fn goto_file_start(cx: &mut Context) {
965 if cx.count.is_some() {
965 if cx.count.is_some() {
966 goto_line(cx);
966 goto_line(cx);
967 } else {
967 } else {
968− push_jump(cx.editor);
969 let (view, doc) = current!(cx.editor);
968 let (view, doc) = current!(cx.editor);
970 let text = doc.text().slice(..);
969 let text = doc.text().slice(..);
971 let selection = doc
970 let selection = doc
972 .selection(view.id)
971 .selection(view.id)
973 .clone()
972 .clone()
974 .transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
973 .transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
974+ push_jump(view, doc);
975 doc.set_selection(view.id, selection);
975 doc.set_selection(view.id, selection);
976 }
976 }
977}
977}
978
978
979fn goto_file_end(cx: &mut Context) {
979fn goto_file_end(cx: &mut Context) {
980− push_jump(cx.editor);
981 let (view, doc) = current!(cx.editor);
980 let (view, doc) = current!(cx.editor);
982 let text = doc.text().slice(..);
981 let text = doc.text().slice(..);
983 let pos = doc.text().len_chars();
982 let pos = doc.text().len_chars();
@@ -985,6 +984,7 @@ fn goto_file_end(cx: &mut Context) {
985 .selection(view.id)
984 .selection(view.id)
986 .clone()
985 .clone()
987 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
986 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
987+ push_jump(view, doc);
988 doc.set_selection(view.id, selection);
988 doc.set_selection(view.id, selection);
989}
989}
990
990
@@ -2485,8 +2485,7 @@ fn try_restore_indent(doc: &mut Document, view_id: ViewId) {
2485}
2485}
2486
2486
2487// Store a jump on the jumplist.
2487// Store a jump on the jumplist.
2488−fn push_jump(editor: &mut Editor) {
2488+fn push_jump(view: &mut View, doc: &Document) {
2489− let (view, doc) = current!(editor);
2490 let jump = (doc.id(), doc.selection(view.id).clone());
2489 let jump = (doc.id(), doc.selection(view.id).clone());
2491 view.jumps.push(jump);
2490 view.jumps.push(jump);
2492}
2491}
@@ -2497,8 +2496,6 @@ fn goto_line(cx: &mut Context) {
2497
2496
2498fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
2497fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
2499 if let Some(count) = count {
2498 if let Some(count) = count {
2500− push_jump(editor);
2501−
2502 let (view, doc) = current!(editor);
2499 let (view, doc) = current!(editor);
2503 let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
2500 let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
2504 // If the last line is blank, don't jump to it.
2501 // If the last line is blank, don't jump to it.
@@ -2513,13 +2510,13 @@ fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
2513 .selection(view.id)
2510 .selection(view.id)
2514 .clone()
2511 .clone()
2515 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2512 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2513+
2514+ push_jump(view, doc);
2516 doc.set_selection(view.id, selection);
2515 doc.set_selection(view.id, selection);
2517 }
2516 }
2518}
2517}
2519
2518
2520fn goto_last_line(cx: &mut Context) {
2519fn goto_last_line(cx: &mut Context) {
2521− push_jump(cx.editor);
2522−
2523 let (view, doc) = current!(cx.editor);
2520 let (view, doc) = current!(cx.editor);
2524 let line_idx = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
2521 let line_idx = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
2525 // If the last line is blank, don't jump to it.
2522 // If the last line is blank, don't jump to it.
@@ -2533,6 +2530,8 @@ fn goto_last_line(cx: &mut Context) {
2533 .selection(view.id)
2530 .selection(view.id)
2534 .clone()
2531 .clone()
2535 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2532 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2533+
2534+ push_jump(view, doc);
2536 doc.set_selection(view.id, selection);
2535 doc.set_selection(view.id, selection);
2537}
2536}
2538
2537
@@ -2601,10 +2600,9 @@ fn exit_select_mode(cx: &mut Context) {
2601}
2600}
2602
2601
2603fn goto_pos(editor: &mut Editor, pos: usize) {
2602fn goto_pos(editor: &mut Editor, pos: usize) {
2604− push_jump(editor);
2605−
2606 let (view, doc) = current!(editor);
2603 let (view, doc) = current!(editor);
2607
2604
2605+ push_jump(view, doc);
2608 doc.set_selection(view.id, Selection::point(pos));
2606 doc.set_selection(view.id, Selection::point(pos));
2609 align_view(doc, view, Align::Center);
2607 align_view(doc, view, Align::Center);
2610}
2608}
@@ -3886,7 +3884,8 @@ fn jump_backward(cx: &mut Context) {
3886}
3884}
3887
3885
3888fn save_selection(cx: &mut Context) {
3886fn save_selection(cx: &mut Context) {
3889− push_jump(cx.editor);
3887+ let (view, doc) = current!(cx.editor);
3888+ push_jump(view, doc);
3890 cx.editor.set_status("Selection saved to jumplist");
3889 cx.editor.set_status("Selection saved to jumplist");
3891}
3890}
3892
3891
helix-term/src/commands/lsp.rs+7−5
@@ -39,13 +39,15 @@ fn location_to_file_location(location: &lsp::Location) -> FileLocation {
39}
39}
40
40
41// TODO: share with symbol picker(symbol.location)
41// TODO: share with symbol picker(symbol.location)
42−// TODO: need to use push_jump() before?
43fn jump_to_location(
42fn jump_to_location(
44 editor: &mut Editor,
43 editor: &mut Editor,
45 location: &lsp::Location,
44 location: &lsp::Location,
46 offset_encoding: OffsetEncoding,
45 offset_encoding: OffsetEncoding,
47 action: Action,
46 action: Action,
48) {
47) {
48+ let (view, doc) = current!(editor);
49+ push_jump(view, doc);
50+
49 let path = match location.uri.to_file_path() {
51 let path = match location.uri.to_file_path() {
50 Ok(path) => path,
52 Ok(path) => path,
51 Err(_) => {
53 Err(_) => {
@@ -93,9 +95,10 @@ fn sym_picker(
93 }
95 }
94 },
96 },
95 move |cx, symbol, action| {
97 move |cx, symbol, action| {
98+ let (view, doc) = current!(cx.editor);
99+ push_jump(view, doc);
100+
96− if current_path2.as_ref() == Some(&symbol.location.uri) {
101+ if current_path2.as_ref() != Some(&symbol.location.uri) {
97− push_jump(cx.editor);
98− } else {
99 let uri = &symbol.location.uri;
102 let uri = &symbol.location.uri;
100 let path = match uri.to_file_path() {
103 let path = match uri.to_file_path() {
101 Ok(path) => path,
104 Ok(path) => path,
@@ -518,7 +521,6 @@ fn goto_impl(
518 format!("{}:{}", file, line).into()
521 format!("{}:{}", file, line).into()
519 },
522 },
520 move |cx, location, action| {
523 move |cx, location, action| {
521− push_jump(cx.editor);
522 jump_to_location(cx.editor, location, offset_encoding, action)
524 jump_to_location(cx.editor, location, offset_encoding, action)
523 },
525 },
524 move |_editor, location| Some(location_to_file_location(location)),
526 move |_editor, location| Some(location_to_file_location(location)),