From 93a6dd0c6705c23ebe81753c7774bfdab61f9824 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 23 Aug 2018 08:59:36 +0200 Subject: [PATCH] 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 --- src/libs/utils/pathchooser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 7fde56993e4..142d061682a 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 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)