From 1283081f8278843b6064ac9f1ec49479e027992a Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 2 Nov 2023 22:54:28 +0900 Subject: [PATCH] keep yanked lines in `Vec` --- src/textarea.rs | 46 +++++++++++++++++++++++++++++++++++++--------- tests/textarea.rs | 6 +++--- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/textarea.rs b/src/textarea.rs index 2008517..8270de5 100644 --- a/src/textarea.rs +++ b/src/textarea.rs @@ -17,6 +17,33 @@ use ratatui::text::Line; use tui::text::Spans as Line; use unicode_width::UnicodeWidthChar as _; +#[derive(Debug, Clone)] +enum YankText { + Piece(String), + Chunk(Vec), +} + +impl Default for YankText { + fn default() -> Self { + Self::Piece(String::new()) + } +} + +impl> From for YankText { + fn from(s: S) -> Self { + Self::Piece(s.into()) + } +} + +impl ToString for YankText { + fn to_string(&self) -> String { + match self { + Self::Piece(s) => s.clone(), + Self::Chunk(ss) => ss.join("\n"), + } + } +} + /// A type to manage state of textarea. /// /// [`TextArea::default`] creates an empty textarea. [`TextArea::new`] creates a textarea with given text lines. @@ -50,7 +77,7 @@ pub struct TextArea<'a> { line_number_style: Option