diff --git a/src/ui/chat/tree.rs b/src/ui/chat/tree.rs index 95ae013..50737ad 100644 --- a/src/ui/chat/tree.rs +++ b/src/ui/chat/tree.rs @@ -169,6 +169,7 @@ impl> InnerTreeViewState { coming_from: id, parent, }; + self.correction = Some(Correction::MakeCursorVisible); } } KeyCode::Char('R') => { @@ -177,6 +178,7 @@ impl> InnerTreeViewState { coming_from: id, parent, }; + self.correction = Some(Correction::MakeCursorVisible); } } KeyCode::Char('t' | 'T') => { @@ -184,6 +186,7 @@ impl> InnerTreeViewState { coming_from: id, parent: None, }; + self.correction = Some(Correction::MakeCursorVisible); } _ => return false, } diff --git a/src/ui/chat/tree/layout.rs b/src/ui/chat/tree/layout.rs index 41317c6..8c33662 100644 --- a/src/ui/chat/tree/layout.rs +++ b/src/ui/chat/tree/layout.rs @@ -51,9 +51,9 @@ impl> InnerTreeViewState { } fn editor_block(&self, nick: &str, frame: &mut Frame, indent: usize) -> Block> { - let (widget, cursor_line) = widgets::editor::(frame, indent, nick, &self.editor); - let cursor_line = cursor_line as i32; - Block::new(frame, BlockId::Cursor, widget).focus(cursor_line..cursor_line + 1) + let (widget, cursor_row) = widgets::editor::(frame, indent, nick, &self.editor); + let cursor_row = cursor_row as i32; + Block::new(frame, BlockId::Cursor, widget).focus(cursor_row..cursor_row + 1) } fn pseudo_block(&self, nick: &str, frame: &mut Frame, indent: usize) -> Block> { @@ -319,7 +319,18 @@ impl> InnerTreeViewState { } fn scroll_so_cursor_is_visible(&self, frame: &mut Frame, blocks: &mut TreeBlocks) { - if !matches!(self.cursor, Cursor::Msg(_)) { + if !matches!( + self.cursor, + Cursor::Msg(_) + | Cursor::Editor { + parent: Some(_), + .. + } + | Cursor::Pseudo { + parent: Some(_), + .. + } + ) { // In all other cases, there is no need to make the cursor visible // since scrolling behaves differently enough. return; diff --git a/src/ui/chat/tree/widgets.rs b/src/ui/chat/tree/widgets.rs index 62408cd..286161b 100644 --- a/src/ui/chat/tree/widgets.rs +++ b/src/ui/chat/tree/widgets.rs @@ -77,7 +77,7 @@ pub fn editor( Indent::new(1, false).into(), Padding::new(Text::new(nick)).right(1).into(), ])), - Segment::new(editor).priority(1), + Segment::new(editor).priority(1).expanding(true), ]) .into(); diff --git a/src/ui/widgets/editor.rs b/src/ui/widgets/editor.rs index 2a555cf..e2a85a2 100644 --- a/src/ui/widgets/editor.rs +++ b/src/ui/widgets/editor.rs @@ -27,7 +27,7 @@ struct InnerEditorState { /// Width of the text when the editor was last rendered. /// /// Does not include additional column for cursor. - last_width: usize, + last_width: u16, } impl InnerEditorState { @@ -286,8 +286,9 @@ impl Editor { } pub fn cursor_row(&self, frame: &mut Frame) -> usize { - let width: usize = frame.size().width.into(); - let indices = frame.wrap(self.text.text(), width); + let width = self.state.lock().last_width; + let text_width = (width - 1) as usize; + let indices = frame.wrap(self.text.text(), text_width); let (row, _) = Self::wrapped_cursor(self.idx, &indices); row } @@ -324,5 +325,7 @@ impl Widget for Editor { for (i, line) in lines.into_iter().enumerate() { frame.write(Pos::new(0, i as i32), line); } + + self.state.lock().last_width = width; } }