if (ch.assigned_signal)
continue;
+ const QString ch_name = ch.name.toLower();
+
+ shared_ptr<data::SignalBase> match;
for (shared_ptr<data::SignalBase> s : session_.signalbases()) {
if (!s->enabled())
continue;
- const QString ch_name = ch.name.toLower();
const QString s_name = s->name().toLower();
if (s->logic_data() &&
((ch_name.contains(s_name)) || (s_name.contains(ch_name)))) {
- ch.assigned_signal = s.get();
- new_assignment = true;
+ if (!match)
+ match = s;
+ else {
+ // Only replace an existing match if it matches more characters
+ int old_unmatched = ch_name.length() - match->name().length();
+ int new_unmatched = ch_name.length() - s->name().length();
+ if (abs(new_unmatched) < abs(old_unmatched))
+ match = s;
+ }
}
}
+
+ if (match) {
+ ch.assigned_signal = match.get();
+ new_assignment = true;
+ }
}
if (new_assignment) {