Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
4a9aae40
Commit
4a9aae40
authored
Sep 04, 2022
by
Waqar Ahmed
Browse files
Diff: Improve painting, use the data we gathered
parent
0a8d9fc9
Changes
4
Hide whitespace changes
Inline
Side-by-side
apps/lib/diff/diffeditor.cpp
View file @
4a9aae40
...
...
@@ -216,12 +216,6 @@ void DiffEditor::updateLineNumberAreaWidth(int)
void
DiffEditor
::
paintEvent
(
QPaintEvent
*
e
)
{
bool
textPainted
=
false
;
if
(
!
getPaintContext
().
selections
.
isEmpty
())
{
QPlainTextEdit
::
paintEvent
(
e
);
textPainted
=
true
;
}
QPainter
p
(
viewport
());
QPointF
offset
(
contentOffset
());
QTextBlock
block
=
firstVisibleBlock
();
...
...
@@ -237,10 +231,10 @@ void DiffEditor::paintEvent(QPaintEvent *e)
for
(
auto
c
:
changes
)
{
// full line background is colored
p
.
fillRect
(
r
,
hl
->
added
?
green1
:
red1
);
if
(
c
.
len
>
=
block
.
text
().
length
()
)
{
if
(
c
.
len
=
=
Change
::
FullBlock
)
{
continue
;
}
// qDebug() << "..." << c.len << block.text().length();
QTextLine
sl
=
layout
->
lineForTextPosition
(
c
.
pos
);
QTextLine
el
=
layout
->
lineForTextPosition
(
c
.
pos
+
c
.
len
);
// color any word diffs
...
...
@@ -274,7 +268,7 @@ void DiffEditor::paintEvent(QPaintEvent *e)
}
}
if
(
block
.
text
().
startsWith
(
QStringLiteral
(
"@@ "
)))
{
if
(
m_diffWidget
->
isHunk
(
block
.
blockNumber
(
)))
{
p
.
save
();
QPen
pen
;
pen
.
setColor
(
hunkSeparatorColor
);
...
...
@@ -293,9 +287,7 @@ void DiffEditor::paintEvent(QPaintEvent *e)
block
=
block
.
next
();
}
if
(
!
textPainted
)
{
QPlainTextEdit
::
paintEvent
(
e
);
}
QPlainTextEdit
::
paintEvent
(
e
);
}
const
LineHighlight
*
DiffEditor
::
highlightingForLine
(
int
line
)
...
...
apps/lib/diff/diffeditor.h
View file @
4a9aae40
...
...
@@ -18,6 +18,7 @@ using IntT = int;
struct
Change
{
IntT
pos
;
IntT
len
;
enum
{
FullBlock
=
-
2
};
};
struct
LineHighlight
{
...
...
apps/lib/diff/diffwidget.cpp
View file @
4a9aae40
...
...
@@ -480,7 +480,7 @@ void DiffWidget::parseAndShowDiff(const QByteArray &raw)
LineHighlight
h
;
h
.
line
=
lineB
;
h
.
added
=
true
;
h
.
changes
.
push_back
({
0
,
l
.
size
()
});
h
.
changes
.
push_back
({
0
,
Change
::
FullBlock
});
rightHlts
.
push_back
(
h
);
lineNumsB
.
append
(
tgtLine
++
);
lineToRawDiffLine
.
append
({
lineB
,
j
,
true
});
...
...
@@ -496,7 +496,7 @@ void DiffWidget::parseAndShowDiff(const QByteArray &raw)
LineHighlight
h
;
h
.
line
=
lineA
;
h
.
added
=
false
;
h
.
changes
.
push_back
({
0
,
l
.
size
()
});
h
.
changes
.
push_back
({
0
,
Change
::
FullBlock
});
leftHlts
.
push_back
(
h
);
lineNumsA
.
append
(
srcLine
++
);
...
...
@@ -654,7 +654,7 @@ void DiffWidget::parseAndShowDiffUnified(const QByteArray &raw)
LineHighlight
h
;
h
.
line
=
lineNo
;
h
.
added
=
true
;
h
.
changes
.
push_back
({
0
,
l
.
size
()
});
h
.
changes
.
push_back
({
0
,
Change
::
FullBlock
});
lines
.
append
(
l
);
hlts
.
push_back
(
h
);
lineNums
.
append
(
tgtLine
++
);
...
...
@@ -667,7 +667,7 @@ void DiffWidget::parseAndShowDiffUnified(const QByteArray &raw)
LineHighlight
h
;
h
.
line
=
lineNo
;
h
.
added
=
false
;
h
.
changes
.
push_back
({
0
,
l
.
size
()
});
h
.
changes
.
push_back
({
0
,
Change
::
FullBlock
});
hlts
.
push_back
(
h
);
lineNums
.
append
(
srcLine
++
);
...
...
@@ -748,3 +748,10 @@ void DiffWidget::onError(const QByteArray & /*error*/, int /*code*/)
{
// printf("Got error: \n%s\n==============\n", error.constData());
}
bool
DiffWidget
::
isHunk
(
const
int
line
)
const
{
return
std
::
any_of
(
m_lineToDiffHunkLine
.
begin
(),
m_lineToDiffHunkLine
.
end
(),
[
line
](
const
ViewLineToDiffLine
l
)
{
return
l
.
line
==
line
;
});
}
apps/lib/diff/diffwidget.h
View file @
4a9aae40
...
...
@@ -29,6 +29,8 @@ public:
return
true
;
}
bool
isHunk
(
int
line
)
const
;
private:
void
clearData
();
void
handleStyleChange
(
int
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment