From 31a5164f76f3e3ba38281b3233e2ff52fa38a498 Mon Sep 17 00:00:00 2001 From: Bryan Tan Date: Sun, 20 Jun 2021 14:57:18 -0700 Subject: [PATCH] Simplify KeyboardInputHandler logic --- src/gui/inputdevices/KeyboardInputHandler.cpp | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/gui/inputdevices/KeyboardInputHandler.cpp b/src/gui/inputdevices/KeyboardInputHandler.cpp index a612a3f9..0e1cf30c 100644 --- a/src/gui/inputdevices/KeyboardInputHandler.cpp +++ b/src/gui/inputdevices/KeyboardInputHandler.cpp @@ -21,29 +21,25 @@ auto KeyboardInputHandler::handleImpl(InputEvent const& event) -> bool { EditSelection* selection = xournal->selection; if (selection) { int d = 3; - - if ((keyEvent->state & GDK_MOD1_MASK) || (keyEvent->state & GDK_SHIFT_MASK)) { - if (keyEvent->state & GDK_MOD1_MASK) { - d = 1; - } else { - d = 20; - } + if (keyEvent->state & GDK_MOD1_MASK) { + d = 1; + } else if (keyEvent->state & GDK_SHIFT_MASK) { + d = 20; } + int xdir = 0; + int ydir = 0; if (keyEvent->keyval == GDK_KEY_Left) { - selection->moveSelection(-d, 0); - return true; - } - if (keyEvent->keyval == GDK_KEY_Up) { - selection->moveSelection(0, -d); - return true; - } - if (keyEvent->keyval == GDK_KEY_Right) { - selection->moveSelection(d, 0); - return true; + xdir = -1; + } else if (keyEvent->keyval == GDK_KEY_Up) { + ydir = -1; + } else if (keyEvent->keyval == GDK_KEY_Right) { + xdir = 1; + } else if (keyEvent->keyval == GDK_KEY_Down) { + ydir = 1; } - if (keyEvent->keyval == GDK_KEY_Down) { - selection->moveSelection(0, d); + if (xdir != 0 || ydir != 0) { + selection->moveSelection(d * xdir, d * ydir); return true; } }