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
5756ba29
Commit
5756ba29
authored
Sep 12, 2022
by
Waqar Ahmed
Browse files
Diff: Fix comment block highlighting in hunks
parent
cbe04fba
Pipeline
#230782
passed with stage
in 12 minutes and 30 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/lib/diff/diffeditor.cpp
View file @
5756ba29
...
...
@@ -14,9 +14,17 @@
#include
<QTextBlock>
#include
<KLocalizedString>
#include
<KSyntaxHighlighting/Definition>
#include
<KSyntaxHighlighting/Format>
#include
<KSyntaxHighlighting/State>
#include
<KTextEditor/Editor>
DiffSyntaxHighlighter
::
DiffSyntaxHighlighter
(
QTextDocument
*
parent
,
DiffWidget
*
diffWidget
)
:
KSyntaxHighlighting
::
SyntaxHighlighter
(
parent
)
,
m_diffWidget
(
diffWidget
)
{
}
void
DiffSyntaxHighlighter
::
applyFormat
(
int
offset
,
int
length
,
const
KSyntaxHighlighting
::
Format
&
format
)
{
if
(
format
.
textStyle
()
==
KSyntaxHighlighting
::
Theme
::
TextStyle
::
Error
)
{
...
...
@@ -25,6 +33,21 @@ void DiffSyntaxHighlighter::applyFormat(int offset, int length, const KSyntaxHig
KSyntaxHighlighting
::
SyntaxHighlighter
::
applyFormat
(
offset
,
length
,
format
);
}
void
DiffSyntaxHighlighter
::
highlightBlock
(
const
QString
&
text
)
{
// Delete user data i.e., the stored state in the block
// when we encounter a hunk to avoid issues like everything
// is commented because previous hunk ended with an unclosed
// comment block
if
(
m_diffWidget
->
isHunk
(
currentBlock
().
blockNumber
()))
{
auto
prevBlock
=
currentBlock
().
previous
();
const
auto
prevData
=
prevBlock
.
userData
();
delete
prevData
;
prevBlock
.
setUserData
(
new
QTextBlockUserData
);
}
KSyntaxHighlighting
::
SyntaxHighlighter
::
highlightBlock
(
text
);
}
DiffEditor
::
DiffEditor
(
DiffParams
::
Flags
f
,
QWidget
*
parent
)
:
QPlainTextEdit
(
parent
)
,
m_lineNumArea
(
new
LineNumArea
(
this
))
...
...
apps/lib/diff/diffeditor.h
View file @
5756ba29
...
...
@@ -15,13 +15,17 @@
class
DiffSyntaxHighlighter
final
:
public
KSyntaxHighlighting
::
SyntaxHighlighter
{
public:
using
KSyntaxHighlighting
::
SyntaxHighlighter
::
SyntaxHighlighter
;
void
applyFormat
(
int
offset
,
int
length
,
const
KSyntaxHighlighting
::
Format
&
format
)
override
;
DiffSyntaxHighlighter
(
QTextDocument
*
parent
,
class
DiffWidget
*
diffWidget
);
void
highlightBlock
(
const
QString
&
text
)
override
;
void
applyFormat
(
int
offset
,
int
length
,
const
KSyntaxHighlighting
::
Format
&
format
)
override
;
void
applyFolding
(
int
,
int
,
KSyntaxHighlighting
::
FoldingRegion
)
override
{
// no folding
}
private:
class
DiffWidget
*
const
m_diffWidget
;
};
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
...
...
apps/lib/diff/diffwidget.cpp
View file @
5756ba29
...
...
@@ -35,8 +35,8 @@ DiffWidget::DiffWidget(DiffParams p, QWidget *parent)
layout
->
addWidget
(
m_left
);
layout
->
addWidget
(
m_right
);
leftHl
=
new
DiffSyntaxHighlighter
(
m_left
->
document
());
rightHl
=
new
DiffSyntaxHighlighter
(
m_right
->
document
());
leftHl
=
new
DiffSyntaxHighlighter
(
m_left
->
document
()
,
this
);
rightHl
=
new
DiffSyntaxHighlighter
(
m_right
->
document
()
,
this
);
leftHl
->
setTheme
(
KTextEditor
::
Editor
::
instance
()
->
theme
());
rightHl
->
setTheme
(
KTextEditor
::
Editor
::
instance
()
->
theme
());
...
...
apps/lib/diff/diffwidget.h
View file @
5756ba29
...
...
@@ -64,8 +64,8 @@ private:
class
DiffEditor
*
m_left
;
class
DiffEditor
*
m_right
;
KSyntaxHighlighting
::
Syntax
Highlighter
*
leftHl
;
KSyntaxHighlighting
::
Syntax
Highlighter
*
rightHl
;
KSyntaxHighlighting
::
Abstract
Highlighter
*
leftHl
;
KSyntaxHighlighting
::
Abstract
Highlighter
*
rightHl
;
DiffStyle
m_style
=
SideBySide
;
DiffParams
m_params
;
QByteArray
m_rawDiff
;
// Raw diff saved as is
...
...
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