From 02408a3dd6080ff8734632a697721343a1beb566 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Tue, 9 Nov 2021 10:31:01 +0800 Subject: [PATCH 1/6] accept count for goto_window also fix view is not fullfilled issue --- helix-term/src/commands.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 245fbe4ee44b..b174a4cc0a31 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -581,21 +581,29 @@ fn goto_first_nonwhitespace(cx: &mut Context) { } fn goto_window(cx: &mut Context, align: Align) { + let count = cx.count.map(|_| cx.count() - 1); let (view, doc) = current!(cx.editor); let height = view.inner_area().height as usize; + // respect user given count if any // - 1 so we have at least one gap in the middle. // a height of 6 with padding of 3 on each side will keep shifting the view back and forth // as we type - let scrolloff = cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2); + let scrolloff = + count.unwrap_or_else(|| cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2)); let last_line = view.last_line(doc); let line = match align { Align::Top => (view.offset.row + scrolloff), - Align::Center => (view.offset.row + (height / 2)), - Align::Bottom => last_line.saturating_sub(scrolloff), + // the last line might far above height, so use content middle if the view is not fullfilled + Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)), + // the last line might far above height, so se use last line if the view is not fullfilled + Align::Bottom => std::cmp::min( + last_line, + (view.offset.row + height - 1).saturating_sub(scrolloff), + ), } .min(last_line.saturating_sub(scrolloff)); From 26ce99a448dd261b132c23de13c60e565ca106ff Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Tue, 9 Nov 2021 10:38:58 +0800 Subject: [PATCH 2/6] fix fulfilled mispell --- helix-term/src/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b174a4cc0a31..878ff75c93a6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -597,9 +597,9 @@ fn goto_window(cx: &mut Context, align: Align) { let line = match align { Align::Top => (view.offset.row + scrolloff), - // the last line might far above height, so use content middle if the view is not fullfilled + // the last line might far above height, so use content middle if the view is not fulfilled Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)), - // the last line might far above height, so se use last line if the view is not fullfilled + // the last line might far above height, so se use last line if the view is not fulfilled Align::Bottom => std::cmp::min( last_line, (view.offset.row + height - 1).saturating_sub(scrolloff), From 93e8774d08c556c4289f498bc766bdf0682e3003 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 15 Nov 2021 09:03:21 +0800 Subject: [PATCH 3/6] Update helix-term/src/commands.rs Co-authored-by: Ivan Tham --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4f23caba595f..73704bbc18d4 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -581,7 +581,7 @@ fn goto_first_nonwhitespace(cx: &mut Context) { } fn goto_window(cx: &mut Context, align: Align) { - let count = cx.count.map(|_| cx.count() - 1); + let count = cx.count(); let (view, doc) = current!(cx.editor); let height = view.inner_area().height as usize; From a58eb04d63a7178e19527a9b53b768e66953a340 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 15 Nov 2021 09:03:21 +0800 Subject: [PATCH 4/6] Update helix-term/src/commands.rs Co-authored-by: Ivan Tham --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 73704bbc18d4..e3e8deb5e681 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -581,7 +581,7 @@ fn goto_first_nonwhitespace(cx: &mut Context) { } fn goto_window(cx: &mut Context, align: Align) { - let count = cx.count(); + let count = cx.count() - 1; let (view, doc) = current!(cx.editor); let height = view.inner_area().height as usize; From 8960c70654a5c434410b74071cd21f9d63bd43ef Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Mon, 15 Nov 2021 12:05:19 +0800 Subject: [PATCH 5/6] fix merge issue --- helix-term/src/commands.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e3e8deb5e681..2a711811d08b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -590,22 +590,17 @@ fn goto_window(cx: &mut Context, align: Align) { // - 1 so we have at least one gap in the middle. // a height of 6 with padding of 3 on each side will keep shifting the view back and forth // as we type - let scrolloff = - count.unwrap_or_else(|| cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2)); + let scrolloff = cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2); let last_line = view.last_line(doc); let line = match align { - Align::Top => (view.offset.row + scrolloff), - // the last line might far above height, so use content middle if the view is not fulfilled + Align::Top => (view.offset.row + scrolloff + count), Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)), - // the last line might far above height, so se use last line if the view is not fulfilled - Align::Bottom => std::cmp::min( - last_line, - (view.offset.row + height - 1).saturating_sub(scrolloff), - ), + Align::Bottom => last_line.saturating_sub((scrolloff + count).min(last_line)), } - .min(last_line.saturating_sub(scrolloff)); + .min((view.offset.row + height - 1).saturating_sub(scrolloff)) + .max(view.offset.row + scrolloff); let pos = doc.text().line_to_char(line); From cc393df2368d4e9becb1caffc90dd29721a85bd8 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Mon, 22 Nov 2021 20:21:07 +0800 Subject: [PATCH 6/6] revert line computation logic --- helix-term/src/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e332d4ffb9f0..318d0428d044 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -642,9 +642,9 @@ fn goto_window(cx: &mut Context, align: Align) { let line = match align { Align::Top => (view.offset.row + scrolloff + count), Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)), - Align::Bottom => last_line.saturating_sub((scrolloff + count).min(last_line)), + Align::Bottom => last_line.saturating_sub(scrolloff + count), } - .min((view.offset.row + height - 1).saturating_sub(scrolloff)) + .min(last_line.saturating_sub(scrolloff)) .max(view.offset.row + scrolloff); let pos = doc.text().line_to_char(line);