From 6e95bf4d8ad85645986ba94aaa04a115a9dcc010 Mon Sep 17 00:00:00 2001 From: Cristian Tibirna Date: Sun, 6 Nov 2022 09:48:09 -0500 Subject: [PATCH] FIX issue #19 where multiple widget values led to bad replacements in the command --- src/inputdialog.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index a79fafb..5244e46 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -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) { -- 2.11.4.GIT