goto end of file if count is not present

pull/8135/head
GiM 1 year ago
parent a38ec6d6ca
commit ced96cff2d

@ -3105,16 +3105,13 @@ fn push_jump(view: &mut View, doc: &Document) {
} }
fn goto_line(cx: &mut Context) { fn goto_line(cx: &mut Context) {
if cx.count.is_some() {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
push_jump(view, doc); push_jump(view, doc);
goto_line_without_jumplist(cx.editor, cx.count); goto_line_without_jumplist(cx.editor, cx.count);
}
} }
fn goto_line_without_jumplist(editor: &mut Editor, count: Option<NonZeroUsize>) { fn goto_line_without_jumplist(editor: &mut Editor, count: Option<NonZeroUsize>) {
if let Some(count) = count {
let (view, doc) = current!(editor); let (view, doc) = current!(editor);
let text = doc.text().slice(..); let text = doc.text().slice(..);
let max_line = if text.line(text.len_lines() - 1).len_chars() == 0 { let max_line = if text.line(text.len_lines() - 1).len_chars() == 0 {
@ -3123,7 +3120,13 @@ fn goto_line_without_jumplist(editor: &mut Editor, count: Option<NonZeroUsize>)
} else { } else {
text.len_lines() - 1 text.len_lines() - 1
}; };
let line_idx = std::cmp::min(count.get() - 1, max_line);
let line_idx = if let Some(count) = count {
std::cmp::min(count.get() - 1, max_line)
} else {
max_line
};
let pos = text.line_to_char(line_idx); let pos = text.line_to_char(line_idx);
let selection = doc let selection = doc
.selection(view.id) .selection(view.id)
@ -3131,7 +3134,6 @@ fn goto_line_without_jumplist(editor: &mut Editor, count: Option<NonZeroUsize>)
.transform(|range| range.put_cursor(text, pos, editor.mode == Mode::Select)); .transform(|range| range.put_cursor(text, pos, editor.mode == Mode::Select));
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) {

Loading…
Cancel
Save