Solution: on_resize/ui_attach events must always update model, so model manipulation commands will always works right
This commit is contained in:
parent
0f4234a622
commit
08d8408adc
24
src/shell.rs
24
src/shell.rs
@ -88,7 +88,7 @@ impl State {
|
|||||||
let font_ctx = render::Context::new(FontDescription::from_string(DEFAULT_FONT_NAME));
|
let font_ctx = render::Context::new(FontDescription::from_string(DEFAULT_FONT_NAME));
|
||||||
|
|
||||||
State {
|
State {
|
||||||
model: UiModel::new(1, 1),
|
model: UiModel::empty(),
|
||||||
color_model: ColorModel::new(),
|
color_model: ColorModel::new(),
|
||||||
nvim: Rc::new(RefCell::new(NeovimClient::new())),
|
nvim: Rc::new(RefCell::new(NeovimClient::new())),
|
||||||
cur_attrs: None,
|
cur_attrs: None,
|
||||||
@ -135,6 +135,16 @@ impl State {
|
|||||||
self.nvim.clone()
|
self.nvim.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn start_init(&self) -> bool {
|
||||||
|
let mut nvim = self.nvim.borrow_mut();
|
||||||
|
if nvim.is_uninitialized() {
|
||||||
|
nvim.set_in_progress();
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_detach_cb<F>(&mut self, cb: Option<F>)
|
pub fn set_detach_cb<F>(&mut self, cb: Option<F>)
|
||||||
where
|
where
|
||||||
F: FnMut() + Send + 'static,
|
F: FnMut() + Send + 'static,
|
||||||
@ -791,12 +801,10 @@ fn draw_initializing(state: &State, ctx: &cairo::Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_nvim(state_ref: &Arc<UiMutex<State>>) {
|
fn init_nvim(state_ref: &Arc<UiMutex<State>>) {
|
||||||
let state = state_ref.borrow_mut();
|
let mut state = state_ref.borrow_mut();
|
||||||
let mut nvim = state.nvim.borrow_mut();
|
if state.start_init() {
|
||||||
if nvim.is_uninitialized() {
|
|
||||||
nvim.set_in_progress();
|
|
||||||
|
|
||||||
let (cols, rows) = state.calc_nvim_size();
|
let (cols, rows) = state.calc_nvim_size();
|
||||||
|
state.model = UiModel::new(rows as u64, cols as u64);
|
||||||
state.resize_state.set(
|
state.resize_state.set(
|
||||||
ResizeState::NvimResizeRequest(cols, rows),
|
ResizeState::NvimResizeRequest(cols, rows),
|
||||||
);
|
);
|
||||||
@ -830,7 +838,9 @@ impl RedrawEvents for State {
|
|||||||
|
|
||||||
fn on_resize(&mut self, columns: u64, rows: u64) -> RepaintMode {
|
fn on_resize(&mut self, columns: u64, rows: u64) -> RepaintMode {
|
||||||
match self.resize_state.get() {
|
match self.resize_state.get() {
|
||||||
ResizeState::NvimResizeTimer(..) => (),
|
ResizeState::NvimResizeTimer(..) => {
|
||||||
|
self.model = UiModel::new(rows, columns);
|
||||||
|
},
|
||||||
ResizeState::Wait |
|
ResizeState::Wait |
|
||||||
ResizeState::NvimResizeRequest(..) => {
|
ResizeState::NvimResizeRequest(..) => {
|
||||||
if self.model.columns != columns as usize || self.model.rows != rows as usize {
|
if self.model.columns != columns as usize || self.model.rows != rows as usize {
|
||||||
|
@ -41,6 +41,20 @@ impl UiModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn empty() -> UiModel {
|
||||||
|
UiModel {
|
||||||
|
columns: 0,
|
||||||
|
rows: 0,
|
||||||
|
cur_row: 0,
|
||||||
|
cur_col: 0,
|
||||||
|
model: Box::new([]),
|
||||||
|
top: 0,
|
||||||
|
bot: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn model(&self) -> &[Line] {
|
pub fn model(&self) -> &[Line] {
|
||||||
&self.model
|
&self.model
|
||||||
|
Loading…
Reference in New Issue
Block a user