From 7033e04d18da7f0dd4d7a2409dc1c6b7b6534639 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 6 Jun 2024 14:37:18 +0200 Subject: [PATCH] =?UTF-8?q?fix=20vec2list=20projection:=20reset=20len=20to?= =?UTF-8?q?=200=20on=20=1B[H=1B[2J=1B[3J?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/projection/reverse_list.rs | 14 +++++--------- src/projection/vec2list.rs | 1 + src/view/port.rs | 2 -- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/projection/reverse_list.rs b/src/projection/reverse_list.rs index c020233..d0b78ff 100644 --- a/src/projection/reverse_list.rs +++ b/src/projection/reverse_list.rs @@ -78,24 +78,20 @@ where Item: Clone + Send + Sync + 'static, if let Some(v) = self.src_view.as_ref() { self.end = v.len().unwrap(); for idx in 0 .. self.end { - if idx < self.end { - let val = v.get( &(self.end - idx - 1) ).unwrap(); - self.cast.notify(&ListDiff::Insert{ idx: idx, val }); - } + let val = v.get( &(self.end - idx - 1) ).unwrap(); + self.cast.notify(&ListDiff::Insert{ idx: idx, val }); } + } else { + self.end = 0; } } fn notify(&mut self, msg: &ListDiff) { - /* todo optimize - */ - //let len = self.src_view.len().unwrap(); - self.cast.notify(&match msg { ListDiff::Clear => { self.end = 0; ListDiff::Clear - }, + } ListDiff::Remove(mut idx) => { self.end -= 1; idx = self.end - idx; diff --git a/src/projection/vec2list.rs b/src/projection/vec2list.rs index febf290..1026fb4 100644 --- a/src/projection/vec2list.rs +++ b/src/projection/vec2list.rs @@ -67,6 +67,7 @@ where fn notify(&mut self, diff: &VecDiff) { match diff { VecDiff::Clear => { + self.cur_len = 0; self.cast.notify(&ListDiff::Clear); } VecDiff::Push(val) => { diff --git a/src/view/port.rs b/src/view/port.rs index 3dac40d..25d045d 100644 --- a/src/view/port.rs +++ b/src/view/port.rs @@ -107,8 +107,6 @@ where V::Msg: Clone pub fn attach_to_port(&self, other_port: ViewPort) { self.set_view( other_port.view.read().unwrap().clone() ); other_port.add_observer( self.cast.clone() ); - // todo: forward reset() ? - self.update_hooks.write().unwrap().clear(); self.add_update_hook( Arc::new(other_port) ); }