Changeset View
Changeset View
Standalone View
Standalone View
src/lib/abstracthighlighter.cpp
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | 141 | if (text.isEmpty()) { | |||
---|---|---|---|---|---|
173 | auto context = stateData->topContext(); | 173 | auto context = stateData->topContext(); | ||
174 | applyFormat(0, 0, context->attributeFormat()); | 174 | applyFormat(0, 0, context->attributeFormat()); | ||
175 | return newState; | 175 | return newState; | ||
176 | } | 176 | } | ||
177 | 177 | | |||
178 | int offset = 0, beginOffset = 0; | 178 | int offset = 0, beginOffset = 0; | ||
179 | bool lineContinuation = false; | 179 | bool lineContinuation = false; | ||
180 | QHash<Rule *, int> skipOffsets; | 180 | QHash<Rule *, int> skipOffsets; | ||
181 | QStringList capturesForLastDynamicSkipOffset; | ||||
181 | 182 | | |||
182 | /** | 183 | /** | ||
183 | * current active format | 184 | * current active format | ||
184 | * stored as pointer to avoid deconstruction/constructions inside the internal loop | 185 | * stored as pointer to avoid deconstruction/constructions inside the internal loop | ||
185 | * the pointers are stable, the formats are either in the contexts or rules | 186 | * the pointers are stable, the formats are either in the contexts or rules | ||
186 | */ | 187 | */ | ||
187 | auto currentFormat = &stateData->topContext()->attributeFormat(); | 188 | auto currentFormat = &stateData->topContext()->attributeFormat(); | ||
188 | 189 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 242 | if (offset > firstNonSpace) { | |||
242 | continue; | 243 | continue; | ||
243 | } | 244 | } | ||
244 | } | 245 | } | ||
245 | 246 | | |||
246 | /** | 247 | /** | ||
247 | * shall we skip application of this rule? two cases: | 248 | * shall we skip application of this rule? two cases: | ||
248 | * - rule can't match at all => currentSkipOffset < 0 | 249 | * - rule can't match at all => currentSkipOffset < 0 | ||
249 | * - rule will only match for some higher offset => currentSkipOffset > offset | 250 | * - rule will only match for some higher offset => currentSkipOffset > offset | ||
251 | * | ||||
252 | * we need to invalidate this if we are dynamic and have different captures then last time | ||||
250 | */ | 253 | */ | ||
254 | if (rule->isDynamic() && (capturesForLastDynamicSkipOffset != stateData->topCaptures())) { | ||||
255 | skipOffsets.clear(); | ||||
256 | } | ||||
251 | const auto currentSkipOffset = skipOffsets.value(rule.get()); | 257 | const auto currentSkipOffset = skipOffsets.value(rule.get()); | ||
252 | if (currentSkipOffset < 0 || currentSkipOffset > offset) | 258 | if (currentSkipOffset < 0 || currentSkipOffset > offset) | ||
253 | continue; | 259 | continue; | ||
254 | 260 | | |||
255 | const auto newResult = rule->doMatch(text, offset, stateData->topCaptures()); | 261 | const auto newResult = rule->doMatch(text, offset, stateData->topCaptures()); | ||
256 | newOffset = newResult.offset(); | 262 | newOffset = newResult.offset(); | ||
257 | 263 | | |||
258 | /** | 264 | /** | ||
259 | * update skip offset if new one rules out any later match or is larger than current one | 265 | * update skip offset if new one rules out any later match or is larger than current one | ||
260 | */ | 266 | */ | ||
261 | if (newResult.skipOffset() < 0 || newResult.skipOffset() > currentSkipOffset) | 267 | if (newResult.skipOffset() < 0 || newResult.skipOffset() > currentSkipOffset) { | ||
262 | skipOffsets.insert(rule.get(), newResult.skipOffset()); | 268 | skipOffsets.insert(rule.get(), newResult.skipOffset()); | ||
263 | 269 | | |||
270 | // remember new captures, if dynamic to enforce proper reset above on change! | ||||
271 | if (rule->isDynamic()) { | ||||
272 | capturesForLastDynamicSkipOffset = stateData->topCaptures(); | ||||
273 | } | ||||
274 | } | ||||
275 | | ||||
264 | if (newOffset <= offset) | 276 | if (newOffset <= offset) | ||
265 | continue; | 277 | continue; | ||
266 | 278 | | |||
267 | /** | 279 | /** | ||
268 | * apply folding. | 280 | * apply folding. | ||
269 | * special cases: | 281 | * special cases: | ||
270 | * - rule with endRegion + beginRegion: in endRegion, the length is 0 | 282 | * - rule with endRegion + beginRegion: in endRegion, the length is 0 | ||
271 | * - rule with lookAhead: length is 0 | 283 | * - rule with lookAhead: length is 0 | ||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |