Skip to content
GitLab
Menu
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
cc5258fc
Commit
cc5258fc
authored
Jan 18, 2021
by
Waqar Ahmed
Browse files
Optimize search some more and reduce memory usage
parent
3b03ce93
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/search/plugin_search.cpp
View file @
cc5258fc
...
...
@@ -785,26 +785,33 @@ void KatePluginSearchView::updateSearchColors()
KTextEditor
::
ConfigInterface
*
ciface
=
qobject_cast
<
KTextEditor
::
ConfigInterface
*>
(
view
);
if
(
ciface
&&
view
)
{
// save for later reuse when the search tree starts getting populated
m_
searchBackgroundColor
=
QBrush
(
ciface
->
configValue
(
QStringLiteral
(
"search-highlight-color"
)).
value
<
QColor
>
()
)
;
if
(
!
m_
searchBackgroundColor
.
color
().
isValid
())
m_
searchBackgroundColor
=
Qt
::
yellow
;
m_
replaceHighlightColor
=
QBrush
(
ciface
->
configValue
(
QStringLiteral
(
"replace-highlight-color"
)).
value
<
QColor
>
()
)
;
if
(
!
m_
replaceHighlightColor
.
color
().
isValid
())
m_
replaceHighlightColor
=
Qt
::
green
;
m_
foregroundColor
=
QBrush
(
view
->
defaultStyleAttribute
(
KTextEditor
::
dsNormal
)
->
foreground
().
color
()
)
;
QColor
searchBackgroundColor
=
ciface
->
configValue
(
QStringLiteral
(
"search-highlight-color"
)).
value
<
QColor
>
();
if
(
!
searchBackgroundColor
.
isValid
())
searchBackgroundColor
=
Qt
::
yellow
;
QColor
replaceHighlightColor
=
ciface
->
configValue
(
QStringLiteral
(
"replace-highlight-color"
)).
value
<
QColor
>
();
if
(
!
replaceHighlightColor
.
isValid
())
replaceHighlightColor
=
Qt
::
green
;
QColor
foregroundColor
=
view
->
defaultStyleAttribute
(
KTextEditor
::
dsNormal
)
->
foreground
().
color
();
QColor
lineNrBackgroundColor
=
ciface
->
configValue
(
QStringLiteral
(
"icon-border-color"
)).
value
<
QColor
>
();
if
(
!
lineNrBackgroundColor
.
isValid
())
lineNrBackgroundColor
=
view
->
defaultStyleAttribute
(
KTextEditor
::
dsNormal
)
->
background
().
color
();
if
(
!
resultAttr
)
resultAttr
=
new
KTextEditor
::
Attribute
();
// reset colors at the start of search
resultAttr
->
clear
();
resultAttr
->
setBackground
(
searchBackgroundColor
);
resultAttr
->
setForeground
(
foregroundColor
);
if
(
m_curResults
)
{
auto
*
delegate
=
qobject_cast
<
SPHtmlDelegate
*>
(
m_curResults
->
treeView
->
itemDelegate
());
if
(
delegate
)
{
delegate
->
setDisplayFont
(
ciface
->
configValue
(
QStringLiteral
(
"font"
)).
value
<
QFont
>
());
}
m_curResults
->
matchModel
.
setMatchColors
(
m_
foregroundColor
.
color
()
,
m_
searchBackgroundColor
.
color
()
,
m_
replaceHighlightColor
.
color
()
,
m_curResults
->
matchModel
.
setMatchColors
(
foregroundColor
,
searchBackgroundColor
,
replaceHighlightColor
,
lineNrBackgroundColor
);
}
}
...
...
@@ -1351,7 +1358,7 @@ void KatePluginSearchView::clearDocMarksAndRanges(KTextEditor::Document *doc)
}
}
void
KatePluginSearchView
::
addRangeAndMark
(
KTextEditor
::
Document
*
doc
,
const
KateSearchMatch
&
match
)
void
KatePluginSearchView
::
addRangeAndMark
(
KTextEditor
::
Document
*
doc
,
const
KateSearchMatch
&
match
,
KTextEditor
::
Attribute
::
Ptr
attr
,
KTextEditor
::
MovingInterface
*
miface
)
{
if
(
!
doc
)
return
;
...
...
@@ -1381,15 +1388,10 @@ void KatePluginSearchView::addRangeAndMark(KTextEditor::Document *doc, const Kat
}
// Highlight the match
KTextEditor
::
Attribute
::
Ptr
attr
(
new
KTextEditor
::
Attribute
());
if
(
isReplaced
)
{
attr
->
setBackground
(
m_replaceHighlightColor
);
}
else
{
attr
->
setBackground
(
m_searchBackgroundColor
);
}
attr
->
setForeground
(
m_foregroundColor
);
KTextEditor
::
MovingInterface
*
miface
=
qobject_cast
<
KTextEditor
::
MovingInterface
*>
(
doc
);
KTextEditor
::
MovingRange
*
mr
=
miface
->
newMovingRange
(
match
.
range
);
mr
->
setAttribute
(
attr
);
mr
->
setZDepth
(
-
90000.0
);
// Set the z-depth to slightly worse than the selection
...
...
@@ -1435,10 +1437,12 @@ void KatePluginSearchView::updateMatchMarks()
// Re-add the highlighting on document reload
connect
(
doc
,
&
KTextEditor
::
Document
::
reloaded
,
this
,
&
KatePluginSearchView
::
updateMatchMarks
,
Qt
::
UniqueConnection
);
KTextEditor
::
MovingInterface
*
miface
=
qobject_cast
<
KTextEditor
::
MovingInterface
*>
(
doc
);
// Add match marks for all matches in the file
const
QVector
<
KateSearchMatch
>
&
fileMatches
=
res
->
matchModel
.
fileMatches
(
doc
->
url
());
for
(
const
KateSearchMatch
&
match
:
fileMatches
)
{
addRangeAndMark
(
doc
,
match
);
addRangeAndMark
(
doc
,
match
,
resultAttr
,
miface
);
}
}
...
...
addons/search/plugin_search.h
View file @
cc5258fc
...
...
@@ -44,6 +44,7 @@ class QPoint;
namespace
KTextEditor
{
class
MovingRange
;
class
MovingInterface
;
}
class
Results
:
public
QWidget
,
public
Ui
::
Results
...
...
@@ -136,7 +137,7 @@ private Q_SLOTS:
void
matchesFound
(
const
QUrl
&
url
,
const
QVector
<
KateSearchMatch
>
&
searchMatches
);
void
addRangeAndMark
(
KTextEditor
::
Document
*
doc
,
const
KateSearchMatch
&
match
);
void
addRangeAndMark
(
KTextEditor
::
Document
*
doc
,
const
KateSearchMatch
&
match
,
KTextEditor
::
Attribute
::
Ptr
attr
,
KTextEditor
::
MovingInterface
*
miface
);
void
searchDone
();
void
searchWhileTypingDone
();
...
...
@@ -199,9 +200,8 @@ private:
QVector
<
KTextEditor
::
MovingRange
*>
m_matchRanges
;
QTimer
m_changeTimer
;
QPointer
<
KTextEditor
::
Message
>
m_infoMessage
;
QBrush
m_searchBackgroundColor
;
QBrush
m_foregroundColor
;
QBrush
m_replaceHighlightColor
;
QColor
m_replaceHighlightColor
;
KTextEditor
::
Attribute
::
Ptr
resultAttr
;
/**
* current project plugin view, if any
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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