aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2018-08-23 08:59:36 +0200
committerEike Ziller <eike.ziller@qt.io>2018-08-28 08:12:12 +0000
commit93a6dd0c6705c23ebe81753c7774bfdab61f9824 (patch)
tree9c90c497c53fe5f89c6188a2222d34ea6d9aadb3
parentd2146644a69c1d130b42d611c2591c8dbdbc8abf (diff)
Fix editing of custom executable path
When editing the path for a custom executable run configuration, the text cursor would jump to the end every time anything is typed. This makes changing a part inside the text very cumbersome. This happens because the executable aspect registers a "display filter" that transforms the input to native separators. Solve that issue generically for the path chooser by resetting its text cursor position after the path has been set, if the input field has focus. Change-Id: Ic0a178e942da8df1e53b5d90c78a5bf1675865c2 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
-rw-r--r--src/libs/utils/pathchooser.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp
index 7fde56993e..142d061682 100644
--- a/src/libs/utils/pathchooser.cpp
+++ b/src/libs/utils/pathchooser.cpp
@@ -26,6 +26,7 @@
#include "pathchooser.h"
#include "environment.h"
+#include "optional.h"
#include "qtcassert.h"
#include "synchronousprocess.h"
@@ -340,14 +341,22 @@ QString PathChooser::expandedDirectory(const QString &input, const Environment &
return path;
}
+void setTextKeepingActiveCursor(QLineEdit *edit, const QString &text)
+{
+ optional<int> cursor = edit->hasFocus() ? make_optional(edit->cursorPosition()) : nullopt;
+ edit->setText(text);
+ if (cursor)
+ edit->setCursorPosition(*cursor);
+}
+
void PathChooser::setPath(const QString &path)
{
- d->m_lineEdit->setText(QDir::toNativeSeparators(path));
+ setTextKeepingActiveCursor(d->m_lineEdit, QDir::toNativeSeparators(path));
}
void PathChooser::setFileName(const FileName &fn)
{
- d->m_lineEdit->setText(fn.toUserOutput());
+ setTextKeepingActiveCursor(d->m_lineEdit, fn.toUserOutput());
}
void PathChooser::setErrorColor(const QColor &errorColor)