Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Added work around for ctrl+x/c keys.
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
mkrueger committed Feb 18, 2024
1 parent c81e20b commit d50b368
Showing 1 changed file with 41 additions and 31 deletions.
72 changes: 41 additions & 31 deletions src/ui/terminal_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use eframe::{
egui::{self, CursorIcon, PointerButton},
epaint::Vec2,
};
use egui::{ImageButton, RichText};
use egui::{Event, ImageButton, Modifiers, RichText};
use i18n_embed_fl::fl;
use icy_engine::{Position, Selection, TextPane};

Expand Down Expand Up @@ -379,39 +379,16 @@ impl MainWindow {
}
}

egui::Event::Cut => {
self.handle_key_press(ui, &response, egui::Key::X, Modifiers::CTRL);
}
egui::Event::Copy => {
self.handle_key_press(ui, &response, egui::Key::C, Modifiers::CTRL);
}
egui::Event::Key {
key, pressed: true, modifiers, ..
} => {
let im = self.screen_mode.get_input_mode();
let key_map = im.cur_map();
let mut key_code = key as u32;
if modifiers.ctrl || modifiers.command {
key_code |= icy_engine_egui::ui::CTRL_MOD;
}
if modifiers.shift {
key_code |= icy_engine_egui::ui::SHIFT_MOD;
}
for (k, m) in key_map {
if *k == key_code {
let mut print = true;
if let Some(con) = self.connection.lock().as_mut() {
if con.is_connected() {
let res = con.send(m.to_vec());
check_error!(self, res, true);
print = false;
}
}
if print {
for c in *m {
self.print_char(*c);
}
}
response.request_focus();

ui.input_mut(|i| i.consume_key(modifiers, key));
break;
}
}
self.handle_key_press(ui, &response, key, modifiers);
}
_ => {}
}
Expand Down Expand Up @@ -577,6 +554,39 @@ impl MainWindow {
}
}

fn handle_key_press(&mut self, ui: &mut egui::Ui, response: &egui::Response, key: egui::Key, modifiers: egui::Modifiers) {
let im = self.screen_mode.get_input_mode();
let key_map = im.cur_map();
let mut key_code = key as u32;
if modifiers.ctrl || modifiers.command {
key_code |= icy_engine_egui::ui::CTRL_MOD;
}
if modifiers.shift {
key_code |= icy_engine_egui::ui::SHIFT_MOD;
}
for (k, m) in key_map {
if *k == key_code {
let mut print = true;
if let Some(con) = self.connection.lock().as_mut() {
if con.is_connected() {
let res = con.send(m.to_vec());
check_error!(self, res, true);
print = false;
}
}
if print {
for c in *m {
self.print_char(*c);
}
}
response.request_focus();

ui.input_mut(|i| i.consume_key(modifiers, key));
break;
}
}
}

fn copy_to_clipboard(&mut self) {
let buffer_view = self.buffer_view.clone();
let mut l = buffer_view.lock();
Expand Down

0 comments on commit d50b368

Please sign in to comment.