Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flatpak-qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marco Bubke
flatpak-qt-creator
Commits
accc2c69
Commit
accc2c69
authored
15 years ago
by
Friedemann Kleint
Browse files
Options
Downloads
Patches
Plain Diff
Diff-Highlighter: Mark trailing whitespace in added lines.
... using inverted colors.
parent
c996238d
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/vcsbase/diffhighlighter.cpp
+37
-2
37 additions, 2 deletions
src/plugins/vcsbase/diffhighlighter.cpp
with
37 additions
and
2 deletions
src/plugins/vcsbase/diffhighlighter.cpp
+
37
−
2
View file @
accc2c69
...
...
@@ -34,6 +34,7 @@
#include
<QtCore/QDebug>
#include
<QtCore/QtAlgorithms>
#include
<QtCore/QRegExp>
#include
<QtGui/QBrush>
namespace
VCSBase
{
...
...
@@ -57,6 +58,7 @@ struct DiffHighlighterPrivate {
const
QChar
m_diffInIndicator
;
const
QChar
m_diffOutIndicator
;
QTextCharFormat
m_formats
[
NumDiffFormats
];
QTextCharFormat
m_addedTrailingWhiteSpaceFormat
;
};
DiffHighlighterPrivate
::
DiffHighlighterPrivate
(
const
QRegExp
&
filePattern
)
:
...
...
@@ -96,20 +98,53 @@ DiffHighlighter::~DiffHighlighter()
delete
m_d
;
}
// Check trailing spaces
static
inline
int
trimmedLength
(
const
QString
&
in
)
{
for
(
int
pos
=
in
.
length
()
-
1
;
pos
>=
0
;
pos
--
)
if
(
!
in
.
at
(
pos
).
isSpace
())
return
pos
+
1
;
return
0
;
}
void
DiffHighlighter
::
highlightBlock
(
const
QString
&
text
)
{
if
(
text
.
isEmpty
())
return
;
const
int
length
=
text
.
length
();
const
DiffFormats
format
=
m_d
->
analyzeLine
(
text
);
if
(
format
!=
DiffTextFormat
)
setFormat
(
0
,
text
.
length
(),
m_d
->
m_formats
[
format
]);
switch
(
format
)
{
case
DiffTextFormat
:
break
;
case
DiffInFormat
:
{
// Mark trailing whitespace.
const
int
trimmedLen
=
trimmedLength
(
text
);
setFormat
(
0
,
trimmedLen
,
m_d
->
m_formats
[
format
]);
if
(
trimmedLen
!=
length
)
setFormat
(
trimmedLen
,
length
-
trimmedLen
,
m_d
->
m_addedTrailingWhiteSpaceFormat
);
}
break
;
default
:
setFormat
(
0
,
length
,
m_d
->
m_formats
[
format
]);
break
;
}
}
static
inline
QTextCharFormat
invertedColorFormat
(
const
QTextCharFormat
&
in
)
{
QTextCharFormat
rc
=
in
;
rc
.
setForeground
(
in
.
background
());
rc
.
setBackground
(
in
.
foreground
());
return
rc
;
}
void
DiffHighlighter
::
setFormats
(
const
QVector
<
QTextCharFormat
>
&
s
)
{
if
(
s
.
size
()
==
NumDiffFormats
)
{
qCopy
(
s
.
constBegin
(),
s
.
constEnd
(),
m_d
->
m_formats
);
// Display trailing blanks with colors swapped
m_d
->
m_addedTrailingWhiteSpaceFormat
=
invertedColorFormat
(
m_d
->
m_formats
[
DiffInFormat
]);
}
else
{
qWarning
(
"%s: insufficient setting size: %d"
,
Q_FUNC_INFO
,
s
.
size
());
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment