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
f6ab51d9
Commit
f6ab51d9
authored
Jan 04, 2021
by
Kåre Särs
Browse files
Rebase on the grouped emits
parent
4798781e
Changes
5
Hide whitespace changes
Inline
Side-by-side
addons/search/MatchModel.cpp
View file @
f6ab51d9
...
...
@@ -53,7 +53,7 @@ int MatchModel::matchFileRow(const QUrl& fileUrl)
static
const
int
totalContectLen
=
150
;
/** This function is used to add a match to a new file */
void
MatchModel
::
addMatch
(
const
QUrl
&
fileUrl
,
const
Q
String
&
lineContent
,
int
matchLen
,
int
line
,
int
column
,
int
endLine
,
int
endColumn
)
void
MatchModel
::
addMatch
es
(
const
QUrl
&
fileUrl
,
const
Q
Vector
<
KateSearchMatch
>
&
searchMatches
)
{
int
fileIndex
=
matchFileRow
(
fileUrl
);
if
(
fileIndex
==
-
1
)
{
...
...
@@ -65,29 +65,31 @@ void MatchModel::addMatch(const QUrl &fileUrl, const QString &lineContent, int m
m_matchFiles
[
fileIndex
].
fileUrl
=
fileUrl
;
endInsertRows
();
}
MatchModel
::
Match
match
;
match
.
matchLen
=
matchLen
;
match
.
startLine
=
line
;
match
.
startColumn
=
column
;
match
.
endLine
=
endLine
;
match
.
endColumn
=
endColumn
;
int
contextLen
=
totalContectLen
-
matchLen
;
int
preLen
=
qMin
(
contextLen
/
3
,
column
);
int
postLen
=
contextLen
-
preLen
;
int
matchIndex
=
m_matchFiles
[
fileIndex
].
matches
.
size
();
beginInsertRows
(
index
(
fileIndex
,
0
),
matchIndex
,
matchIndex
+
searchMatches
.
size
()
-
1
);
for
(
const
auto
&
sMatch
:
searchMatches
)
{
MatchModel
::
Match
match
;
match
.
matchLen
=
sMatch
.
matchLen
;
match
.
startLine
=
sMatch
.
matchRange
.
start
().
line
();
match
.
startColumn
=
sMatch
.
matchRange
.
start
().
column
();
match
.
endLine
=
sMatch
.
matchRange
.
end
().
line
();
match
.
endColumn
=
sMatch
.
matchRange
.
end
().
column
();
match
.
preMatchStr
=
lineContent
.
mid
(
column
-
preLen
,
preLen
);
if
(
column
>
preLen
)
match
.
preMatchStr
.
prepend
(
QLatin1String
(
"..."
));
int
contextLen
=
totalContectLen
-
sMatch
.
matchLen
;
int
preLen
=
qMin
(
contextLen
/
3
,
match
.
startColumn
);
int
postLen
=
contextLen
-
preLen
;
match
.
p
ost
MatchStr
=
lineContent
.
mid
(
endColumn
,
post
Len
);
if
(
end
Column
+
preLen
<
lineContent
.
size
()
)
match
.
p
ost
MatchStr
.
a
ppend
(
QLatin1String
(
"..."
));
match
.
p
re
MatchStr
=
sMatch
.
lineContent
.
mid
(
match
.
startColumn
-
preLen
,
pre
Len
);
if
(
match
.
start
Column
>
preLen
)
match
.
p
re
MatchStr
.
p
re
pend
(
QLatin1String
(
"..."
));
match
.
matchStr
=
lineContent
.
mid
(
column
,
matchLen
);
match
.
postMatchStr
=
sMatch
.
lineContent
.
mid
(
match
.
endColumn
,
postLen
);
if
(
match
.
endColumn
+
preLen
<
sMatch
.
lineContent
.
size
())
match
.
postMatchStr
.
append
(
QLatin1String
(
"..."
));
int
match
Index
=
m_matchFiles
[
fileIndex
].
matches
.
size
(
);
beginInsertRows
(
index
(
fileIndex
,
0
),
matchIndex
,
matchIndex
);
// We are always starting the insert at the end, so we could optimize by delaying/grouping the signaling of the updates
m_matchFiles
[
fileIndex
].
matches
.
append
(
match
);
match
.
matchStr
=
sMatch
.
lineContent
.
mid
(
match
.
startColumn
,
sMatch
.
matchLen
);
m_matchFiles
[
fileIndex
].
matches
.
append
(
match
);
}
endInsertRows
();
}
...
...
addons/search/MatchModel.h
View file @
f6ab51d9
...
...
@@ -13,6 +13,25 @@
#include <QUrl>
#include <QBrush>
#include <KTextEditor/Range>
/**
* data holder for one match in one file
* used to transfer multiple matches at once via signals to avoid heavy costs for files with a lot of matches
*/
class
KateSearchMatch
{
public:
QString
lineContent
;
int
matchLen
;
KTextEditor
::
Range
matchRange
;
};
Q_DECLARE_METATYPE
(
KateSearchMatch
)
class
MatchModel
:
public
QAbstractItemModel
{
Q_OBJECT
...
...
@@ -68,7 +87,7 @@ public Q_SLOTS:
int
matchFileRow
(
const
QUrl
&
fileUrl
);
/** This function is used to add a new file */
void
addMatch
(
const
QUrl
&
fileUrl
,
const
Q
String
&
lineContent
,
int
matchLen
,
int
line
,
int
column
,
int
endLine
,
int
endColumn
);
void
addMatch
es
(
const
QUrl
&
fileUrl
,
const
Q
Vector
<
KateSearchMatch
>
&
searchMatches
);
// /** This function is used to modify a match */
// void replaceMatch(const QModelIndex &matchIndex, const QRegularExpression ®exp, const QString &replaceText);
...
...
addons/search/SearchDiskFiles.h
View file @
f6ab51d9
...
...
@@ -26,21 +26,7 @@
#include <QThread>
#include <QVector>
#include <KTextEditor/Range>
/**
* data holder for one match in one file
* used to transfer multiple matches at once via signals to avoid heavy costs for files with a lot of matches
*/
class
KateSearchMatch
{
public:
QString
lineContent
;
int
matchLen
;
KTextEditor
::
Range
matchRange
;
};
Q_DECLARE_METATYPE
(
KateSearchMatch
)
#include "MatchModel.h"
class
SearchDiskFiles
:
public
QThread
{
...
...
addons/search/plugin_search.cpp
View file @
f6ab51d9
...
...
@@ -966,6 +966,8 @@ void KatePluginSearchView::matchesFound(const QUrl &url, const QVector<KateSearc
const
QString
bgColor
=
m_searchBackgroundColor
.
color
().
name
();
const
QString
fgColor
=
m_foregroundColor
.
color
().
name
();
m_curResults
->
matchModel
.
addMatches
(
url
,
searchMatches
);
/**
* handle all received matches, add them as one operation to the widget afterwards
*/
...
...
addons/search/search_open_files.h
View file @
f6ab51d9
...
...
@@ -24,7 +24,7 @@
#include <QTimer>
#include <ktexteditor/document.h>
#include "
SearchDiskFiles
.h"
#include "
MatchModel
.h"
class
SearchOpenFiles
:
public
QObject
{
...
...
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