Skip to content

Commit

Permalink
FIX issue #19 where multiple widget values led to bad replacements in…
Browse files Browse the repository at this point in the history
… the command
  • Loading branch information
tibirna committed Nov 6, 2022
1 parent 958af3e commit 6e95bf4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/inputdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ bool InputDialog::validate()
QString InputDialog::replace(const VariableMap &variables) const
{
QString result = cmd;
int shift = 0, start = 0, len = 0; // will keep track of position shifts during replacements
for (WidgetMap::const_iterator it = widgets.begin(), end = widgets.end(); it != end; ++it) {
QString token = "%" + it.key() + "%";
WidgetItemPtr item = it.value();
start = item->start - shift;
len = item->end - item->start;
QString value = item->widget->property(item->prop_name).toString();
result.replace(item->start, item->end - item->start, value); // replace main token
result.replace(start, len, value); // replace main token
shift += len - value.length();
result.replace(token, value); // replace all other occurences of %name%
}
for (VariableMap::const_iterator it=variables.begin(), end=variables.end(); it != end; ++it) {
Expand Down

0 comments on commit 6e95bf4

Please sign in to comment.