forked from qt-creator/qt-creator
Editor: fix visual glitch after disabling overwrite mode
Change-Id: Ied85cf298a12a29cf448e6dec6c81f6a0a2dc4b7 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -537,8 +537,15 @@ public:
|
|||||||
void paintIfDefedOutBlocks(const PaintEventData &data, QPainter &painter) const;
|
void paintIfDefedOutBlocks(const PaintEventData &data, QPainter &painter) const;
|
||||||
void paintFindScope(const PaintEventData &data, QPainter &painter) const;
|
void paintFindScope(const PaintEventData &data, QPainter &painter) const;
|
||||||
void paintCurrentLineHighlight(const PaintEventData &data, QPainter &painter) const;
|
void paintCurrentLineHighlight(const PaintEventData &data, QPainter &painter) const;
|
||||||
void paintCursorAsBlock(const PaintEventData &data, QPainter &painter,
|
QRectF cursorBlockRect(const QTextDocument *doc,
|
||||||
PaintEventBlockData &blockData, int cursorPosition) const;
|
const QTextBlock &block,
|
||||||
|
int cursorPosition,
|
||||||
|
QRectF blockBoundingRect = {},
|
||||||
|
bool *doSelection = nullptr) const;
|
||||||
|
void paintCursorAsBlock(const PaintEventData &data,
|
||||||
|
QPainter &painter,
|
||||||
|
PaintEventBlockData &blockData,
|
||||||
|
int cursorPosition) const;
|
||||||
void paintAdditionalVisualWhitespaces(PaintEventData &data, QPainter &painter, qreal top) const;
|
void paintAdditionalVisualWhitespaces(PaintEventData &data, QPainter &painter, qreal top) const;
|
||||||
void paintIndentDepth(PaintEventData &data, QPainter &painter, const PaintEventBlockData &blockData);
|
void paintIndentDepth(PaintEventData &data, QPainter &painter, const PaintEventBlockData &blockData);
|
||||||
void paintReplacement(PaintEventData &data, QPainter &painter, qreal top) const;
|
void paintReplacement(PaintEventData &data, QPainter &painter, qreal top) const;
|
||||||
@@ -2787,6 +2794,14 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
if (ro) break;
|
if (ro) break;
|
||||||
if (e->modifiers() == Qt::NoModifier) {
|
if (e->modifiers() == Qt::NoModifier) {
|
||||||
setOverwriteMode(!inOverwriteMode);
|
setOverwriteMode(!inOverwriteMode);
|
||||||
|
if (inOverwriteMode) {
|
||||||
|
for (const QTextCursor &cursor : multiTextCursor()) {
|
||||||
|
const QRectF oldBlockRect = d->cursorBlockRect(document(),
|
||||||
|
cursor.block(),
|
||||||
|
cursor.position());
|
||||||
|
viewport()->update(oldBlockRect.toAlignedRect());
|
||||||
|
}
|
||||||
|
}
|
||||||
e->accept();
|
e->accept();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4436,19 +4451,22 @@ void TextEditorWidgetPrivate::paintCurrentLineHighlight(const PaintEventData &da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidgetPrivate::paintCursorAsBlock(const PaintEventData &data, QPainter &painter,
|
QRectF TextEditorWidgetPrivate::cursorBlockRect(const QTextDocument *doc,
|
||||||
PaintEventBlockData &blockData, int cursorPosition) const
|
const QTextBlock &block,
|
||||||
|
int cursorPosition,
|
||||||
|
QRectF blockBoundingRect,
|
||||||
|
bool *doSelection) const
|
||||||
{
|
{
|
||||||
const qreal space = charWidth();
|
const qreal space = charWidth();
|
||||||
int relativePos = cursorPosition - blockData.position;
|
int relativePos = cursorPosition - block.position();
|
||||||
bool doSelection = true;
|
QTextLine line = block.layout()->lineForTextPosition(relativePos);
|
||||||
QTextLine line = blockData.layout->lineForTextPosition(relativePos);
|
|
||||||
qreal x = line.cursorToX(relativePos);
|
qreal x = line.cursorToX(relativePos);
|
||||||
qreal w = 0;
|
qreal w = 0;
|
||||||
if (relativePos < line.textLength() - line.textStart()) {
|
if (relativePos < line.textLength() - line.textStart()) {
|
||||||
w = line.cursorToX(relativePos + 1) - x;
|
w = line.cursorToX(relativePos + 1) - x;
|
||||||
if (data.doc->characterAt(cursorPosition) == QLatin1Char('\t')) {
|
if (doc->characterAt(cursorPosition) == QLatin1Char('\t')) {
|
||||||
doSelection = false;
|
if (doSelection)
|
||||||
|
*doSelection = false;
|
||||||
if (w > space) {
|
if (w > space) {
|
||||||
x += w - space;
|
x += w - space;
|
||||||
w = space;
|
w = space;
|
||||||
@@ -4458,12 +4476,30 @@ void TextEditorWidgetPrivate::paintCursorAsBlock(const PaintEventData &data, QPa
|
|||||||
w = space; // in sync with QTextLine::draw()
|
w = space; // in sync with QTextLine::draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF lineRect = line.rect();
|
if (blockBoundingRect.isEmpty())
|
||||||
lineRect.moveTop(lineRect.top() + blockData.boundingRect.top());
|
blockBoundingRect = q->blockBoundingGeometry(block).translated(q->contentOffset());
|
||||||
lineRect.moveLeft(blockData.boundingRect.left() + x);
|
|
||||||
lineRect.setWidth(w);
|
QRectF cursorRect = line.rect();
|
||||||
|
cursorRect.moveTop(cursorRect.top() + blockBoundingRect.top());
|
||||||
|
cursorRect.moveLeft(blockBoundingRect.left() + x);
|
||||||
|
cursorRect.setWidth(w);
|
||||||
|
return cursorRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextEditorWidgetPrivate::paintCursorAsBlock(const PaintEventData &data,
|
||||||
|
QPainter &painter,
|
||||||
|
PaintEventBlockData &blockData,
|
||||||
|
int cursorPosition) const
|
||||||
|
{
|
||||||
|
bool doSelection = true;
|
||||||
|
const QRectF cursorRect = cursorBlockRect(data.doc,
|
||||||
|
data.block,
|
||||||
|
cursorPosition,
|
||||||
|
blockData.boundingRect,
|
||||||
|
&doSelection);
|
||||||
const QTextCharFormat textFormat = data.fontSettings.toTextCharFormat(C_TEXT);
|
const QTextCharFormat textFormat = data.fontSettings.toTextCharFormat(C_TEXT);
|
||||||
painter.fillRect(lineRect, textFormat.foreground());
|
painter.fillRect(cursorRect, textFormat.foreground());
|
||||||
|
int relativePos = cursorPosition - blockData.position;
|
||||||
if (doSelection) {
|
if (doSelection) {
|
||||||
blockData.selections.append(
|
blockData.selections.append(
|
||||||
createBlockCursorCharFormatRange(relativePos,
|
createBlockCursorCharFormatRange(relativePos,
|
||||||
|
|||||||
Reference in New Issue
Block a user