wip: system clipboard support

This commit is contained in:
Jeremy Wall 2025-04-09 00:10:01 -04:00
parent fbbdcb983f
commit 25a782bfed
2 changed files with 8 additions and 4 deletions

View File

@ -135,13 +135,13 @@ impl Book {
/// Construct a payload of (html, csv_text) for a sheet.
pub fn sheeet_to_clipboard_content(&self, sheet: u32) -> Result<(String, String), anyhow::Error> {
let rows = self.get_export_rows_for_sheet(sheet)?;
rows_to_clipboard_content(rows)
rows_to_clipboard_content(&rows)
}
/// Construct a payload of (html, csv_text) for the address range.
pub fn range_to_clipboard_content(&self, range: AddressRange) -> Result<(String, String), anyhow::Error> {
let rows = self.get_rows_for_range(&range).unwrap_or_default();
rows_to_clipboard_content(rows)
rows_to_clipboard_content(&rows)
}
/// Get rows for current sheet to export.
@ -722,14 +722,14 @@ impl Book {
}
}
fn rows_to_clipboard_content(rows: Vec<Vec<String>>) -> std::result::Result<(String, String), anyhow::Error> {
pub fn rows_to_clipboard_content(rows: &Vec<Vec<String>>) -> std::result::Result<(String, String), anyhow::Error> {
use htmf::prelude::*;
let table = table([]);
let mut writer = csv::Writer::from_writer(vec![]);
let mut table_rows = vec![];
for row in rows {
let table_row = tr([]);
writer.write_record(&row)?;
writer.write_record(row)?;
let mut row_cells = vec![];
for cell in row {
row_cells.push(td([]).with(text(cell)));

View File

@ -644,6 +644,7 @@ impl<'ws> Workspace<'ws> {
}
fn copy_range(&mut self, formatted: bool) -> Result<(), anyhow::Error> {
use arboard::Clipboard;
self.update_range_selection()?;
match &self.state.range_select.get_range() {
Some((start, end)) => {
@ -659,6 +660,9 @@ impl<'ws> Workspace<'ws> {
}
rows.push(cols);
}
let mut cb = Clipboard::new()?;
let (html, csv) = crate::book::rows_to_clipboard_content(&rows)?;
cb.set_html(html, Some(csv))?;
self.state.clipboard = Some(ClipboardContents::Range(rows));
}
None => {