@@ -1572,47 +1572,67 @@ fn tutor(
1575+fn abort_goto_line_number_preview(cx: &mut compositor::Context) {
1576+ if let Some(last_selection) = cx.editor.last_selection.take() {
1577+ let scrolloff = cx.editor.config().scrolloff;
1579+ let (view, doc) = current!(cx.editor);
1580+ doc.set_selection(view.id, last_selection);
1581+ view.ensure_cursor_in_view(doc, scrolloff);
1585+fn update_goto_line_number_preview(
1586+ cx: &mut compositor::Context,
1588+) -> anyhow::Result<()> {
1589+ cx.editor.last_selection.get_or_insert_with(|| {
1590+ let (view, doc) = current!(cx.editor);
1591+ doc.selection(view.id).clone()
1594+ let scrolloff = cx.editor.config().scrolloff;
1595+ let line = args[0].parse::<usize>()?;
1596+ goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line));
1598+ let (view, doc) = current!(cx.editor);
1599+ view.ensure_cursor_in_view(doc, scrolloff);
1575pub(super) fn goto_line_number(
1604pub(super) fn goto_line_number(
1576 cx: &mut compositor::Context,
1605 cx: &mut compositor::Context,
1577 args: &[Cow<str>],
1606 args: &[Cow<str>],
1578 event: PromptEvent,
1607 event: PromptEvent,
1579) -> anyhow::Result<()> {
1608) -> anyhow::Result<()> {
1580 match event {
1609 match event {
1581− PromptEvent::Abort => {
1610+ PromptEvent::Abort => abort_goto_line_number_preview(cx),
1582− if let Some(line_number) = cx.editor.last_line_number {
1583− goto_line_impl(cx.editor, NonZeroUsize::new(line_number));
1584− let (view, doc) = current!(cx.editor);
1585− view.ensure_cursor_in_view(doc, line_number);
1586− cx.editor.last_line_number = None;
1590 PromptEvent::Validate => {
1611 PromptEvent::Validate => {
1591 ensure!(!args.is_empty(), "Line number required");
1612 ensure!(!args.is_empty(), "Line number required");
1592− cx.editor.last_line_number = None;
1613+
1593− }
1614+ // If we are invoked directly via a keybinding, Validate is
1594− PromptEvent::Update => {
1615+ // sent without any prior Update events. Ensure the cursor
1595− if args.is_empty() {
1616+ // is moved to the appropriate location.
1596− if let Some(line_number) = cx.editor.last_line_number {
1617+ update_goto_line_number_preview(cx, args)?;
1597− // When a user hits backspace and there are no numbers left,
1618+
1598− // we can bring them back to their original line
1619+ let last_selection = cx
1599− goto_line_impl(cx.editor, NonZeroUsize::new(line_number));
1620+ .editor
1600− let (view, doc) = current!(cx.editor);
1621+ .last_selection
1601− view.ensure_cursor_in_view(doc, line_number);
1622+ .take()
1602− cx.editor.last_line_number = None;
1623+ .expect("update_goto_line_number_preview should always set last_selection");
1606 let (view, doc) = current!(cx.editor);
1625 let (view, doc) = current!(cx.editor);
1607− let text = doc.text().slice(..);
1626+ view.jumps.push((doc.id(), last_selection));
1608− let line = doc.selection(view.id).primary().cursor_line(text);
1609− cx.editor.last_line_number.get_or_insert(line + 1);
1629+ // When a user hits backspace and there are no numbers left,
1630+ // we can bring them back to their original selection. If they
1631+ // begin typing numbers again, we'll start a new preview session.
1632+ PromptEvent::Update if args.is_empty() => abort_goto_line_number_preview(cx),
1633+ PromptEvent::Update => update_goto_line_number_preview(cx, args)?,
1612− let line = args[0].parse::<usize>()?;
1635+
1613− goto_line_impl(cx.editor, NonZeroUsize::new(line));
1614− let (view, doc) = current!(cx.editor);
1615− view.ensure_cursor_in_view(doc, line);