* Checks the input of the console to make the correct indentations. * After a command is prompted completely the Python interpreter is started. */
| 560 | * After a command is prompted completely the Python interpreter is started. |
| 561 | */ |
| 562 | void PythonConsole::keyPressEvent(QKeyEvent* e) |
| 563 | { |
| 564 | bool restartHistory = true; |
| 565 | QTextCursor cursor = this->textCursor(); |
| 566 | QTextCursor inputLineBegin = this->inputBegin(); |
| 567 | |
| 568 | if (e->key() == Qt::Key_C && e->modifiers() == Qt::ControlModifier) { |
| 569 | if (d->interpreter->interrupt()) { |
| 570 | return; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | if (!cursorBeyond(cursor, inputLineBegin)) { |
| 575 | /** |
| 576 | * The cursor is placed not on the input line (or within the prompt string) |
| 577 | * So we handle key input as follows: |
| 578 | * - don't allow changing previous lines. |
| 579 | * - allow full movement (no prompt restriction) |
| 580 | * - allow copying content (Ctrl+C) |
| 581 | * - "escape" to end of input line |
| 582 | */ |
| 583 | switch (e->key()) { |
| 584 | case Qt::Key_Return: |
| 585 | case Qt::Key_Enter: |
| 586 | case Qt::Key_Escape: |
| 587 | case Qt::Key_Backspace: |
| 588 | this->moveCursor(QTextCursor::End); |
| 589 | break; |
| 590 | |
| 591 | default: |
| 592 | if (e->text().isEmpty() || e->matches(QKeySequence::Copy) |
| 593 | || e->matches(QKeySequence::SelectAll)) { |
| 594 | PythonTextEditor::keyPressEvent(e); |
| 595 | } |
| 596 | else if ( |
| 597 | !e->text().isEmpty() |
| 598 | && (e->modifiers() == Qt::NoModifier || e->modifiers() == Qt::ShiftModifier) |
| 599 | ) { |
| 600 | this->moveCursor(QTextCursor::End); |
| 601 | PythonTextEditor::keyPressEvent(e); |
| 602 | } |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | else { |
| 607 | /** |
| 608 | * The cursor sits somewhere on the input line (after the prompt) |
| 609 | * Here we handle key input a bit different: |
| 610 | * - restrict cursor movement to input line range (excluding the prompt characters) |
| 611 | * - roam the history by Up/Down keys |
| 612 | * - show call tips on period |
| 613 | */ |
| 614 | QTextBlock inputBlock = inputLineBegin.block(); //< get the last paragraph's text |
| 615 | QString inputLine = inputBlock.text(); |
| 616 | QString inputStrg = stripPromptFrom(inputLine); |
| 617 | if (this->_sourceDrain && !this->_sourceDrain->isEmpty()) { |
| 618 | inputStrg = inputLine.mid(this->_sourceDrain->length()); |
| 619 | } |
nothing calls this directly
no test coverage detected