From 8fdf849090041b72f7c9fbb02ea8fa4bdef09cbd Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 31 Dec 2023 00:01:35 +0900 Subject: [PATCH] fix(editor): use local defined div_ceil --- src/editor.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 3f07423a9..45bcbd25b 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -997,9 +997,20 @@ impl Selecting { where C: ConversionEngine>, { - self.candidates(editor, dict) - .len() - .div_ceil(editor.options.candidates_per_page) + // MSRV: stable after rust 1.73 + fn div_ceil(lhs: usize, rhs: usize) -> usize { + let d = lhs / rhs; + let r = lhs % rhs; + if r > 0 && rhs > 0 { + d + 1 + } else { + d + } + } + div_ceil( + self.candidates(editor, dict).len(), + editor.options.candidates_per_page, + ) } fn select(mut self, editor: &mut Editor, n: usize) -> Transition where