Fix editor cursor not being made visible
This commit is contained in:
parent
cfcc663169
commit
3ab73668ba
4 changed files with 25 additions and 8 deletions
|
|
@ -169,6 +169,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
coming_from: id,
|
||||
parent,
|
||||
};
|
||||
self.correction = Some(Correction::MakeCursorVisible);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('R') => {
|
||||
|
|
@ -177,6 +178,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
coming_from: id,
|
||||
parent,
|
||||
};
|
||||
self.correction = Some(Correction::MakeCursorVisible);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('t' | 'T') => {
|
||||
|
|
@ -184,6 +186,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
coming_from: id,
|
||||
parent: None,
|
||||
};
|
||||
self.correction = Some(Correction::MakeCursorVisible);
|
||||
}
|
||||
_ => return false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
}
|
||||
|
||||
fn editor_block(&self, nick: &str, frame: &mut Frame, indent: usize) -> Block<BlockId<M::Id>> {
|
||||
let (widget, cursor_line) = widgets::editor::<M>(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::<M>(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<BlockId<M::Id>> {
|
||||
|
|
@ -319,7 +319,18 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
}
|
||||
|
||||
fn scroll_so_cursor_is_visible(&self, frame: &mut Frame, blocks: &mut TreeBlocks<M::Id>) {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ pub fn editor<M: ChatMsg>(
|
|||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue