correction + regexp
This commit is contained in:
53
src/app.rs
53
src/app.rs
@ -9,6 +9,9 @@ use std::time::{Duration, Instant};
|
||||
use syntect::highlighting::ThemeSet;
|
||||
use syntect::parsing::SyntaxSet;
|
||||
|
||||
const PREVIEW_MAX_WIDTH: u32 = 1280;
|
||||
const PREVIEW_MAX_HEIGHT: u32 = 720;
|
||||
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub enum Mode {
|
||||
Normal,
|
||||
@ -32,7 +35,7 @@ pub struct App {
|
||||
pub list_state: ListState,
|
||||
pub input_buffer: String,
|
||||
pub should_quit: bool,
|
||||
pub undo_stack: Vec<(usize, HistoryItem)>,
|
||||
pub undo_stack: Vec<HistoryItem>,
|
||||
pub current_image: Option<protocol::StatefulProtocol>,
|
||||
pub last_selected_index: Option<usize>,
|
||||
pub picker: Picker,
|
||||
@ -223,7 +226,8 @@ impl App {
|
||||
if let Some(i) = self.list_state.selected() {
|
||||
if i < self.filtered_items.len() {
|
||||
let item = self.filtered_items.remove(i);
|
||||
self.undo_stack.push((i, item.clone()));
|
||||
// On stocke juste l'item (plus l'index filtré qui était faux)
|
||||
self.undo_stack.push(item.clone());
|
||||
self.all_items.retain(|x| x.content != item.content);
|
||||
|
||||
let new_sel = if self.filtered_items.is_empty() {
|
||||
@ -240,22 +244,25 @@ impl App {
|
||||
}
|
||||
|
||||
pub fn undo_delete(&mut self) {
|
||||
if let Some((i, item)) = self.undo_stack.pop() {
|
||||
if let Some(item) = self.undo_stack.pop() {
|
||||
ipc::add_entry(item.content.clone());
|
||||
let pos = i.min(self.all_items.len());
|
||||
self.all_items.insert(pos, item.clone());
|
||||
|
||||
if let Some(new_items) = ipc::fetch_history(200) {
|
||||
self.all_items = new_items;
|
||||
} else {
|
||||
self.all_items.insert(0, item.clone());
|
||||
}
|
||||
|
||||
self.update_search();
|
||||
let sel = self
|
||||
|
||||
if let Some(pos) = self
|
||||
.filtered_items
|
||||
.iter()
|
||||
.position(|x| x.content == item.content)
|
||||
.unwrap_or(0)
|
||||
.min(self.filtered_items.len().saturating_sub(1));
|
||||
self.list_state.select(if self.filtered_items.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(sel)
|
||||
});
|
||||
{
|
||||
self.list_state.select(Some(pos));
|
||||
self.last_selected_index = None;
|
||||
}
|
||||
}
|
||||
self.update_preview();
|
||||
}
|
||||
@ -317,7 +324,6 @@ impl App {
|
||||
Some(key) => key.encrypt(&content),
|
||||
None => return,
|
||||
};
|
||||
|
||||
self.crypto = None;
|
||||
|
||||
match encrypt_result {
|
||||
@ -343,7 +349,6 @@ impl App {
|
||||
Some(key) => key.decrypt(&content),
|
||||
None => return,
|
||||
};
|
||||
|
||||
self.crypto = None;
|
||||
|
||||
match decrypt_result {
|
||||
@ -373,7 +378,6 @@ impl App {
|
||||
Some(key) => key.decrypt(&content),
|
||||
None => return,
|
||||
};
|
||||
|
||||
self.crypto = None;
|
||||
|
||||
match decrypt_result {
|
||||
@ -412,14 +416,10 @@ impl App {
|
||||
self.crypto = None;
|
||||
self.pending_action = Some(PendingAction::PasteEncrypted);
|
||||
self.enter_password_mode();
|
||||
} else if ipc::set_clipboard(content) {
|
||||
self.should_quit = true;
|
||||
} else {
|
||||
if ipc::set_clipboard(content) {
|
||||
self.should_quit = true;
|
||||
} else {
|
||||
self.set_error(
|
||||
"Impossible de définir le presse-papier (daemon injoignable ?)".into(),
|
||||
);
|
||||
}
|
||||
self.set_error("Impossible de définir le presse-papier (daemon injoignable ?)".into());
|
||||
}
|
||||
}
|
||||
|
||||
@ -455,6 +455,13 @@ impl App {
|
||||
let path = dirs.data_dir().join("images").join(&content);
|
||||
if path.exists() {
|
||||
if let Ok(img) = image::open(&path) {
|
||||
let img = if img.width() > PREVIEW_MAX_WIDTH
|
||||
|| img.height() > PREVIEW_MAX_HEIGHT
|
||||
{
|
||||
img.thumbnail(PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT)
|
||||
} else {
|
||||
img
|
||||
};
|
||||
self.current_image = Some(self.picker.new_resize_protocol(img));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user