1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Browser Hotkey Conflicts (#1697)

* code hotkey to N, move superscript hotkey to Y

ctrl A S D F G H are all taken, CTRL Q is traditionally to remove formatting and should be reserved for that. CTRL W E R T are also all taken. CTRL Z X C V are taken so all of the first 4/5 keys of each row except Q are inaccessible.

* strike through conflict, update text

* fixed underline command

* added ALTSHIFT, browser documentation

* underline ALTSHIFT Q

it leaves the Q character which is considered a bug but before this pull underline was not working entirely so this is progress

* update text

* ALTSHIFT is treated as a command

* added eighth command, ALTSHIFT+W adds two spaces

* CTRL+Y to toggle case on text_edit demo

* better code

* Revised Menu

* fix dead link

* Update lib.rs

* Update easy_mark_editor.rs

* Update egui/src/data/input.rs

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* update

* reverted variables used for debugging

* fixed labels hotkey conflict

* comments

* fmt

* cargo fmt

* Nice hotkey menu

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Thomas Hansen
2022-07-03 09:25:35 -04:00
committed by GitHub
parent 14ae4b24a7
commit cb9bc8698d
5 changed files with 69 additions and 37 deletions

View File

@@ -62,12 +62,12 @@ impl super::View for TextEdit {
ui.add_enabled(
anything_selected,
egui::Label::new("Press ctrl+T to toggle the case of selected text (cmd+T on Mac)"),
egui::Label::new("Press ctrl+Y to toggle the case of selected text (cmd+Y on Mac)"),
);
if ui
.input_mut()
.consume_key(egui::Modifiers::COMMAND, egui::Key::T)
.consume_key(egui::Modifiers::COMMAND, egui::Key::Y)
{
if let Some(text_cursor_range) = output.cursor_range {
use egui::TextBuffer as _;

View File

@@ -45,15 +45,12 @@ impl EasyMarkEditor {
pub fn ui(&mut self, ui: &mut egui::Ui) {
egui::Grid::new("controls").show(ui, |ui| {
let _ = ui.button("Hotkeys").on_hover_ui(nested_hotkeys_ui);
ui.checkbox(&mut self.show_rendered, "Show rendered");
ui.checkbox(&mut self.highlight_editor, "Highlight editor");
egui::reset_button(ui, self);
ui.end_row();
ui.checkbox(&mut self.show_rendered, "Show rendered");
});
ui.label("Use ctrl/cmd + key to toggle: B: *strong* C: `code` I: /italics/ L: $lowered$ R: ^raised^ S: ~strikethrough~ U: _underline_");
ui.separator();
if self.show_rendered {
@@ -109,20 +106,43 @@ impl EasyMarkEditor {
}
}
fn nested_hotkeys_ui(ui: &mut egui::Ui) {
let _ = ui.label("CTRL+B *bold*");
let _ = ui.label("CTRL+N `code`");
let _ = ui.label("CTRL+I /italics/");
let _ = ui.label("CTRL+L $subscript$");
let _ = ui.label("CTRL+Y ^superscript^");
let _ = ui.label("ALT+SHIFT+Q ~strikethrough~");
let _ = ui.label("ALT+SHIFT+W _underline_");
let _ = ui.label("ALT+SHIFT+E two spaces"); // Placeholder for tab indent
}
fn shortcuts(ui: &Ui, code: &mut dyn TextBuffer, ccursor_range: &mut CCursorRange) -> bool {
let mut any_change = false;
for (key, surrounding) in [
(Key::B, "*"), // *bold*
(Key::C, "`"), // `code`
(Key::I, "/"), // /italics/
(Key::L, "$"), // $subscript$
(Key::R, "^"), // ^superscript^
(Key::S, "~"), // ~strikethrough~
(Key::U, "_"), // _underline_
if ui
.input_mut()
.consume_key(egui::Modifiers::ALT_SHIFT, Key::E)
{
// This is a placeholder till we can indent the active line
any_change = true;
let [primary, _secondary] = ccursor_range.sorted();
let advance = code.insert_text(" ", primary.index);
ccursor_range.primary.index += advance;
ccursor_range.secondary.index += advance;
}
for (modifier, key, surrounding) in [
(egui::Modifiers::COMMAND, Key::B, "*"), // *bold*
(egui::Modifiers::COMMAND, Key::N, "`"), // `code`
(egui::Modifiers::COMMAND, Key::I, "/"), // /italics/
(egui::Modifiers::COMMAND, Key::L, "$"), // $subscript$
(egui::Modifiers::COMMAND, Key::Y, "^"), // ^superscript^
(egui::Modifiers::ALT_SHIFT, Key::Q, "~"), // ~strikethrough~
(egui::Modifiers::ALT_SHIFT, Key::W, "_"), // _underline_
] {
if ui.input_mut().consume_key(egui::Modifiers::COMMAND, key) {
toggle_surrounding(code, ccursor_range, surrounding);
if ui.input_mut().consume_key(modifier, key) {
any_change = true;
toggle_surrounding(code, ccursor_range, surrounding);
};
}
any_change
@@ -222,6 +242,11 @@ The style characters are chosen to be similar to what they are representing:
# TODO
- Sub-headers (`## h2`, `### h3` etc)
- Hotkey Editor
- International keyboard algorithm for non-letter keys
- ALT+SHIFT+Num1 is not a functioning hotkey
- Tab Indent Increment/Decrement CTRL+], CTRL+[
- Images
- we want to be able to optionally specify size (width and\/or height)
- centering of images is very desirable