<table><tr><td style="">poboiko added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D28819">View Revision</a></tr></table><br /><div><div><p><a href="https://phabricator.kde.org/p/dfaure/" style="
border-color: #f1f7ff;
color: #19558d;
background-color: #f1f7ff;
border: 1px solid transparent;
border-radius: 3px;
font-weight: bold;
padding: 0 4px;">@dfaure</a> 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.</p>
<p>This is the same issue as in <a href="https://bugs.kde.org/show_bug.cgi?id=195828" class="remarkup-link" target="_blank" rel="noreferrer">ancient bug 195828</a>, and it seems like it is Qt issue.</p>
<p>Here's the simplest MWE:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">#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();
}</pre></div>
<p>Seems like the following code in <tt style="background: #ebebeb; font-size: 13px;">QTextCursorPrivate::setX</tt> causes the trouble:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">if (priv->isInEditBlock() || priv->inContentsChange) {
x = -1; // mark dirty
return;
}</pre></div>
<p>and seems like this "dirty" value is treated literally afterwards.</p>
<p>For this example, switching <tt style="background: #ebebeb; font-size: 13px;">endEditBlock</tt> and <tt style="background: #ebebeb; font-size: 13px;">setTextCursor</tt> lines fixes the issue (and same with <tt style="background: #ebebeb; font-size: 13px;">Insert Rule</tt>).<br />
I've also found a (dirty) workaround for the original patch: if I call <tt style="background: #ebebeb; font-size: 13px;">setTextCursor(textCursor())</tt> right after <tt style="background: #ebebeb; font-size: 13px;">endEditBlock()</tt>, it works like a charm. It seems like this line (although semantically is a NOOP) triggers the update of this "dirty" value.</p>
<p>How should I proceed?</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R310 KTextWidgets</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D28819">https://phabricator.kde.org/D28819</a></div></div><br /><div><strong>To: </strong>poboiko, Frameworks, mlaurent, dfaure<br /><strong>Cc: </strong>ahmadsamir, kde-frameworks-devel, LeGast00n, cblack, michaelh, ngraham, bruns<br /></div>