From ef4bdf5b1aefcab36c56a1b7e80507e6eed86805 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 22 Jan 2021 15:11:08 +0100 Subject: [PATCH] fix locks in StringInsertView --- src/string_editor.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/string_editor.rs b/src/string_editor.rs index 6dddd30..7458ae3 100644 --- a/src/string_editor.rs +++ b/src/string_editor.rs @@ -115,7 +115,7 @@ pub mod insert_view { _data_obs: Arc, Self>>>, cursor: Arc>, - data: Arc>, + data: Arc>>, cur_pos: usize, cast: Arc>> } @@ -130,16 +130,17 @@ pub mod insert_view { fn get(&self, pos: &Point2) -> Option { if pos.y == 0 && pos.x >= 0 { let i = pos.x as usize; - let len = self.data.len().unwrap_or(0); + let data = self.data.read().unwrap(); + let len = data.len().unwrap_or(0); if i < len+1 { return Some( - if i < self.cur_pos && i < len { - TerminalAtom::from(self.data.get(&i).unwrap()) + if i < self.cur_pos { + TerminalAtom::from(data.get(&i)?) } else if i == self.cur_pos { TerminalAtom::new('|', TerminalStyle::fg_color((200, 0, 0))) } else { - TerminalAtom::from(self.data.get(&(i-1)).unwrap()) + TerminalAtom::from(data.get(&(i - 1))?) } ); }