Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/input/state/actions/action_board_pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use log::info;
use super::super::{InputState, UiToastKind};

impl InputState {
pub(super) fn handle_board_pages_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_board_pages_action(&mut self, action: Action) -> bool {
match action {
Action::ToggleWhiteboard => {
if self.boards.has_board(BOARD_ID_WHITEBOARD) {
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_capture_zoom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::input::{OutputFocusAction, ZoomAction};
use super::super::InputState;

impl InputState {
pub(super) fn handle_capture_zoom_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_capture_zoom_action(&mut self, action: Action) -> bool {
match action {
Action::CaptureFullScreen
| Action::CaptureActiveWindow
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::util;
use super::super::InputState;

impl InputState {
pub(super) fn handle_color_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_color_action(&mut self, action: Action) -> bool {
let Some(color) = action_color(action) else {
return false;
};
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::config::Action;
use log::info;

impl InputState {
pub(super) fn handle_core_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_core_action(&mut self, action: Action) -> bool {
match action {
Action::Exit => {
if self.try_cancel_active_interaction() {
Expand Down
45 changes: 2 additions & 43 deletions src/input/state/actions/action_dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,10 @@
use crate::config::Action;
use log::warn;

use super::super::{InputState, UiToastKind};
use super::super::{InputState, interaction};

impl InputState {
/// Handle an action triggered by a keybinding.
pub(crate) fn handle_action(&mut self, action: Action) {
if !matches!(
action,
Action::OpenContextMenu | Action::ToggleSelectionProperties
) {
self.close_properties_panel();
}

if matches!(action, Action::PickScreenColorDeprecated) {
warn!("Deprecated action pick_screen_color triggered; ignoring.");
self.set_ui_toast(
UiToastKind::Warning,
"Pick screen color was removed. Use the palette or paste a hex value.",
);
return;
}

if self.handle_core_action(action) {
return;
}
if self.handle_history_action(action) {
return;
}
if self.handle_selection_action(action) {
return;
}
if self.handle_tool_action(action) {
return;
}
if self.handle_board_pages_action(action) {
return;
}
if self.handle_ui_action(action) {
return;
}
if self.handle_color_action(action) {
return;
}
if self.handle_capture_zoom_action(action) {
return;
}
self.handle_preset_action(action);
let _ = interaction::route_action(self, action);
}
}
2 changes: 1 addition & 1 deletion src/input/state/actions/action_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::config::Action;
use super::super::InputState;

impl InputState {
pub(super) fn handle_history_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_history_action(&mut self, action: Action) -> bool {
match action {
Action::Undo => {
if let Some(action) = self.boards.active_frame_mut().undo_last() {
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::config::Action;
use super::super::InputState;

impl InputState {
pub(super) fn handle_preset_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_preset_action(&mut self, action: Action) -> bool {
match action {
Action::ApplyPreset1 => {
let _ = self.apply_preset(1);
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const KEYBOARD_NUDGE_SMALL: i32 = 8;
const KEYBOARD_NUDGE_LARGE: i32 = 32;

impl InputState {
pub(super) fn handle_selection_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_selection_action(&mut self, action: Action) -> bool {
match action {
Action::CopySelection => {
let copied = self.copy_selection();
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use log::info;
use super::super::InputState;

impl InputState {
pub(super) fn handle_tool_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_tool_action(&mut self, action: Action) -> bool {
match action {
Action::IncreaseThickness => {
self.nudge_thickness_for_active_tool(1.0);
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/action_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use log::info;
use super::super::{DrawingState, InputState, UiToastKind};

impl InputState {
pub(super) fn handle_ui_action(&mut self, action: Action) -> bool {
pub(in crate::input::state) fn handle_ui_action(&mut self, action: Action) -> bool {
match action {
Action::ToggleHelp => {
self.toggle_help_overlay();
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/help_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::input::events::Key;
use super::super::InputState;

impl InputState {
pub(super) fn handle_help_overlay_key(&mut self, key: Key) -> bool {
pub(in crate::input::state) fn handle_help_overlay_key(&mut self, key: Key) -> bool {
if !self.show_help {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/input/state/actions/key_press/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::input::events::Key;

pub(super) fn key_to_action_label(key: Key) -> Option<String> {
pub(in crate::input::state) fn key_to_action_label(key: Key) -> Option<String> {
match key {
Key::Char(c) => Some(c.to_string()),
Key::Escape => Some("Escape".to_string()),
Expand Down Expand Up @@ -28,7 +28,7 @@ pub(super) fn key_to_action_label(key: Key) -> Option<String> {
}
}

pub(super) fn fallback_unshifted_label(key: &str) -> Option<&'static str> {
pub(in crate::input::state) fn fallback_unshifted_label(key: &str) -> Option<&'static str> {
match key {
"!" => Some("1"),
"@" => Some("2"),
Expand Down
134 changes: 4 additions & 130 deletions src/input/state/actions/key_press/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
mod bindings;
pub(in crate::input::state) mod bindings;
mod panels;
mod text_input;

use crate::config::Action;
use crate::input::events::Key;

use super::super::{DrawingState, InputState};
use bindings::{fallback_unshifted_label, key_to_action_label};
use super::super::{DrawingState, InputState, interaction};

impl InputState {
fn handle_modifier_key_press(&mut self, key: Key) -> bool {
pub(in crate::input::state) fn handle_modifier_key_press(&mut self, key: Key) -> bool {
match key {
Key::Shift => self.modifiers.shift = true,
Key::Ctrl => self.modifiers.ctrl = true,
Expand All @@ -34,130 +32,6 @@ impl InputState {
/// - Help toggle (configurable)
/// - Modifier key tracking
pub fn on_key_press(&mut self, key: Key) {
// Tour takes highest priority when active
if self.tour_active && self.handle_tour_key(key) {
return;
}

// Command palette takes priority
if self.command_palette_open && self.handle_command_palette_key(key) {
return;
}

if self.show_help && self.handle_help_overlay_key(key) {
return;
}

if self.is_radial_menu_open() {
if self.handle_modifier_key_press(key) {
return;
}

if matches!(key, Key::Escape) {
self.close_radial_menu();
return;
}

if let Some(key_str) = key_to_action_label(key) {
let mapped_action = self.find_action(&key_str).or_else(|| {
if self.modifiers.shift {
fallback_unshifted_label(&key_str)
.and_then(|fallback| self.find_action(fallback))
} else {
None
}
});
if matches!(mapped_action, Some(Action::ToggleRadialMenu)) {
self.close_radial_menu();
}
}
return;
}

if self.is_color_picker_popup_open() && self.handle_color_picker_popup_key(key) {
return;
}

if self.is_context_menu_open() && self.handle_context_menu_key(key) {
return;
}

if self.is_board_picker_open() && self.handle_board_picker_key(key) {
return;
}

// Handle modifier keys first
if self.handle_modifier_key_press(key) {
return;
}

if self.is_properties_panel_open() {
let handled = self.handle_properties_panel_key(key);
if handled {
return;
}
return;
}

// Escape cancels pending board or page deletion
if matches!(key, Key::Escape) && self.has_pending_board_delete() {
self.cancel_pending_board_delete();
return;
}
if matches!(key, Key::Escape) && self.has_pending_page_delete() {
self.cancel_pending_page_delete();
return;
}

if matches!(key, Key::Escape)
&& matches!(self.state, DrawingState::Idle)
&& self.has_selection()
{
let bounds = self.selection_bounding_box(self.selected_shape_ids());
self.clear_selection();
self.mark_selection_dirty_region(bounds);
self.needs_redraw = true;
return;
}

if matches!(&self.state, DrawingState::TextInput { .. }) {
self.handle_text_input_key(key);
return;
}

// Handle Escape in Drawing state for canceling
if matches!(key, Key::Escape)
&& let DrawingState::Drawing { .. } = &self.state
&& let Some(Action::Exit) = self.find_action("Escape")
{
self.try_cancel_active_interaction();
return;
}

// Convert key to string for action lookup
let Some(key_str) = key_to_action_label(key) else {
return;
};

// Look up action based on keybinding
if let Some(action) = self.find_action(&key_str) {
self.handle_action(action);
return;
}
if self.modifiers.shift
&& let Some(fallback) = fallback_unshifted_label(&key_str)
&& let Some(action) = self.find_action(fallback)
{
self.handle_action(action);
return;
}

if matches!(key, Key::Return)
&& !self.modifiers.ctrl
&& !self.modifiers.shift
&& !self.modifiers.alt
&& matches!(self.state, DrawingState::Idle)
&& self.edit_selected_text()
{}
let _ = interaction::route_key_press(self, key);
}
}
8 changes: 4 additions & 4 deletions src/input/state/actions/key_press/panels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::input::state::InputState;
const PROPERTIES_PANEL_COARSE_STEP: i32 = 5;

impl InputState {
pub(super) fn handle_color_picker_popup_key(&mut self, key: Key) -> bool {
pub(in crate::input::state) fn handle_color_picker_popup_key(&mut self, key: Key) -> bool {
if !self.is_color_picker_popup_open() {
return false;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ impl InputState {
}
}

pub(super) fn handle_board_picker_key(&mut self, key: Key) -> bool {
pub(in crate::input::state) fn handle_board_picker_key(&mut self, key: Key) -> bool {
if !self.is_board_picker_open() {
return false;
}
Expand Down Expand Up @@ -314,7 +314,7 @@ impl InputState {
}
}

pub(super) fn handle_properties_panel_key(&mut self, key: Key) -> bool {
pub(in crate::input::state) fn handle_properties_panel_key(&mut self, key: Key) -> bool {
let adjust_step = if self.modifiers.shift {
PROPERTIES_PANEL_COARSE_STEP
} else {
Expand All @@ -338,7 +338,7 @@ impl InputState {
}
}

pub(super) fn handle_context_menu_key(&mut self, key: Key) -> bool {
pub(in crate::input::state) fn handle_context_menu_key(&mut self, key: Key) -> bool {
match key {
Key::Escape => {
self.close_context_menu();
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/key_press/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::bindings::{fallback_unshifted_label, key_to_action_label};
const MAX_TEXT_LENGTH: usize = 10_000;

impl InputState {
pub(super) fn handle_text_input_key(&mut self, key: Key) {
pub(in crate::input::state) fn handle_text_input_key(&mut self, key: Key) {
let should_check_actions = match key {
// Special keys always check for actions
Key::Escape
Expand Down
2 changes: 1 addition & 1 deletion src/input/state/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ mod action_selection;
mod action_tools;
mod action_ui;
mod help_overlay;
mod key_press;
pub(in crate::input::state) mod key_press;
mod key_release;
Loading
Loading