poboiko added a comment.

  @dfaure There seem to be a regression caused by this patch: if I reach the 
end of current view, and then press Enter so it has to scroll down, it scrolls 
to the very beginning of the document instead.
  
  This is the same issue as in ancient bug 195828 
<https://bugs.kde.org/show_bug.cgi?id=195828>, and it seems like it is Qt issue.
  
  Here's the simplest MWE:
  
    #include <QApplication>
    #include <QMainWindow>
    #include <QTextEdit>
    #include <QPushButton>
    #include <QVBoxLayout>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        auto w = new QWidget();
        auto edit = new QTextEdit();
        auto button = new QPushButton(QStringLiteral("Insert new line"));
        button->connect(button, &QPushButton::clicked, [edit](){
            auto cursor = edit->textCursor();
            cursor.beginEditBlock();
            cursor.insertBlock();
            edit->setTextCursor(cursor);
            cursor.endEditBlock();
        });
        auto layout = new QVBoxLayout(w);
        layout->addWidget(edit);
        layout->addWidget(button);
        w->show();
        return a.exec();
    }
  
  Seems like the following code in `QTextCursorPrivate::setX` causes the 
trouble:
  
    if (priv->isInEditBlock() || priv->inContentsChange) {
        x = -1; // mark dirty
        return;
    }
  
  and seems like this "dirty" value is treated literally afterwards.
  
  For this example, switching `endEditBlock` and `setTextCursor` lines fixes 
the issue (and same with `Insert Rule`).
  I've also found a (dirty) workaround for the original patch: if I call 
`setTextCursor(textCursor())` right after `endEditBlock()`, it works like a 
charm. It seems like this line (although semantically is a NOOP) triggers the 
update of this "dirty" value.
  
  How should I proceed?

REPOSITORY
  R310 KTextWidgets

REVISION DETAIL
  https://phabricator.kde.org/D28819

To: poboiko, #frameworks, mlaurent, dfaure
Cc: ahmadsamir, kde-frameworks-devel, LeGast00n, cblack, michaelh, ngraham, 
bruns

Reply via email to