diff --git a/crates/ratatui/src/editor.rs b/crates/ratatui/src/editor.rs index 71f9079..8e042e2 100644 --- a/crates/ratatui/src/editor.rs +++ b/crates/ratatui/src/editor.rs @@ -111,6 +111,14 @@ impl Editor { self.text.paste() } + pub fn yank_text(&self) -> String { + self.text.yank_text() + } + + pub fn set_yank_text(&mut self, text: impl Into) { + self.text.set_yank_text(text); + } + pub fn select_all(&mut self) { self.text.select_all(); } @@ -138,7 +146,11 @@ impl Editor { } pub fn set_content(&mut self, lines: Vec) { + let yank = self.text.yank_text(); self.text = TextArea::new(lines); + if !yank.is_empty() { + self.text.set_yank_text(yank); + } self.completion.active = false; self.sample_finder.active = false; self.search.query.clear(); diff --git a/src/input/modal.rs b/src/input/modal.rs index aadd85c..4fe339a 100644 --- a/src/input/modal.rs +++ b/src/input/modal.rs @@ -343,13 +343,26 @@ pub(super) fn handle_modal_input(ctx: &mut InputContext, key: KeyEvent) -> Input editor.select_all(); } KeyCode::Char('c') if ctrl => { - editor.copy(); + ctx.app.editor_ctx.editor.copy(); + let text = ctx.app.editor_ctx.editor.yank_text(); + if let Some(clip) = &mut ctx.app.clipboard { + let _ = clip.set_text(text); + } } KeyCode::Char('x') if ctrl => { - editor.cut(); + ctx.app.editor_ctx.editor.cut(); + let text = ctx.app.editor_ctx.editor.yank_text(); + if let Some(clip) = &mut ctx.app.clipboard { + let _ = clip.set_text(text); + } } KeyCode::Char('v') if ctrl => { - editor.paste(); + if let Some(clip) = &mut ctx.app.clipboard { + if let Ok(text) = clip.get_text() { + ctx.app.editor_ctx.editor.set_yank_text(text); + } + } + ctx.app.editor_ctx.editor.paste(); } KeyCode::Left | KeyCode::Right | KeyCode::Up | KeyCode::Down if shift => { if !editor.is_selecting() {