use crate::app::window_state::WindowState;
use par_term_terminal::ClipboardSlot;
impl WindowState {
pub(crate) fn toggle_clipboard_history(&mut self) {
if let Some(tab) = self.tab_manager.active_tab() {
let terminal = tab.read_terminal_handle();
if let Ok(term) = terminal.try_read() {
let mut all_entries = Vec::new();
all_entries.extend(term.get_clipboard_history(ClipboardSlot::Primary));
all_entries.extend(term.get_clipboard_history(ClipboardSlot::Clipboard));
all_entries.extend(term.get_clipboard_history(ClipboardSlot::Selection));
all_entries.sort_by_key(|e| std::cmp::Reverse(e.timestamp));
self.overlay_ui
.clipboard_history_ui
.update_entries(all_entries);
}
}
self.overlay_ui.clipboard_history_ui.toggle();
self.focus_state.needs_redraw = true;
log::debug!(
"Clipboard history UI toggled: {}",
self.overlay_ui.clipboard_history_ui.visible
);
}
pub(crate) fn paste_text(&mut self, text: &str) {
if self.config.load().selection.warn_paste_control_chars
&& crate::paste_transform::paste_contains_control_chars(text)
{
log::warn!(
"Clipboard paste content contained control characters (ESC, C0, C1) that were \
stripped before pasting to prevent terminal escape sequence injection. \
This may indicate the clipboard contains crafted or binary content. \
Set `warn_paste_control_chars: false` in config to suppress this warning."
);
crate::debug_info!(
"PASTE",
"SECURITY: paste content contained control chars — stripped before PTY write \
({} chars original)",
text.len(),
);
}
let text = crate::paste_transform::sanitize_paste_content(text);
if self.broadcast_paste(&text) {
return;
}
if self.paste_via_tmux(&text) {
return; }
if let Some(tab) = self.tab_manager.active_tab() {
use std::sync::Arc;
let terminal_clone = tab
.pane_manager
.as_ref()
.and_then(|pm| pm.focused_pane())
.map(|pane| Arc::clone(&pane.terminal))
.unwrap_or_else(|| Arc::clone(&tab.terminal));
let delay_ms = self.config.load().selection.paste_delay_ms;
self.runtime.spawn(async move {
let term = terminal_clone.read().await;
if delay_ms > 0 && text.contains('\n') {
let _ = term.paste_with_delay(&text, delay_ms).await;
} else {
let _ = term.paste(&text);
}
log::debug!("Pasted text ({} chars)", text.len());
});
}
}
}