mirror of https://github.com/helix-editor/helix
Do not add intermediate lines to jumplist with :<linenum> command.
parent
4eca4b3079
commit
70ade5f46e
|
@ -2715,10 +2715,15 @@ fn push_jump(view: &mut View, doc: &Document) {
|
|||
}
|
||||
|
||||
fn goto_line(cx: &mut Context) {
|
||||
goto_line_impl(cx.editor, cx.count)
|
||||
if cx.count.is_some() {
|
||||
goto_line_without_jumplist(cx.editor, cx.count);
|
||||
|
||||
let (view, doc) = current!(cx.editor);
|
||||
push_jump(view, doc);
|
||||
}
|
||||
}
|
||||
|
||||
fn goto_line_impl(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 text = doc.text().slice(..);
|
||||
|
@ -2735,7 +2740,6 @@ fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
|
|||
.clone()
|
||||
.transform(|range| range.put_cursor(text, pos, editor.mode == Mode::Select));
|
||||
|
||||
push_jump(view, doc);
|
||||
doc.set_selection(view.id, selection);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1418,7 +1418,7 @@ pub(super) fn goto_line_number(
|
|||
match event {
|
||||
PromptEvent::Abort => {
|
||||
if let Some(line_number) = cx.editor.last_line_number {
|
||||
goto_line_impl(cx.editor, NonZeroUsize::new(line_number));
|
||||
goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line_number));
|
||||
let (view, doc) = current!(cx.editor);
|
||||
view.ensure_cursor_in_view(doc, line_number);
|
||||
cx.editor.last_line_number = None;
|
||||
|
@ -1427,6 +1427,10 @@ pub(super) fn goto_line_number(
|
|||
}
|
||||
PromptEvent::Validate => {
|
||||
ensure!(!args.is_empty(), "Line number required");
|
||||
|
||||
let (view, doc) = current!(cx.editor);
|
||||
push_jump(view, doc);
|
||||
|
||||
cx.editor.last_line_number = None;
|
||||
}
|
||||
PromptEvent::Update => {
|
||||
|
@ -1434,7 +1438,7 @@ pub(super) fn goto_line_number(
|
|||
if let Some(line_number) = cx.editor.last_line_number {
|
||||
// When a user hits backspace and there are no numbers left,
|
||||
// we can bring them back to their original line
|
||||
goto_line_impl(cx.editor, NonZeroUsize::new(line_number));
|
||||
goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line_number));
|
||||
let (view, doc) = current!(cx.editor);
|
||||
view.ensure_cursor_in_view(doc, line_number);
|
||||
cx.editor.last_line_number = None;
|
||||
|
@ -1445,12 +1449,13 @@ pub(super) fn goto_line_number(
|
|||
let text = doc.text().slice(..);
|
||||
let line = doc.selection(view.id).primary().cursor_line(text);
|
||||
cx.editor.last_line_number.get_or_insert(line + 1);
|
||||
|
||||
let line = args[0].parse::<usize>()?;
|
||||
goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line));
|
||||
let (view, doc) = current!(cx.editor);
|
||||
view.ensure_cursor_in_view(doc, line);
|
||||
}
|
||||
}
|
||||
let line = args[0].parse::<usize>()?;
|
||||
goto_line_impl(cx.editor, NonZeroUsize::new(line));
|
||||
let (view, doc) = current!(cx.editor);
|
||||
view.ensure_cursor_in_view(doc, line);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -21,18 +21,21 @@ type Jump = (DocumentId, Selection);
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct JumpList {
|
||||
jumps: VecDeque<Jump>,
|
||||
current: usize,
|
||||
current_idx: usize,
|
||||
}
|
||||
|
||||
impl JumpList {
|
||||
pub fn new(initial: Jump) -> Self {
|
||||
let mut jumps = VecDeque::with_capacity(JUMP_LIST_CAPACITY);
|
||||
jumps.push_back(initial);
|
||||
Self { jumps, current: 0 }
|
||||
Self {
|
||||
jumps,
|
||||
current_idx: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, jump: Jump) {
|
||||
self.jumps.truncate(self.current);
|
||||
self.jumps.truncate(self.current_idx + 1);
|
||||
// don't push duplicates
|
||||
if self.jumps.back() != Some(&jump) {
|
||||
// If the jumplist is full, drop the oldest item.
|
||||
|
@ -41,14 +44,14 @@ impl JumpList {
|
|||
}
|
||||
|
||||
self.jumps.push_back(jump);
|
||||
self.current = self.jumps.len();
|
||||
self.current_idx = self.jumps.len() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn forward(&mut self, count: usize) -> Option<&Jump> {
|
||||
if self.current + count < self.jumps.len() {
|
||||
self.current += count;
|
||||
self.jumps.get(self.current)
|
||||
if self.current_idx + count < self.jumps.len() {
|
||||
self.current_idx += count;
|
||||
self.jumps.get(self.current_idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -56,13 +59,13 @@ impl JumpList {
|
|||
|
||||
// Taking view and doc to prevent unnecessary cloning when jump is not required.
|
||||
pub fn backward(&mut self, view_id: ViewId, doc: &mut Document, count: usize) -> Option<&Jump> {
|
||||
if let Some(current) = self.current.checked_sub(count) {
|
||||
if self.current == self.jumps.len() {
|
||||
if let Some(current) = self.current_idx.checked_sub(count) {
|
||||
if self.current_idx == self.jumps.len() {
|
||||
let jump = (doc.id(), doc.selection(view_id).clone());
|
||||
self.push(jump);
|
||||
}
|
||||
self.current = current;
|
||||
self.jumps.get(self.current)
|
||||
self.current_idx = current;
|
||||
self.jumps.get(self.current_idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue