forked from qt-creator/qt-creator
FancyLineEdit: Add camel case navigation
Use it for search and replace functions as well as for Locator. The camel case navigation can be switched on / off with the existing menu Options > Text Editor > Behavior > Enable Build-in camel case navigation. Fixes: QTCREATORBUG-21140 Change-Id: I3f2dcafff231366b3c8f08c14514dd8940cca2a0 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
71e9e3832a
commit
839f45faa9
@@ -23,6 +23,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "camelcasecursor.h"
|
||||
#include "execmenu.h"
|
||||
#include "fancylineedit.h"
|
||||
#include "historycompleter.h"
|
||||
@@ -80,6 +81,8 @@ enum { margin = 6 };
|
||||
|
||||
namespace Utils {
|
||||
|
||||
static bool camelCaseNavigation = false;
|
||||
|
||||
// --------- FancyLineEditPrivate
|
||||
class FancyLineEditPrivate : public QObject
|
||||
{
|
||||
@@ -328,6 +331,24 @@ void FancyLineEdit::onEditingFinished()
|
||||
d->m_historyCompleter->addEntry(text());
|
||||
}
|
||||
|
||||
void FancyLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
const QTextCursor::MoveMode mode = (event->modifiers() & Qt::ShiftModifier)
|
||||
? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor;
|
||||
|
||||
if (camelCaseNavigation && event == QKeySequence::MoveToPreviousWord)
|
||||
CamelCaseCursor::left(this, mode);
|
||||
else if (camelCaseNavigation && event == QKeySequence::MoveToNextWord)
|
||||
CamelCaseCursor::right(this, mode);
|
||||
else
|
||||
QLineEdit::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void FancyLineEdit::setCamelCaseNavigationEnabled(bool enabled)
|
||||
{
|
||||
camelCaseNavigation = enabled;
|
||||
}
|
||||
|
||||
void FancyLineEdit::setSpecialCompleter(QCompleter *completer)
|
||||
{
|
||||
QTC_ASSERT(!d->m_historyCompleter, return);
|
||||
|
||||
Reference in New Issue
Block a user