Replace the last line of the text edit when the new line is

the last line followed by a suffix.
This commit is contained in:
Gerhard Hoffmann 2023-11-29 14:18:01 +01:00
parent fbffdc923f
commit d2e11d8f07

View File

@ -248,11 +248,15 @@ void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) {
void MainWindow::onReplaceLast(QString text, QString suffix) { void MainWindow::onReplaceLast(QString text, QString suffix) {
// Utils::printInfoMsg(QString("ON REPLACE LAST (TEXT) CALLED AT ") // Utils::printInfoMsg(QString("ON REPLACE LAST (TEXT) CALLED AT ")
// + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); // + QDateTime::currentDateTime().toString(Qt::ISODateWithMs));
QString editText = ui->updateStatus->toPlainText(); QString editText = ui->updateStatus->toPlainText();
QStringList lines = editText.split('\n', QString::SplitBehavior::SkipEmptyParts); QStringList lines = editText.split('\n', QString::SplitBehavior::SkipEmptyParts);
if (lines.size() > 0) { if (lines.size() > 0) {
// removing the last line is really meant for refreshing the last line
// with a string very similar than the original one, typically only
// followed by a suffix.
if (lines.last().contains(text)) {
lines.removeLast(); lines.removeLast();
}
if (!suffix.isNull() && suffix.size() > 0 && suffix != "\n") { if (!suffix.isNull() && suffix.size() > 0 && suffix != "\n") {
QString const add = text.leftJustified(m_width-10) + suffix; QString const add = text.leftJustified(m_width-10) + suffix;
if (!add.isEmpty()) { if (!add.isEmpty()) {