MCPcopy Create free account
hub / github.com/Cubitect/cubiomes-viewer / keyPressEvent

Method keyPressEvent

src/scripts.cpp:612–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612void ScriptEditor::keyPressEvent(QKeyEvent *event)
613{
614 if (event->key() == Qt::Key_Return)
615 {
616 QTextCursor cursor = textCursor();
617 int pos = cursor.position();
618 int start = pos - cursor.positionInBlock();
619 int end = start;
620 while (end < pos)
621 {
622 if (!document()->characterAt(end).isSpace())
623 break;
624 end++;
625 }
626 if (start < end)
627 {
628 const QString text = document()->toPlainText();
629 const QChar linebreak = QChar(0x2029);
630 QString ws = linebreak + text.mid(start, end-start);
631 cursor.beginEditBlock();
632 cursor.insertText(ws);
633 cursor.endEditBlock();
634 return; // cancel normal enter
635 }
636 }
637 else if (event->key() == Qt::Key_Tab || event->key() == Qt::Key_Backtab)
638 {
639 bool back = event->key() == Qt::Key_Backtab;
640 QTextCursor cursor = textCursor();
641
642 if (back || cursor.hasSelection())
643 {
644 int s = cursor.selectionStart();
645 int e = cursor.selectionEnd();
646 cursor.setPosition(e);
647 e = cursor.block().blockNumber();
648 cursor.setPosition(s);
649 s = cursor.block().blockNumber();
650 cursor.beginEditBlock();
651 for (int i = s; i <= e; i++)
652 {
653 cursor.movePosition(QTextCursor::StartOfBlock);
654 if (back == false)
655 cursor.insertText("\t");
656 else if (document()->characterAt(cursor.position()) == '\t')
657 cursor.deleteChar();
658 cursor.movePosition(QTextCursor::NextBlock);
659 }
660 cursor.endEditBlock();
661 return;
662 }
663 }
664 QPlainTextEdit::keyPressEvent(event);
665}
666
667

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected