From b14e54b4584d19c7c9a50b7d30eadd7e16299517 Mon Sep 17 00:00:00 2001 From: mae <qt-info@nokia.com> Date: Wed, 10 Nov 2010 12:53:45 +0100 Subject: [PATCH] Extend camel-case cursor movement We now have different actions to bind to (saves us an explicit option). Small fixes to state machines. Done-with: Erik Verbruggen --- src/plugins/texteditor/basetexteditor.cpp | 33 +++++++++++++++++++ src/plugins/texteditor/basetexteditor.h | 4 +++ .../texteditor/texteditoractionhandler.cpp | 16 +++++++++ .../texteditor/texteditoractionhandler.h | 4 +++ src/plugins/texteditor/texteditorconstants.h | 4 +++ 5 files changed, 61 insertions(+) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 9b9900f5bb1..6f0661b8d3b 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -811,6 +811,35 @@ void BaseTextEditor::gotoNextWordWithSelection() moveCursor(QTextCursor::NextWord, QTextCursor::KeepAnchor); } +void BaseTextEditor::gotoPreviousWordCamelCase() +{ + QTextCursor c = textCursor(); + camelCaseLeft(c, QTextCursor::MoveAnchor); + setTextCursor(c); +} + +void BaseTextEditor::gotoPreviousWordCamelCaseWithSelection() +{ + QTextCursor c = textCursor(); + camelCaseLeft(c, QTextCursor::KeepAnchor); + setTextCursor(c); +} + +void BaseTextEditor::gotoNextWordCamelCase() +{ + qDebug() << Q_FUNC_INFO; + QTextCursor c = textCursor(); + camelCaseRight(c, QTextCursor::MoveAnchor); + setTextCursor(c); +} + +void BaseTextEditor::gotoNextWordCamelCaseWithSelection() +{ + QTextCursor c = textCursor(); + camelCaseRight(c, QTextCursor::KeepAnchor); + setTextCursor(c); +} + static QTextCursor flippedCursor(const QTextCursor &cursor) @@ -1146,6 +1175,7 @@ bool BaseTextEditor::camelCaseLeft(QTextCursor &cursor, QTextCursor::MoveMode mo case Input_U: break; default: + cursor.movePosition(QTextCursor::Right, mode); return true; } break; @@ -1266,6 +1296,9 @@ bool BaseTextEditor::camelCaseRight(QTextCursor &cursor, QTextCursor::MoveMode m case Input_l: cursor.movePosition(QTextCursor::Left, mode); return true; + case Input_underscore: + state = 6; + break; case Input_space: state = 7; break; diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 9296b581269..f0774c75b07 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -268,6 +268,10 @@ public slots: void gotoPreviousWordWithSelection(); void gotoNextWord(); void gotoNextWordWithSelection(); + void gotoPreviousWordCamelCase(); + void gotoPreviousWordCamelCaseWithSelection(); + void gotoNextWordCamelCase(); + void gotoNextWordCamelCaseWithSelection(); void selectBlockUp(); void selectBlockDown(); diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index df4d0959b2d..d5e20aa9ee4 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -327,6 +327,12 @@ void TextEditorActionHandler::createActions() a = new QAction(tr("Goto Next Word"), this); command = am->registerAction(a, Constants::GOTO_NEXT_WORD, m_contextId); connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWord())); + a = new QAction(tr("Goto Previous Word Camel Case"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD_CAMEL_CASE, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWordCamelCase())); + a = new QAction(tr("Goto Next Word Camel Case"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_WORD_CAMEL_CASE, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordCamelCase())); a = new QAction(tr("Goto Line Start With Selection"), this); command = am->registerAction(a, Constants::GOTO_LINE_START_WITH_SELECTION, m_contextId); @@ -352,6 +358,12 @@ void TextEditorActionHandler::createActions() a = new QAction(tr("Goto Next Word With Selection"), this); command = am->registerAction(a, Constants::GOTO_NEXT_WORD_WITH_SELECTION, m_contextId); connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordWithSelection())); + a = new QAction(tr("Goto Previous Word Camel Case With Selection"), this); + command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWordCamelCaseWithSelection())); + a = new QAction(tr("Goto Next Word Camel Case With Selection"), this); + command = am->registerAction(a, Constants::GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION, m_contextId); + connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordCamelCaseWithSelection())); } @@ -532,8 +544,12 @@ FUNCTION(gotoNextCharacter) FUNCTION(gotoNextCharacterWithSelection) FUNCTION(gotoPreviousWord) FUNCTION(gotoPreviousWordWithSelection) +FUNCTION(gotoPreviousWordCamelCase) +FUNCTION(gotoPreviousWordCamelCaseWithSelection) FUNCTION(gotoNextWord) FUNCTION(gotoNextWordWithSelection) +FUNCTION(gotoNextWordCamelCase) +FUNCTION(gotoNextWordCamelCaseWithSelection) void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor) diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index cfa7f019d7e..eaf9049ade6 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -136,6 +136,10 @@ private slots: void gotoPreviousWordWithSelection(); void gotoNextWord(); void gotoNextWordWithSelection(); + void gotoPreviousWordCamelCase(); + void gotoPreviousWordCamelCaseWithSelection(); + void gotoNextWordCamelCase(); + void gotoNextWordCamelCaseWithSelection(); private: diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 56ca8961c65..83b4261e02f 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -78,6 +78,8 @@ const char * const GOTO_PREVIOUS_CHARACTER = "TextEditor.GotoPreviousCharacter"; const char * const GOTO_NEXT_CHARACTER = "TextEditor.GotoNextCharacter"; const char * const GOTO_PREVIOUS_WORD = "TextEditor.GotoPreviousWord"; const char * const GOTO_NEXT_WORD = "TextEditor.GotoNextWord"; +const char * const GOTO_PREVIOUS_WORD_CAMEL_CASE = "TextEditor.GotoPreviousWordCamelCase"; +const char * const GOTO_NEXT_WORD_CAMEL_CASE = "TextEditor.GotoNextWordCamelCase"; const char * const GOTO_LINE_START_WITH_SELECTION = "TextEditor.GotoLineStartWithSelection"; const char * const GOTO_LINE_END_WITH_SELECTION = "TextEditor.GotoLineEndWithSelection"; const char * const GOTO_NEXT_LINE_WITH_SELECTION = "TextEditor.GotoNextLineWithSelection"; @@ -86,6 +88,8 @@ const char * const GOTO_PREVIOUS_CHARACTER_WITH_SELECTION = "TextEditor.GotoPrev const char * const GOTO_NEXT_CHARACTER_WITH_SELECTION = "TextEditor.GotoNextCharacterWithSelection"; const char * const GOTO_PREVIOUS_WORD_WITH_SELECTION = "TextEditor.GotoPreviousWordWithSelection"; const char * const GOTO_NEXT_WORD_WITH_SELECTION = "TextEditor.GotoNextWordWithSelection"; +const char * const GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION = "TextEditor.GotoPreviousWordCamelCaseWithSelection"; +const char * const GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION = "TextEditor.GotoNextWordCamelCaseWithSelection"; const char * const C_TEXTEDITOR_MIMETYPE_TEXT = "text/plain"; const char * const INFO_SYNTAX_DEFINITION = "TextEditor.InfoSyntaxDefinition"; const char * const TASK_DOWNLOAD_DEFINITIONS = "TextEditor.Task.Download"; -- GitLab