We need both key and keychar because `key` is easy to use, but is case insensitive
| 538 | |
| 539 | // We need both key and keychar because `key` is easy to use, but is case insensitive |
| 540 | bool MemoryViewTable::KeyPress(int key, QChar keychar, DebugInterface& cpu) |
| 541 | { |
| 542 | if (!cpu.isValidAddress(selectedAddress)) |
| 543 | return false; |
| 544 | |
| 545 | bool pressHandled = false; |
| 546 | |
| 547 | const bool keyCharIsText = keychar.isLetterOrNumber() || keychar.isSpace(); |
| 548 | |
| 549 | if (selectedText) |
| 550 | { |
| 551 | if (keyCharIsText || (!keychar.isNonCharacter() && keychar.category() != QChar::Other_Control)) |
| 552 | { |
| 553 | const QPointer<MemoryViewTable> table(this); |
| 554 | Host::RunOnCPUThread([table, address = selectedAddress, &cpu, val = keychar.toLatin1()] { |
| 555 | cpu.Write8(address, val); |
| 556 | |
| 557 | QtHost::RunOnUIThread([table, address]() { |
| 558 | if (!table) |
| 559 | return; |
| 560 | |
| 561 | table->UpdateSelectedAddress(address + 1); |
| 562 | table->parent->update(); |
| 563 | }); |
| 564 | }); |
| 565 | pressHandled = true; |
| 566 | } |
| 567 | |
| 568 | switch (key) |
| 569 | { |
| 570 | case Qt::Key::Key_Backspace: |
| 571 | case Qt::Key::Key_Escape: |
| 572 | { |
| 573 | const QPointer<MemoryViewTable> table(this); |
| 574 | Host::RunOnCPUThread([table, address = selectedAddress, &cpu] { |
| 575 | cpu.Write8(address, 0); |
| 576 | |
| 577 | QtHost::RunOnUIThread([table] { |
| 578 | if (!table) |
| 579 | return; |
| 580 | |
| 581 | table->BackwardSelection(); |
| 582 | table->parent->update(); |
| 583 | }); |
| 584 | }); |
| 585 | pressHandled = true; |
| 586 | break; |
| 587 | } |
| 588 | case Qt::Key::Key_Right: |
| 589 | ForwardSelection(); |
| 590 | pressHandled = true; |
| 591 | break; |
| 592 | case Qt::Key::Key_Left: |
| 593 | BackwardSelection(); |
| 594 | pressHandled = true; |
| 595 | break; |
| 596 | default: |
| 597 | break; |
no test coverage detected