forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user