|
|
@ -1410,53 +1410,60 @@ fn tutor(
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn undo_goto_line_number_preview(cx: &mut compositor::Context) {
|
|
|
|
|
|
|
|
if cx.editor.goto_line_number_preview {
|
|
|
|
|
|
|
|
log::info!("undoing goto_line_number preview, jumping backwards");
|
|
|
|
|
|
|
|
// if let Some(line_number) = cx.editor.last_line_number {
|
|
|
|
|
|
|
|
// goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line_number));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the jump we added during the preview session.
|
|
|
|
|
|
|
|
jump_backward_impl(cx.editor, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
// view.ensure_cursor_in_view(doc, line_number);
|
|
|
|
|
|
|
|
cx.editor.goto_line_number_preview = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn start_goto_line_number_preview(cx: &mut compositor::Context) {
|
|
|
|
|
|
|
|
if !cx.editor.goto_line_number_preview {
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Allow the user to jump back to the previous location before invoking
|
|
|
|
|
|
|
|
// `goto_line_number`.
|
|
|
|
|
|
|
|
push_jump(view, doc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cx.editor.goto_line_number_preview = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn goto_line_number(
|
|
|
|
pub(super) fn goto_line_number(
|
|
|
|
cx: &mut compositor::Context,
|
|
|
|
cx: &mut compositor::Context,
|
|
|
|
args: &[Cow<str>],
|
|
|
|
args: &[Cow<str>],
|
|
|
|
event: PromptEvent,
|
|
|
|
event: PromptEvent,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
match event {
|
|
|
|
match event {
|
|
|
|
PromptEvent::Abort => {
|
|
|
|
PromptEvent::Abort => undo_goto_line_number_preview(cx),
|
|
|
|
if let Some(line_number) = cx.editor.last_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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PromptEvent::Validate => {
|
|
|
|
PromptEvent::Validate => {
|
|
|
|
ensure!(!args.is_empty(), "Line number required");
|
|
|
|
ensure!(!args.is_empty(), "Line number required");
|
|
|
|
|
|
|
|
cx.editor.goto_line_number_preview = false;
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
push_jump(view, doc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cx.editor.last_line_number = None;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PromptEvent::Update => {
|
|
|
|
PromptEvent::Update => {
|
|
|
|
if args.is_empty() {
|
|
|
|
|
|
|
|
if let Some(line_number) = cx.editor.last_line_number {
|
|
|
|
|
|
|
|
// When a user hits backspace and there are no numbers left,
|
|
|
|
// When a user hits backspace and there are no numbers left,
|
|
|
|
// we can bring them back to their original line
|
|
|
|
// we can bring them back to their original selection(s).
|
|
|
|
goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line_number));
|
|
|
|
if args.is_empty() {
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
undo_goto_line_number_preview(cx);
|
|
|
|
view.ensure_cursor_in_view(doc, line_number);
|
|
|
|
|
|
|
|
cx.editor.last_line_number = None;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !cx.editor.goto_line_number_preview {
|
|
|
|
|
|
|
|
start_goto_line_number_preview(cx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cx.editor.last_line_number.get_or_insert_with(|| {
|
|
|
|
let line = args[0].parse::<usize>()?;
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
|
|
|
|
let line = doc.selection(view.id).primary().cursor_line(text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
line + 1
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
let line = args[0].parse::<usize>()?;
|
|
|
|
|
|
|
|
view.ensure_cursor_in_view(doc, line);
|
|
|
|
view.ensure_cursor_in_view(doc, line);
|
|
|
|
goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line));
|
|
|
|
goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line));
|
|
|
|
}
|
|
|
|
}
|
|
|
|