mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Fix #70: overlapping keyword matches show reminder text for both keywords, now longest match is used
This commit is contained in:
+3
-1
@@ -7,7 +7,9 @@
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
* Fixed keywords after atoms (#67)
|
* Fixed: keywords after atoms were not showing up (#67)
|
||||||
|
* Fixed: multiple keywords that matched in the same place both showed reminder text. (#70)
|
||||||
|
Now, when there are overlapping matches the longest one is used.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- 2.1.0, 2020-06-01
|
-- 2.1.0, 2020-06-01
|
||||||
|
|||||||
+12
-11
@@ -443,13 +443,16 @@ void keyword_matches(const String& untagged_str, unordered_set<Keyword const*> k
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void sort_keyword_matches(vector<KeywordMatch>& matches) {
|
void sort_keyword_matches(vector<KeywordMatch>& matches) {
|
||||||
// sort matches by their start position
|
|
||||||
sort(matches.begin(), matches.end(), [](KeywordMatch const& a, KeywordMatch const& b) {
|
sort(matches.begin(), matches.end(), [](KeywordMatch const& a, KeywordMatch const& b) {
|
||||||
|
// sort matches by their start position
|
||||||
if (a.pos < b.pos) return true;
|
if (a.pos < b.pos) return true;
|
||||||
if (a.pos > b.pos) return false;
|
if (a.pos > b.pos) return false;
|
||||||
// otherwise sort by matching set keywords (non-fixed) first
|
// otherwise sort by matching set keywords (non-fixed) first
|
||||||
if (a.keyword->fixed < b.keyword->fixed) return true;
|
if (a.keyword->fixed < b.keyword->fixed) return true;
|
||||||
if (a.keyword->fixed > b.keyword->fixed) return false;
|
if (a.keyword->fixed > b.keyword->fixed) return false;
|
||||||
|
// otherwise sort by longest match first
|
||||||
|
if (a.match[0].length() > b.match[0].length()) return true;
|
||||||
|
if (a.match[0].length() < b.match[0].length()) return false;
|
||||||
// otherwise sort by name
|
// otherwise sort by name
|
||||||
return a.keyword->keyword < b.keyword->keyword;
|
return a.keyword->keyword < b.keyword->keyword;
|
||||||
});
|
});
|
||||||
@@ -522,17 +525,15 @@ String expand_keywords(const String& tagged_str, vector<KeywordMatch> const& mat
|
|||||||
if (atom == 0) {
|
if (atom == 0) {
|
||||||
// don't expand keywords that are inside <atom> tags
|
// don't expand keywords that are inside <atom> tags
|
||||||
while (match_it != matches.end() && match_it->pos <= untagged_pos) {
|
while (match_it != matches.end() && match_it->pos <= untagged_pos) {
|
||||||
if (match_it->pos > untagged_pos) {
|
if (match_it->pos == untagged_pos) {
|
||||||
|
// try to expand
|
||||||
|
auto [match,new_it] = expand_keyword(it, end, *match_it, expand_type, out, options);
|
||||||
++match_it;
|
++match_it;
|
||||||
continue;
|
if (match) {
|
||||||
}
|
untagged_pos += untagged_length(it,new_it);
|
||||||
// try to expand
|
it = new_it;
|
||||||
auto [match,new_it] = expand_keyword(it, end, *match_it, expand_type, out, options);
|
goto after_match;
|
||||||
if (match) {
|
}
|
||||||
untagged_pos += untagged_length(it,new_it);
|
|
||||||
it = new_it;
|
|
||||||
++match_it;
|
|
||||||
goto after_match;
|
|
||||||
} else {
|
} else {
|
||||||
++match_it;
|
++match_it;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user