diff --git a/src/app/Browser.cpp b/src/app/Browser.cpp index 88252078..5deae484 100644 --- a/src/app/Browser.cpp +++ b/src/app/Browser.cpp @@ -285,7 +285,7 @@ struct ModelBox : widget::OpaqueWidget { void onHoverKey(const HoverKeyEvent& e) override { if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { - if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_F1, RACK_MOD_CTRL)) { system::openBrowser(model->getManualUrl()); e.consume(this); } @@ -799,7 +799,7 @@ struct Browser : widget::OpaqueWidget { void onHoverKey(const HoverKeyEvent& e) override { if (e.action == GLFW_PRESS) { // Secret key command to dump all visible modules into rack - if (e.key == GLFW_KEY_F2 && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT | GLFW_MOD_ALT)) { + if (e.isKeyCommand(GLFW_KEY_F2, RACK_MOD_CTRL | GLFW_MOD_SHIFT | GLFW_MOD_ALT)) { int count = 0; for (widget::Widget* w : modelContainer->children) { ModelBox* mb = dynamic_cast(w); @@ -841,7 +841,7 @@ inline void ClearButton::onAction(const ActionEvent& e) { inline void BrowserSearchField::onSelectKey(const SelectKeyEvent& e) { if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { // Backspace when the field is empty to clear filters. - if (e.key == GLFW_KEY_BACKSPACE) { + if (e.isKeyCommand(GLFW_KEY_BACKSPACE) || e.isKeyCommand(GLFW_KEY_BACKSPACE, RACK_MOD_CTRL)) { if (text == "") { browser->clear(); e.consume(this); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 62e4d3da..2aac50ec 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -315,52 +315,52 @@ void ModuleWidget::onHover(const HoverEvent& e) { void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { - if (e.key == GLFW_KEY_C && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_C, RACK_MOD_CTRL)) { copyClipboard(); e.consume(this); } - if (e.key == GLFW_KEY_V && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_V, RACK_MOD_CTRL)) { if (pasteClipboardAction()) { e.consume(this); } } - if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL)) { cloneAction(false); e.consume(this); } - if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { cloneAction(true); e.consume(this); } - if (e.key == GLFW_KEY_I && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_I, RACK_MOD_CTRL)) { resetAction(); e.consume(this); } - if (e.key == GLFW_KEY_R && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_R, RACK_MOD_CTRL)) { randomizeAction(); e.consume(this); } - if (e.key == GLFW_KEY_U && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_U, RACK_MOD_CTRL)) { disconnectAction(); e.consume(this); } - if (e.key == GLFW_KEY_E && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_E, RACK_MOD_CTRL)) { bypassAction(!module->isBypassed()); e.consume(this); } - if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_DELETE) || e.isKeyCommand(GLFW_KEY_BACKSPACE)) { // Deletes `this` removeAction(); e.consume(NULL); return; } - if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_F1, RACK_MOD_CTRL)) { std::string manualUrl = model->getManualUrl(); if (!manualUrl.empty()) system::openBrowser(manualUrl); e.consume(this); } - if (e.key == GLFW_KEY_F4 && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_F4, RACK_MOD_CTRL)) { APP->scene->rackScroll->zoomToBound(getBox()); e.consume(this); } diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 583b5960..80c8e5aa 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -33,7 +33,7 @@ struct ParamField : ui::TextField { } void onSelectKey(const SelectKeyEvent& e) override { - if (e.action == GLFW_PRESS && (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER)) { + if (e.action == GLFW_PRESS && (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER))) { engine::ParamQuantity* pq = paramWidget->getParamQuantity(); assert(pq); float oldValue = pq->getValue(); diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 761311d9..0e2c8895 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -170,40 +170,40 @@ void Scene::onDragHover(const DragHoverEvent& e) { void Scene::onHoverKey(const HoverKeyEvent& e) { // Key commands that override children if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { - // DEBUG("key '%d '%c' scancode %d '%c' keyName '%s'", e.key, e.key, e.scancode, e.scancode, e.keyName.c_str()); - if (e.key == GLFW_KEY_N && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + // DEBUG("key %d '%c' scancode %d keyName '%s'", e.key, e.key, e.scancode, e.keyName.c_str()); + if (e.isKeyCommand(GLFW_KEY_N, RACK_MOD_CTRL)) { APP->patch->loadTemplateDialog(); e.consume(this); } - if (e.key == GLFW_KEY_Q && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_Q, RACK_MOD_CTRL)) { APP->window->close(); e.consume(this); } - if (e.key == GLFW_KEY_O && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_O, RACK_MOD_CTRL)) { APP->patch->loadDialog(); e.consume(this); } - if (e.key == GLFW_KEY_O && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + if (e.isKeyCommand(GLFW_KEY_O, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { APP->patch->revertDialog(); e.consume(this); } - if (e.key == GLFW_KEY_S && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_S, RACK_MOD_CTRL)) { APP->patch->saveDialog(); e.consume(this); } - if (e.key == GLFW_KEY_S && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + if (e.isKeyCommand(GLFW_KEY_S, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { APP->patch->saveAsDialog(); e.consume(this); } - if (e.key == GLFW_KEY_Z && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_Z, RACK_MOD_CTRL)) { APP->history->undo(); e.consume(this); } - if (e.key == GLFW_KEY_Z && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + if (e.isKeyCommand(GLFW_KEY_Z, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { APP->history->redo(); e.consume(this); } - if ((e.key == GLFW_KEY_MINUS || e.key == GLFW_KEY_KP_SUBTRACT) && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_MINUS, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_SUBTRACT, RACK_MOD_CTRL)) { float zoom = std::log2(APP->scene->rackScroll->getZoom()); zoom *= 2; zoom = std::ceil(zoom - 0.01f) - 1; @@ -212,7 +212,7 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { e.consume(this); } // Numpad has a "+" key, but the main keyboard section hides it under "=" - if ((e.key == GLFW_KEY_EQUAL || e.key == GLFW_KEY_KP_ADD) && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_EQUAL, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_ADD, RACK_MOD_CTRL)) { float zoom = std::log2(APP->scene->rackScroll->getZoom()); zoom *= 2; zoom = std::floor(zoom + 0.01f) + 1; @@ -220,23 +220,23 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { APP->scene->rackScroll->setZoom(std::pow(2.f, zoom)); e.consume(this); } - if ((e.key == GLFW_KEY_0 || e.key == GLFW_KEY_KP_0) && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_0, RACK_MOD_CTRL) || e.isKeyCommand(GLFW_KEY_KP_0, RACK_MOD_CTRL)) { APP->scene->rackScroll->setZoom(1.f); e.consume(this); } - if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_F1)) { system::openBrowser("https://vcvrack.com/manual/"); e.consume(this); } - if (e.key == GLFW_KEY_F3 && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_F3)) { settings::cpuMeter ^= true; e.consume(this); } - if (e.key == GLFW_KEY_F4 && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_F4)) { APP->scene->rackScroll->zoomToModules(); e.consume(this); } - if (e.key == GLFW_KEY_F11 && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_F11)) { APP->window->setFullScreen(!APP->window->isFullScreen()); // The MenuBar will be hidden when the mouse moves over the RackScrollWidget. // menuBar->hide(); @@ -244,57 +244,57 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { } // Module selections - if (e.key == GLFW_KEY_A && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_A, RACK_MOD_CTRL)) { rack->selectAll(); e.consume(this); } - if (e.key == GLFW_KEY_A && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + if (e.isKeyCommand(GLFW_KEY_A, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { rack->deselectAll(); e.consume(this); } - if (e.key == GLFW_KEY_C && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_C, RACK_MOD_CTRL)) { if (rack->hasSelection()) { rack->copyClipboardSelection(); e.consume(this); } } - if (e.key == GLFW_KEY_I && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_I, RACK_MOD_CTRL)) { if (rack->hasSelection()) { rack->resetSelectionAction(); e.consume(this); } } - if (e.key == GLFW_KEY_R && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_R, RACK_MOD_CTRL)) { if (rack->hasSelection()) { rack->randomizeSelectionAction(); e.consume(this); } } - if (e.key == GLFW_KEY_U && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_U, RACK_MOD_CTRL)) { if (rack->hasSelection()) { rack->disconnectSelectionAction(); e.consume(this); } } - if (e.key == GLFW_KEY_E && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_E, RACK_MOD_CTRL)) { if (rack->hasSelection()) { rack->bypassSelectionAction(!rack->isSelectionBypassed()); e.consume(this); } } - if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL)) { if (rack->hasSelection()) { rack->cloneSelectionAction(false); e.consume(this); } } - if (e.key == GLFW_KEY_D && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + if (e.isKeyCommand(GLFW_KEY_D, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { if (rack->hasSelection()) { rack->cloneSelectionAction(true); e.consume(this); } } - if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_DELETE) || e.isKeyCommand(GLFW_KEY_BACKSPACE)) { if (rack->hasSelection()) { rack->deleteSelectionAction(); e.consume(this); @@ -331,17 +331,17 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { // Key commands that can be overridden by children if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { // Alternative key command for exiting fullscreen, since F11 doesn't work reliably on Mac due to "Show desktop" OS binding. - if (e.key == GLFW_KEY_ESCAPE && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_ESCAPE, 0)) { if (APP->window->isFullScreen()) { APP->window->setFullScreen(false); e.consume(this); } } - if (e.key == GLFW_KEY_V && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_V, RACK_MOD_CTRL)) { rack->pasteClipboardAction(); e.consume(this); } - if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER)) { browser->show(); e.consume(this); } diff --git a/src/core/plugin.hpp b/src/core/plugin.hpp index a5e5789a..b47e0ba5 100644 --- a/src/core/plugin.hpp +++ b/src/core/plugin.hpp @@ -133,7 +133,7 @@ struct CcChoice : LedDisplayChoice { } void onSelectKey(const SelectKeyEvent& e) override { - if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && e.action == GLFW_PRESS && (e.mods & RACK_MOD_MASK) == 0) { + if (e.action == GLFW_PRESS && (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER))) { DeselectEvent eDeselect; onDeselect(eDeselect); APP->event->selectedWidget = NULL; @@ -235,7 +235,7 @@ struct NoteChoice : LedDisplayChoice { } void onSelectKey(const SelectKeyEvent& e) override { - if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && e.action == GLFW_PRESS && (e.mods & RACK_MOD_MASK) == 0) { + if (e.action == GLFW_PRESS && (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER))) { DeselectEvent eDeselect; onDeselect(eDeselect); APP->event->selectedWidget = NULL; diff --git a/src/ui/MenuOverlay.cpp b/src/ui/MenuOverlay.cpp index 9db889a4..eea8bbee 100644 --- a/src/ui/MenuOverlay.cpp +++ b/src/ui/MenuOverlay.cpp @@ -50,7 +50,7 @@ void MenuOverlay::onHoverKey(const HoverKeyEvent& e) { if (e.isConsumed()) return; - if (e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { + if (e.action == GLFW_PRESS && e.isKeyCommand(GLFW_KEY_ESCAPE)) { ActionEvent eAction; onAction(eAction); } diff --git a/src/ui/ScrollWidget.cpp b/src/ui/ScrollWidget.cpp index a2b4341c..464351eb 100644 --- a/src/ui/ScrollWidget.cpp +++ b/src/ui/ScrollWidget.cpp @@ -178,38 +178,38 @@ void ScrollWidget::onHoverKey(const HoverKeyEvent& e) { return; if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { - if (e.key == GLFW_KEY_PAGE_UP && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_PAGE_UP)) { offset.y -= box.size.y * 0.5; e.consume(this); } - if (e.key == GLFW_KEY_PAGE_UP && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_PAGE_UP, GLFW_MOD_SHIFT)) { offset.x -= box.size.x * 0.5; e.consume(this); } - if (e.key == GLFW_KEY_PAGE_DOWN && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_PAGE_DOWN)) { offset.y += box.size.y * 0.5; e.consume(this); } - if (e.key == GLFW_KEY_PAGE_DOWN && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_PAGE_DOWN, GLFW_MOD_SHIFT)) { offset.x += box.size.x * 0.5; e.consume(this); } - if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_HOME)) { math::Rect containerBox = container->getVisibleChildrenBoundingBox(); offset.y = containerBox.getTop(); e.consume(this); } - if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_HOME, GLFW_MOD_SHIFT)) { math::Rect containerBox = container->getVisibleChildrenBoundingBox(); offset.x = containerBox.getLeft(); e.consume(this); } - if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_END)) { math::Rect containerBox = container->getVisibleChildrenBoundingBox(); offset.y = containerBox.getBottom(); e.consume(this); } - if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_END, GLFW_MOD_SHIFT)) { math::Rect containerBox = container->getVisibleChildrenBoundingBox(); offset.x = containerBox.getRight(); e.consume(this); diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index fcd640ec..b9777a95 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -120,7 +120,7 @@ void TextField::onSelectText(const SelectTextEvent& e) { void TextField::onSelectKey(const SelectKeyEvent& e) { if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { // Backspace - if (e.key == GLFW_KEY_BACKSPACE && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_BACKSPACE)) { if (cursor == selection) { cursor = std::max(cursor - 1, 0); } @@ -128,7 +128,7 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { e.consume(this); } // Ctrl+Backspace - if (e.key == GLFW_KEY_BACKSPACE && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_BACKSPACE, RACK_MOD_CTRL)) { if (cursor == selection) { cursorToPrevWord(); } @@ -136,7 +136,7 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { e.consume(this); } // Delete - if (e.key == GLFW_KEY_DELETE && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_DELETE)) { if (cursor == selection) { cursor = std::min(cursor + 1, (int) text.size()); } @@ -144,7 +144,7 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { e.consume(this); } // Ctrl+Delete - if (e.key == GLFW_KEY_DELETE && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_DELETE, RACK_MOD_CTRL)) { if (cursor == selection) { cursorToNextWord(); } @@ -152,81 +152,93 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { e.consume(this); } // Left - if (e.key == GLFW_KEY_LEFT) { - if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { - cursorToPrevWord(); - } - else { - cursor = std::max(cursor - 1, 0); - } - if (!(e.mods & GLFW_MOD_SHIFT)) { - selection = cursor; - } + if (e.isKeyCommand(GLFW_KEY_LEFT)) { + cursor = std::max(cursor - 1, 0); + selection = cursor; + e.consume(this); + } + if (e.isKeyCommand(GLFW_KEY_LEFT, RACK_MOD_CTRL)) { + cursorToPrevWord(); + selection = cursor; + e.consume(this); + } + if (e.isKeyCommand(GLFW_KEY_LEFT, GLFW_MOD_SHIFT)) { + cursor = std::max(cursor - 1, 0); + e.consume(this); + } + if (e.isKeyCommand(GLFW_KEY_LEFT, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + cursorToPrevWord(); e.consume(this); } // Right - if (e.key == GLFW_KEY_RIGHT) { - if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { - cursorToNextWord(); - } - else { - cursor = std::min(cursor + 1, (int) text.size()); - } - if (!(e.mods & GLFW_MOD_SHIFT)) { - selection = cursor; - } + if (e.isKeyCommand(GLFW_KEY_RIGHT)) { + cursor = std::min(cursor + 1, (int) text.size()); + selection = cursor; + e.consume(this); + } + if (e.isKeyCommand(GLFW_KEY_RIGHT, RACK_MOD_CTRL)) { + cursorToNextWord(); + selection = cursor; + e.consume(this); + } + if (e.isKeyCommand(GLFW_KEY_RIGHT, GLFW_MOD_SHIFT)) { + cursor = std::min(cursor + 1, (int) text.size()); + e.consume(this); + } + if (e.isKeyCommand(GLFW_KEY_RIGHT, RACK_MOD_CTRL | GLFW_MOD_SHIFT)) { + cursorToNextWord(); e.consume(this); } // Up (placeholder) - if (e.key == GLFW_KEY_UP) { + if (e.isKeyCommand(GLFW_KEY_UP)) { e.consume(this); } // Down (placeholder) - if (e.key == GLFW_KEY_DOWN) { + if (e.isKeyCommand(GLFW_KEY_DOWN)) { e.consume(this); } // Home - if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_HOME)) { selection = cursor = 0; e.consume(this); } // Shift+Home - if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_HOME, GLFW_MOD_SHIFT)) { cursor = 0; e.consume(this); } // End - if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_END)) { selection = cursor = text.size(); e.consume(this); } // Shift+End - if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_END, GLFW_MOD_SHIFT)) { cursor = text.size(); e.consume(this); } // Ctrl+V - if (e.key == GLFW_KEY_V && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_V, RACK_MOD_CTRL)) { pasteClipboard(); e.consume(this); } // Ctrl+X - if (e.key == GLFW_KEY_X && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_X, RACK_MOD_CTRL)) { cutClipboard(); e.consume(this); } // Ctrl+C - if (e.key == GLFW_KEY_C && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_C, RACK_MOD_CTRL)) { copyClipboard(); e.consume(this); } // Ctrl+A - if (e.key == GLFW_KEY_A && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (e.isKeyCommand(GLFW_KEY_A, RACK_MOD_CTRL)) { selectAll(); e.consume(this); } // Enter - if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_ENTER) || e.isKeyCommand(GLFW_KEY_KP_ENTER)) { if (multiline) { insertText("\n"); } @@ -237,19 +249,19 @@ void TextField::onSelectKey(const SelectKeyEvent& e) { e.consume(this); } // Tab - if (e.key == GLFW_KEY_TAB && (e.mods & RACK_MOD_MASK) == 0) { + if (e.isKeyCommand(GLFW_KEY_TAB)) { if (nextField) APP->event->setSelectedWidget(nextField); e.consume(this); } // Shift+Tab - if (e.key == GLFW_KEY_TAB && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + if (e.isKeyCommand(GLFW_KEY_TAB, GLFW_MOD_SHIFT)) { if (prevField) APP->event->setSelectedWidget(prevField); e.consume(this); } // Consume all printable keys unless Ctrl is held - if ((GLFW_KEY_SPACE <= e.key && e.key <= GLFW_KEY_GRAVE_ACCENT) && (e.mods & RACK_MOD_CTRL) == 0) { + if (GLFW_KEY_SPACE <= e.key && e.key < 128 && (e.mods & RACK_MOD_CTRL) == 0) { e.consume(this); }