From d085759361287afb12ad727352c09a8c21bc4c55 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 4 Jan 2024 07:48:00 +0000 Subject: [PATCH] Factor out feed extension code into a method of File. Mostly just because it's large and cumbersome and it's nice to keep the key-handling match cases short. --- src/file.rs | 63 +++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/file.rs b/src/file.rs index 5773a95..1042b7c 100644 --- a/src/file.rs +++ b/src/file.rs @@ -412,6 +412,38 @@ impl File { self.ensure_enough_rendered(); self.after_setting_pos(); } + + fn try_extend(&mut self, client: &mut Client) -> Result<(), ClientError> { + let action = match self.contents.source.try_extend(client) { + Ok(any_new) => { + self.rendered.remove(&self.contents.first_index()); + if let Some(i) = self.contents.extender_index() { + self.rendered.remove(&i); + } + + if !any_new { + // Can't extend this any further into the past + self.contents.extender = None; + if self.pos.item() < self.contents.origin { + self.coarsen_pos(); + if self.pos.item() < + self.contents.first_index() + { + self.pos = FilePosition::Coarse( + self.contents.first_index()); + } + } + } + + self.contents.update_items(client); + Ok(()) + } + Err(e) => Err(e), + }; + + self.ensure_enough_rendered(); + action + } } impl @@ -544,35 +576,10 @@ impl } Pr('0') | Home => { if self.at_top() && self.contents.extender.is_some() { - let action = match self.contents.source.try_extend(client) { - Ok(any_new) => { - self.rendered.remove(&self.contents.first_index()); - if let Some(i) = self.contents.extender_index() { - self.rendered.remove(&i); - } - - if !any_new { - // Can't extend this any further into the past - // FIXME: this is not tested yet - self.contents.extender = None; - if self.pos.item() < self.contents.origin { - self.coarsen_pos(); - if self.pos.item() < - self.contents.first_index() - { - self.pos = FilePosition::Coarse( - self.contents.first_index()); - } - } - } - - self.contents.update_items(client); - LogicalAction::Nothing - } + match self.try_extend(client) { + Ok(_) => LogicalAction::Nothing, Err(e) => LogicalAction::Error(e), - }; - self.ensure_enough_rendered(); - action + } } else { self.goto_top(); LogicalAction::Nothing -- 2.30.2