Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/language/interfaces/abbreviations.cpp
Show First 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 148 | if ( matchedFragments == typedFragments.size() ) { | |||
---|---|---|---|---|---|
149 | break; | 149 | break; | ||
150 | } | 150 | } | ||
151 | } | 151 | } | ||
152 | lastSpace = isDoubleColon ? i : i+1; | 152 | lastSpace = isDoubleColon ? i : i+1; | ||
153 | } | 153 | } | ||
154 | return matchedFragments == typedFragments.size(); | 154 | return matchedFragments == typedFragments.size(); | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | PathFilterMatchQuality matchPathFilter(const Path &toFilter, const QStringList &text, | 157 | PathFilterMatchQuality matchPathFilter(const Path &toFilter, const QStringList &text) | ||
158 | const QString &joinedText) | | |||
159 | { | 158 | { | ||
160 | const QVector<QString>& segments = toFilter.segments(); | 159 | const QVector<QString>& segments = toFilter.segments(); | ||
161 | 160 | | |||
162 | if (text.count() > segments.count()) { | 161 | if (text.count() > segments.count()) { | ||
163 | // number of segments mismatches, thus item cannot match | 162 | // number of segments mismatches, thus item cannot match | ||
164 | return PathFilterMatchQuality::NoMatch; | 163 | return PathFilterMatchQuality::NoMatch; | ||
165 | } | 164 | } | ||
166 | { | 165 | { | ||
Show All 17 Lines | |||||
184 | int lastMatchIndex = -1; | 183 | int lastMatchIndex = -1; | ||
185 | // stop early if more search fragments remain than available after path index | 184 | // stop early if more search fragments remain than available after path index | ||
186 | while (pathIndex < segments.size() && searchIndex < text.size() | 185 | while (pathIndex < segments.size() && searchIndex < text.size() | ||
187 | && (pathIndex + text.size() - searchIndex - 1) < segments.size() ) | 186 | && (pathIndex + text.size() - searchIndex - 1) < segments.size() ) | ||
188 | { | 187 | { | ||
189 | const QString& segment = segments.at(pathIndex); | 188 | const QString& segment = segments.at(pathIndex); | ||
190 | const QString& typedSegment = text.at(searchIndex); | 189 | const QString& typedSegment = text.at(searchIndex); | ||
191 | lastMatchIndex = segment.indexOf(typedSegment, 0, Qt::CaseInsensitive); | 190 | lastMatchIndex = segment.indexOf(typedSegment, 0, Qt::CaseInsensitive); | ||
192 | if (lastMatchIndex == -1 && !matchesAbbreviation(segment.midRef(0), typedSegment)) { | 191 | bool isMatch = lastMatchIndex != -1; | ||
192 | // do fuzzy path matching on the last segment | ||||
193 | if (!isMatch && searchIndex == text.size() - 1 && pathIndex == segments.size() - 1) { | ||||
194 | isMatch = matchesPath(segment, typedSegment); | ||||
195 | } else if (!isMatch) { | ||||
196 | isMatch = matchesAbbreviation(segment.midRef(0), typedSegment); | ||||
197 | } | ||||
198 | | ||||
199 | if (!isMatch) { | ||||
193 | // no match, try with next path segment | 200 | // no match, try with next path segment | ||
194 | ++pathIndex; | 201 | ++pathIndex; | ||
195 | continue; | 202 | continue; | ||
196 | } | 203 | } | ||
197 | // else we matched | 204 | // else we matched | ||
198 | ++searchIndex; | 205 | ++searchIndex; | ||
199 | ++pathIndex; | 206 | ++pathIndex; | ||
200 | } | 207 | } | ||
201 | 208 | | |||
202 | if (searchIndex != text.size()) { | 209 | if (searchIndex != text.size()) { | ||
203 | if ( ! matchesPath(segments.last(), joinedText) ) { | | |||
204 | return PathFilterMatchQuality::NoMatch; | 210 | return PathFilterMatchQuality::NoMatch; | ||
205 | } | 211 | } | ||
206 | } | | |||
207 | 212 | | |||
208 | // prefer matches whose last element starts with the filter | 213 | // prefer matches whose last element starts with the filter | ||
209 | if (pathIndex == segments.size() && lastMatchIndex == 0) { | 214 | if (pathIndex == segments.size() && lastMatchIndex == 0) { | ||
210 | return PathFilterMatchQuality::StartMatch; | 215 | return PathFilterMatchQuality::StartMatch; | ||
211 | } else { | 216 | } else { | ||
212 | return PathFilterMatchQuality::OtherMatch; | 217 | return PathFilterMatchQuality::OtherMatch; | ||
213 | } | 218 | } | ||
214 | } | 219 | } | ||
215 | 220 | | |||
216 | } // namespace KDevelop | 221 | } // namespace KDevelop | ||
217 | 222 | | |||
218 | // kate: space-indent on; indent-width 2 | 223 | // kate: space-indent on; indent-width 2 |