From 7bc9a959f2e77f53274edda0f895855cd9595235 Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 8 Jul 2022 10:12:49 +0900 Subject: [PATCH] keep undo history on closing search box in editor example --- examples/editor.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/editor.rs b/examples/editor.rs index e807018..61f66b8 100644 --- a/examples/editor.rs +++ b/examples/editor.rs @@ -15,7 +15,7 @@ use tui::style::{Color, Modifier, Style}; use tui::text::{Span, Spans}; use tui::widgets::{Block, Borders, Paragraph}; use tui::Terminal; -use tui_textarea::{Input, Key, TextArea}; +use tui_textarea::{CursorMove, Input, Key, TextArea}; macro_rules! error { ($fmt: expr $(, $args:tt)*) => {{ @@ -46,9 +46,10 @@ impl<'a> SearchBox<'a> { fn close(&mut self) { self.open = false; - let block = self.textarea.block().unwrap().clone(); - self.textarea = TextArea::default(); - self.textarea.set_block(block); + // Remove input for next search. Do not recreate `self.textarea` instance to keep undo history so that users can + // restore previous input easily. + self.textarea.move_cursor(CursorMove::End); + self.textarea.delete_line_by_head(); } fn height(&self) -> u16 {