mirror of https://github.com/helix-editor/helix
Refactor push_jump so we're not needlessly fetching doc twice
parent
3d9923969a
commit
26dbdb70fb
|
@ -965,19 +965,18 @@ fn goto_file_start(cx: &mut Context) {
|
||||||
if cx.count.is_some() {
|
if cx.count.is_some() {
|
||||||
goto_line(cx);
|
goto_line(cx);
|
||||||
} else {
|
} else {
|
||||||
push_jump(cx.editor);
|
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
let selection = doc
|
let selection = doc
|
||||||
.selection(view.id)
|
.selection(view.id)
|
||||||
.clone()
|
.clone()
|
||||||
.transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
|
.transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
|
||||||
|
push_jump(view, doc);
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_file_end(cx: &mut Context) {
|
fn goto_file_end(cx: &mut Context) {
|
||||||
push_jump(cx.editor);
|
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
let pos = doc.text().len_chars();
|
let pos = doc.text().len_chars();
|
||||||
|
@ -985,6 +984,7 @@ fn goto_file_end(cx: &mut Context) {
|
||||||
.selection(view.id)
|
.selection(view.id)
|
||||||
.clone()
|
.clone()
|
||||||
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
|
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
|
||||||
|
push_jump(view, doc);
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2485,8 +2485,7 @@ fn try_restore_indent(doc: &mut Document, view_id: ViewId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store a jump on the jumplist.
|
// Store a jump on the jumplist.
|
||||||
fn push_jump(editor: &mut Editor) {
|
fn push_jump(view: &mut View, doc: &Document) {
|
||||||
let (view, doc) = current!(editor);
|
|
||||||
let jump = (doc.id(), doc.selection(view.id).clone());
|
let jump = (doc.id(), doc.selection(view.id).clone());
|
||||||
view.jumps.push(jump);
|
view.jumps.push(jump);
|
||||||
}
|
}
|
||||||
|
@ -2497,8 +2496,6 @@ fn goto_line(cx: &mut Context) {
|
||||||
|
|
||||||
fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
|
fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
|
||||||
if let Some(count) = count {
|
if let Some(count) = count {
|
||||||
push_jump(editor);
|
|
||||||
|
|
||||||
let (view, doc) = current!(editor);
|
let (view, doc) = current!(editor);
|
||||||
let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
|
let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
|
||||||
// If the last line is blank, don't jump to it.
|
// 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>) {
|
||||||
.selection(view.id)
|
.selection(view.id)
|
||||||
.clone()
|
.clone()
|
||||||
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
|
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
|
||||||
|
|
||||||
|
push_jump(view, doc);
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_last_line(cx: &mut Context) {
|
fn goto_last_line(cx: &mut Context) {
|
||||||
push_jump(cx.editor);
|
|
||||||
|
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let line_idx = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
|
let line_idx = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
|
||||||
// If the last line is blank, don't jump to it.
|
// If the last line is blank, don't jump to it.
|
||||||
|
@ -2533,6 +2530,8 @@ fn goto_last_line(cx: &mut Context) {
|
||||||
.selection(view.id)
|
.selection(view.id)
|
||||||
.clone()
|
.clone()
|
||||||
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
|
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
|
||||||
|
|
||||||
|
push_jump(view, doc);
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2601,10 +2600,9 @@ fn exit_select_mode(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_pos(editor: &mut Editor, pos: usize) {
|
fn goto_pos(editor: &mut Editor, pos: usize) {
|
||||||
push_jump(editor);
|
|
||||||
|
|
||||||
let (view, doc) = current!(editor);
|
let (view, doc) = current!(editor);
|
||||||
|
|
||||||
|
push_jump(view, doc);
|
||||||
doc.set_selection(view.id, Selection::point(pos));
|
doc.set_selection(view.id, Selection::point(pos));
|
||||||
align_view(doc, view, Align::Center);
|
align_view(doc, view, Align::Center);
|
||||||
}
|
}
|
||||||
|
@ -3886,7 +3884,8 @@ fn jump_backward(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_selection(cx: &mut Context) {
|
fn save_selection(cx: &mut Context) {
|
||||||
push_jump(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
|
push_jump(view, doc);
|
||||||
cx.editor.set_status("Selection saved to jumplist");
|
cx.editor.set_status("Selection saved to jumplist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,15 @@ fn location_to_file_location(location: &lsp::Location) -> FileLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: share with symbol picker(symbol.location)
|
// TODO: share with symbol picker(symbol.location)
|
||||||
// TODO: need to use push_jump() before?
|
|
||||||
fn jump_to_location(
|
fn jump_to_location(
|
||||||
editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
location: &lsp::Location,
|
location: &lsp::Location,
|
||||||
offset_encoding: OffsetEncoding,
|
offset_encoding: OffsetEncoding,
|
||||||
action: Action,
|
action: Action,
|
||||||
) {
|
) {
|
||||||
|
let (view, doc) = current!(editor);
|
||||||
|
push_jump(view, doc);
|
||||||
|
|
||||||
let path = match location.uri.to_file_path() {
|
let path = match location.uri.to_file_path() {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -93,9 +95,10 @@ fn sym_picker(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move |cx, symbol, action| {
|
move |cx, symbol, action| {
|
||||||
if current_path2.as_ref() == Some(&symbol.location.uri) {
|
let (view, doc) = current!(cx.editor);
|
||||||
push_jump(cx.editor);
|
push_jump(view, doc);
|
||||||
} else {
|
|
||||||
|
if current_path2.as_ref() != Some(&symbol.location.uri) {
|
||||||
let uri = &symbol.location.uri;
|
let uri = &symbol.location.uri;
|
||||||
let path = match uri.to_file_path() {
|
let path = match uri.to_file_path() {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
|
@ -518,7 +521,6 @@ fn goto_impl(
|
||||||
format!("{}:{}", file, line).into()
|
format!("{}:{}", file, line).into()
|
||||||
},
|
},
|
||||||
move |cx, location, action| {
|
move |cx, location, action| {
|
||||||
push_jump(cx.editor);
|
|
||||||
jump_to_location(cx.editor, location, offset_encoding, action)
|
jump_to_location(cx.editor, location, offset_encoding, action)
|
||||||
},
|
},
|
||||||
move |_editor, location| Some(location_to_file_location(location)),
|
move |_editor, location| Some(location_to_file_location(location)),
|
||||||
|
|
Loading…
Reference in New Issue