Skip to content

Commit 590cf78

Browse files
jiyimetaclaude
andcommitted
Enter lyric melisma with the underscore key on non-US keyboards
A lyric melisma is entered with the underscore character. Its default shortcut is Shift+-, which only yields '_' on US-ANSI keyboards. On layouts where '_' is a dedicated key (e.g. Japanese JIS on macOS) or is produced by a different combination (AZERTY, QWERTZ, ...), the shortcut layer never routes the underscore key to the add-melisma action, so a melisma cannot be entered at all. Handle the underscore key directly in the notation view while editing lyrics: Key_Underscore with no modifiers is claimed in shortcutOverrideEvent() and dispatched to add-melisma in keyPressEvent(), bypassing the keyboard-layout-dependent shortcut path. The dispatch is deferred to the next event-loop turn so add-melisma's edit teardown does not run while the key event is still being delivered. Shift+- keeps working on US layouts, and non-lyrics text editing is unaffected. Refs #14914 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 50a5726 commit 590cf78

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/notationscene/qml/MuseScore/NotationScene/notationviewinputcontroller.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ static bool seekAllowed(const mu::engraving::EngravingItem* element)
6363
return muse::contains(ALLOWED_TYPES, element->type());
6464
}
6565

66+
static bool isEditingLyrics(const INotationInteractionPtr& interaction)
67+
{
68+
const EngravingItem* element = interaction->selection()->element();
69+
return interaction->isTextEditingStarted() && element && element->isLyrics();
70+
}
71+
6672
NotationViewInputController::NotationViewInputController(IControlledView* view, const muse::modularity::ContextPtr& iocCtx)
6773
: muse::Contextable(iocCtx), m_view(view)
6874
{
@@ -1451,6 +1457,13 @@ bool NotationViewInputController::shortcutOverrideEvent(QKeyEvent* event)
14511457
}
14521458

14531459
if (viewInteraction()->isEditingElement()) {
1460+
// The shortcut layer cannot route the underscore key to the add-melisma
1461+
// action on non-US keyboard layouts (e.g. JIS, where '_' is its own
1462+
// dedicated key rather than Shift+'-'). Claim it here so it is delivered
1463+
// as a key press and handled directly in keyPressEvent().
1464+
if (key == Qt::Key_Underscore && event->modifiers() == Qt::NoModifier && isEditingLyrics(viewInteraction())) {
1465+
return true;
1466+
}
14541467
return viewInteraction()->isEditAllowed(event);
14551468
}
14561469

@@ -1475,9 +1488,18 @@ void NotationViewInputController::keyPressEvent(QKeyEvent* event)
14751488
m_view->asItem()->setCursor({});
14761489
event->accept();
14771490
} else if (viewInteraction()->isEditingElement()) {
1478-
viewInteraction()->editElement(event);
1479-
if (key == Qt::Key_Shift) {
1480-
viewInteraction()->updateTimeTickAnchors(event);
1491+
if (key == Qt::Key_Underscore && event->modifiers() == Qt::NoModifier && isEditingLyrics(viewInteraction())) {
1492+
// Underscore -> melisma in lyrics (the shortcut layer can't map '_'
1493+
// to add-melisma on non-US keyboard layouts; see shortcutOverrideEvent()).
1494+
// Dispatch on the next event-loop turn so add-melisma's text-edit
1495+
// teardown does not run while this key event is still being delivered.
1496+
QTimer::singleShot(0, m_view->asItem(), [this]() { dispatcher()->dispatch("add-melisma"); });
1497+
event->accept();
1498+
} else {
1499+
viewInteraction()->editElement(event);
1500+
if (key == Qt::Key_Shift) {
1501+
viewInteraction()->updateTimeTickAnchors(event);
1502+
}
14811503
}
14821504
} else if (key == Qt::Key_Shift) {
14831505
viewInteraction()->updateTimeTickAnchors(event);

0 commit comments

Comments
 (0)