on master help sign in
Refactor push_jump so we're not needlessly fetching doc twice
commit26dbdb70fb29bdad2e875a776b70815bf5533a34 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 7 Jun 2022, 00:19 (4 years ago) parent3d99239
2 files changed+17−16
helix-term/src/commands.rs+10−11 helix-term/src/commands/lsp.rs+7−5
helix-term/src/commands.rs+10−11
@@ -965,19 +965,18 @@ fn goto_file_start(cx: &mut Context) {
965965 if cx.count.is_some() {
966966 goto_line(cx);
967967 } else {
968− push_jump(cx.editor);
969968 let (view, doc) = current!(cx.editor);
970969 let text = doc.text().slice(..);
971970 let selection = doc
972971 .selection(view.id)
973972 .clone()
974973 .transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
974+ push_jump(view, doc);
975975 doc.set_selection(view.id, selection);
976976 }
977977}
978978
979979fn goto_file_end(cx: &mut Context) {
980− push_jump(cx.editor);
981980 let (view, doc) = current!(cx.editor);
982981 let text = doc.text().slice(..);
983982 let pos = doc.text().len_chars();
@@ -985,6 +984,7 @@ fn goto_file_end(cx: &mut Context) {
985984 .selection(view.id)
986985 .clone()
987986 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
987+ push_jump(view, doc);
988988 doc.set_selection(view.id, selection);
989989}
990990
@@ -2485,8 +2485,7 @@ fn try_restore_indent(doc: &mut Document, view_id: ViewId) {
24852485}
24862486
24872487// Store a jump on the jumplist.
2488−fn push_jump(editor: &mut Editor) {
2489− let (view, doc) = current!(editor);
2488+fn push_jump(view: &mut View, doc: &Document) {
24902489 let jump = (doc.id(), doc.selection(view.id).clone());
24912490 view.jumps.push(jump);
24922491}
@@ -2497,8 +2496,6 @@ fn goto_line(cx: &mut Context) {
24972496
24982497fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
24992498 if let Some(count) = count {
2500− push_jump(editor);
2501−
25022499 let (view, doc) = current!(editor);
25032500 let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
25042501 // 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>) {
25132510 .selection(view.id)
25142511 .clone()
25152512 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2513+
2514+ push_jump(view, doc);
25162515 doc.set_selection(view.id, selection);
25172516 }
25182517}
25192518
25202519fn goto_last_line(cx: &mut Context) {
2521− push_jump(cx.editor);
2522−
25232520 let (view, doc) = current!(cx.editor);
25242521 let line_idx = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
25252522 // If the last line is blank, don't jump to it.
@@ -2533,6 +2530,8 @@ fn goto_last_line(cx: &mut Context) {
25332530 .selection(view.id)
25342531 .clone()
25352532 .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
2533+
2534+ push_jump(view, doc);
25362535 doc.set_selection(view.id, selection);
25372536}
25382537
@@ -2601,10 +2600,9 @@ fn exit_select_mode(cx: &mut Context) {
26012600}
26022601
26032602fn goto_pos(editor: &mut Editor, pos: usize) {
2604− push_jump(editor);
2605−
26062603 let (view, doc) = current!(editor);
26072604
2605+ push_jump(view, doc);
26082606 doc.set_selection(view.id, Selection::point(pos));
26092607 align_view(doc, view, Align::Center);
26102608}
@@ -3886,7 +3884,8 @@ fn jump_backward(cx: &mut Context) {
38863884}
38873885
38883886fn save_selection(cx: &mut Context) {
3889− push_jump(cx.editor);
3887+ let (view, doc) = current!(cx.editor);
3888+ push_jump(view, doc);
38903889 cx.editor.set_status("Selection saved to jumplist");
38913890}
38923891
helix-term/src/commands/lsp.rs+7−5
@@ -39,13 +39,15 @@ fn location_to_file_location(location: &lsp::Location) -> FileLocation {
3939}
4040
4141// TODO: share with symbol picker(symbol.location)
42−// TODO: need to use push_jump() before?
4342fn jump_to_location(
4443 editor: &mut Editor,
4544 location: &lsp::Location,
4645 offset_encoding: OffsetEncoding,
4746 action: Action,
4847) {
48+ let (view, doc) = current!(editor);
49+ push_jump(view, doc);
50+
4951 let path = match location.uri.to_file_path() {
5052 Ok(path) => path,
5153 Err(_) => {
@@ -93,9 +95,10 @@ fn sym_picker(
9395 }
9496 },
9597 move |cx, symbol, action| {
96− if current_path2.as_ref() == Some(&symbol.location.uri) {
97− push_jump(cx.editor);
98− } else {
98+ let (view, doc) = current!(cx.editor);
99+ push_jump(view, doc);
100+
101+ if current_path2.as_ref() != Some(&symbol.location.uri) {
99102 let uri = &symbol.location.uri;
100103 let path = match uri.to_file_path() {
101104 Ok(path) => path,
@@ -518,7 +521,6 @@ fn goto_impl(
518521 format!("{}:{}", file, line).into()
519522 },
520523 move |cx, location, action| {
521− push_jump(cx.editor);
522524 jump_to_location(cx.editor, location, offset_encoding, action)
523525 },
524526 move |_editor, location| Some(location_to_file_location(location)),