-
Notifications
You must be signed in to change notification settings - Fork 55
Support more than one line in the Python Console & Refactor #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| connect( | ||
| m_history_edit->document(), | ||
| &QTextDocument::contentsChanged, | ||
| this, | ||
| [this]() | ||
| { | ||
| const int newHeight = calcHeightToFitContents(m_history_edit); | ||
| m_history_edit->setMinimumHeight(newHeight); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set minHeight to history editor so that it would fill all free space in scrollArea if there's some
| connect( | ||
| m_command_edit->document(), | ||
| &QTextDocument::contentsChanged, | ||
| this, | ||
| [this, commandEditMinHeight]() | ||
| { | ||
| const int newHeight = std::max(calcHeightToFitContents(m_command_edit), commandEditMinHeight); | ||
| m_command_edit->setFixedHeight(newHeight); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set fixedHeight to commandEdit so that it is big enough to contain all the text, but doesn't stretch if scrollArea has free space
| std::string const command = m_command_edit->toPlainText().trimmed().toStdString(); | ||
|
|
||
| if (command.length() == 0) | ||
| { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added trimmed(), so that user wouldn't execute empty command
| printCommandStdout(m_python_redirect.stdout_string()); | ||
| printCommandStderr(m_python_redirect.stderr_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printCommandStderr and printCommandStdout were duplicates of writeToHistory so I removed them
| QTextCursor cursor = m_history_edit->textCursor(); | ||
| cursor.movePosition(QTextCursor::End); | ||
| m_history_edit->setTextCursor(cursor); | ||
| m_history_edit->insertPlainText(QString::fromStdString(data)); | ||
| cursor.movePosition(QTextCursor::End); | ||
| m_history_edit->setTextCursor(cursor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we just need to set cursor before we write to the editor since it's read-only editor
| setCommand(QString::fromStdString(command_to_show)); | ||
| } | ||
|
|
||
| void RPythonConsoleDockWidget::navigateCommand(int offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function contained a bug, when not yet executed command couldn't be restored after navigating to past commands and back to the not yet executed command. So I have fixed the bug and simplified the function.
| const auto formatted_command = std::format("[{}] {}\n\n", m_last_command_serial, command); | ||
| writeToHistory(formatted_command); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an equivalent replacement of printCommandHistory() function
| const bool is_first_line_focused = cursor.blockNumber() == 0; | ||
| const bool is_last_line_focused = cursor.blockNumber() == document()->blockCount() - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need this so that navigation between lines of a past command is possible
No description provided.