@@ -277,7 +277,17 @@ impl Editor {
277 // Handle key events
277 // Handle key events
278 let mut event = reader.next().await;
278 let mut event = reader.next().await;
279 match event {
279 match event {
280− // TODO: handle resize events
280+ Some(Ok(Event::Resize(width, height))) => {
281+ self.size = (width, height);
282+ let area = Rect::new(0, 0, width, height);
283+ self.surface = Surface::empty(area);
284+ self.cache = Surface::empty(area);
286+ // TODO: simplistic ensure cursor in view for now
287+ self.ensure_cursor_in_view();
281 Some(Ok(Event::Key(KeyEvent {
291 Some(Ok(Event::Key(KeyEvent {
282 code: KeyCode::Char('q'),
292 code: KeyCode::Char('q'),
@@ -310,6 +320,9 @@ impl Editor {
310 } => helix_core::commands::insert_char(state, '\n'),
320 } => helix_core::commands::insert_char(state, '\n'),
311 _ => (), // skip
321 _ => (), // skip
323+ // TODO: simplistic ensure cursor in view for now
324+ self.ensure_cursor_in_view();
313 self.render();
326 self.render();
315 Mode::Normal => {
328 Mode::Normal => {
@@ -318,6 +331,9 @@ impl Editor {
318 // TODO: handle count other than 1
331 // TODO: handle count other than 1
319 command(state, 1);
332 command(state, 1);
334+ // TODO: simplistic ensure cursor in view for now
335+ self.ensure_cursor_in_view();
321 self.render();
337 self.render();
@@ -333,6 +349,26 @@ impl Editor {
352+ fn ensure_cursor_in_view(&mut self) {
353+ if let Some(state) = &mut self.state {
354+ let cursor = state.selection().cursor();
355+ let line = state.doc().char_to_line(cursor) as u16;
356+ let document_end = self.first_line + self.size.1.saturating_sub(1) - 1;
360+ // TODO: side scroll
362+ if line > document_end.saturating_sub(padding) {
364+ self.first_line += line - (document_end.saturating_sub(padding));
365+ } else if line < self.first_line + padding {
367+ self.first_line = line.saturating_sub(padding);
336 pub async fn run(&mut self) -> Result<(), Error> {
372 pub async fn run(&mut self) -> Result<(), Error> {
337 enable_raw_mode()?;
373 enable_raw_mode()?;