mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-22 04:39:48 -04:00
wip: use system clipboard if nothing is in the regular cipboard
This commit is contained in:
parent
8a76a031cb
commit
f0a82ed2b0
@ -5,6 +5,7 @@ use crate::book::{self, AddressRange, Book};
|
|||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
|
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
|
||||||
|
use csv::StringRecord;
|
||||||
use ironcalc::base::{expressions::types::Area, Model};
|
use ironcalc::base::{expressions::types::Area, Model};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
@ -698,8 +699,13 @@ impl<'ws> Workspace<'ws> {
|
|||||||
let record = rec?;
|
let record = rec?;
|
||||||
let mut row = Vec::with_capacity(record.len());
|
let mut row = Vec::with_capacity(record.len());
|
||||||
for i in 0..record.len() {
|
for i in 0..record.len() {
|
||||||
row.push(String::from_utf8_lossy(record.get(i).expect("Unexpected failure to get cell row")).to_string());
|
row.push(
|
||||||
};
|
String::from_utf8_lossy(
|
||||||
|
record.get(i).expect("Unexpected failure to get cell row"),
|
||||||
|
)
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
rows.push(row);
|
rows.push(row);
|
||||||
}
|
}
|
||||||
Ok(rows)
|
Ok(rows)
|
||||||
@ -972,7 +978,34 @@ impl<'ws> Workspace<'ws> {
|
|||||||
self.book.evaluate();
|
self.book.evaluate();
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// NOOP
|
// Try to get from system clipboard
|
||||||
|
use arboard::Clipboard;
|
||||||
|
let mut cb = Clipboard::new()?;
|
||||||
|
let csv = cb.get_text()?;
|
||||||
|
let rdr = csv::Reader::from_reader(csv.as_bytes());
|
||||||
|
let records: Vec<Result<csv::StringRecord, csv::Error>> =
|
||||||
|
rdr.into_records().collect();
|
||||||
|
let Address { sheet, row, col } = self.book.location.clone();
|
||||||
|
let row_len = records.len();
|
||||||
|
for ri in 0..row_len {
|
||||||
|
let columns = &records[ri];
|
||||||
|
if let Ok(columns) = columns {
|
||||||
|
let col_len = columns.len();
|
||||||
|
for ci in 0..col_len {
|
||||||
|
self.book.update_cell(
|
||||||
|
&Address {
|
||||||
|
sheet,
|
||||||
|
row: ri + row,
|
||||||
|
col: ci + col,
|
||||||
|
},
|
||||||
|
columns
|
||||||
|
.get(ci)
|
||||||
|
.expect("Failed to get column value from csv")
|
||||||
|
.to_string(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.state.clipboard = None;
|
self.state.clipboard = None;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user