Add configurable Paste shortcuts. Helps to fix #130
This commit is contained in:
parent
615d60b17c
commit
182d44580a
|
@ -26,6 +26,7 @@ use std::fs::{File, create_dir_all};
|
|||
use std::io::Read;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use crate::event::KeyModifier;
|
||||
use crate::keyboard::PasteShortcut;
|
||||
use std::collections::{HashSet, HashMap};
|
||||
use log::{error};
|
||||
use std::fmt;
|
||||
|
@ -97,6 +98,9 @@ pub struct Configs {
|
|||
#[serde(default = "default_toggle_interval")]
|
||||
pub toggle_interval: u32,
|
||||
|
||||
#[serde(default)]
|
||||
pub paste_shortcut: PasteShortcut,
|
||||
|
||||
#[serde(default = "default_backspace_limit")]
|
||||
pub backspace_limit: i32,
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
|
|||
},
|
||||
BackendType::Clipboard => {
|
||||
self.clipboard_manager.set_clipboard(&target_string);
|
||||
self.keyboard_manager.trigger_paste();
|
||||
self.keyboard_manager.trigger_paste(&config.paste_shortcut);
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
|
|||
// Make sure the image exist beforehand
|
||||
if content.path.exists() {
|
||||
self.clipboard_manager.set_clipboard_image(&content.path);
|
||||
self.keyboard_manager.trigger_paste();
|
||||
self.keyboard_manager.trigger_paste(&config.paste_shortcut);
|
||||
}else{
|
||||
error!("Image not found in path: {:?}", content.path);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
use std::ffi::CString;
|
||||
use crate::bridge::linux::*;
|
||||
use super::PasteShortcut;
|
||||
use log::error;
|
||||
|
||||
pub struct LinuxKeyboardManager {
|
||||
}
|
||||
|
@ -36,16 +38,29 @@ impl super::KeyboardManager for LinuxKeyboardManager {
|
|||
// On linux this is not needed, so NOOP
|
||||
}
|
||||
|
||||
fn trigger_paste(&self) {
|
||||
fn trigger_paste(&self, shortcut: &PasteShortcut) {
|
||||
unsafe {
|
||||
let is_terminal = is_current_window_terminal();
|
||||
match shortcut {
|
||||
PasteShortcut::Default => {
|
||||
let is_terminal = is_current_window_terminal();
|
||||
|
||||
// Terminals use a different keyboard combination to paste from clipboard,
|
||||
// so we need to check the correct situation.
|
||||
if is_terminal == 0 {
|
||||
trigger_paste();
|
||||
}else{
|
||||
trigger_terminal_paste();
|
||||
// Terminals use a different keyboard combination to paste from clipboard,
|
||||
// so we need to check the correct situation.
|
||||
if is_terminal == 0 {
|
||||
trigger_paste();
|
||||
}else{
|
||||
trigger_terminal_paste();
|
||||
}
|
||||
},
|
||||
PasteShortcut::CtrlV => {
|
||||
trigger_paste();
|
||||
},
|
||||
PasteShortcut::CtrlShiftV => {
|
||||
trigger_terminal_paste();
|
||||
}
|
||||
_ => {
|
||||
error!("Linux backend does not support this Paste Shortcut, please open an issue on GitHub if you need it.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
use std::ffi::CString;
|
||||
use crate::bridge::macos::*;
|
||||
use super::PasteShortcut;
|
||||
use log::error;
|
||||
|
||||
pub struct MacKeyboardManager {
|
||||
}
|
||||
|
@ -39,9 +41,18 @@ impl super::KeyboardManager for MacKeyboardManager {
|
|||
}
|
||||
}
|
||||
|
||||
fn trigger_paste(&self) {
|
||||
fn trigger_paste(&self, shortcut: &PasteShortcut) {
|
||||
unsafe {
|
||||
trigger_paste();
|
||||
match shortcut {
|
||||
PasteShortcut::Default => {
|
||||
unsafe {
|
||||
trigger_paste();
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
error!("MacOS backend does not support this Paste Shortcut, please open an issue on GitHub if you need it.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use serde::{Serialize, Deserialize, Deserializer};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod windows;
|
||||
|
||||
|
@ -29,11 +31,26 @@ mod macos;
|
|||
pub trait KeyboardManager {
|
||||
fn send_string(&self, s: &str);
|
||||
fn send_enter(&self);
|
||||
fn trigger_paste(&self);
|
||||
fn trigger_paste(&self, shortcut: &PasteShortcut);
|
||||
fn delete_string(&self, count: i32);
|
||||
fn move_cursor_left(&self, count: i32);
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum PasteShortcut {
|
||||
Default, // Default one for the current system
|
||||
CtrlV, // Classic Ctrl+V shortcut
|
||||
CtrlShiftV, // Could be used to paste without formatting in many applications
|
||||
ShiftInsert, // Often used in Linux systems
|
||||
MetaV, // Corresponding to Win+V on Windows and Linux, CMD+V on macOS
|
||||
}
|
||||
|
||||
impl Default for PasteShortcut{
|
||||
fn default() -> Self {
|
||||
PasteShortcut::Default
|
||||
}
|
||||
}
|
||||
|
||||
// WINDOWS IMPLEMENTATION
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_manager() -> impl KeyboardManager {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
use widestring::{U16CString};
|
||||
use crate::bridge::windows::*;
|
||||
use super::PasteShortcut;
|
||||
use log::error;
|
||||
|
||||
pub struct WindowsKeyboardManager {
|
||||
}
|
||||
|
@ -44,9 +46,18 @@ impl super::KeyboardManager for WindowsKeyboardManager {
|
|||
}
|
||||
}
|
||||
|
||||
fn trigger_paste(&self) {
|
||||
fn trigger_paste(&self, shortcut: &PasteShortcut) {
|
||||
unsafe {
|
||||
trigger_paste();
|
||||
match shortcut {
|
||||
PasteShortcut::Default => {
|
||||
unsafe {
|
||||
trigger_paste();
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
error!("Windows backend does not support this Paste Shortcut, please open an issue on GitHub if you need it.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user