diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index d7b75672dd6..4d22e9115e0 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -1357,6 +1357,15 @@ bool TextEditorWidget::selectBlockDown() return true; } +void TextEditorWidget::selectWordUnderCursor() +{ + QTextCursor tc = textCursor(); + if (tc.hasSelection()) + return; + tc.select(QTextCursor::WordUnderCursor); + setTextCursor(tc); +} + void TextEditorWidget::copyLineUp() { d->copyLineUpDown(true); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 982af31662f..7048ddb923f 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -396,6 +396,7 @@ public: virtual bool selectBlockUp(); virtual bool selectBlockDown(); + void selectWordUnderCursor(); void moveLineUp(); void moveLineDown(); diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 4e6213bca67..81472b6eeae 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -451,6 +451,9 @@ void TextEditorActionHandlerPrivate::createActions() [this] (TextEditorWidget *w) { w->selectBlockDown(); }, true, tr("Select Block Down"), QKeySequence(tr("Ctrl+Shift+Alt+U")), G_EDIT_BLOCKS, advancedEditMenu); + registerAction(SELECT_WORD_UNDER_CURSOR, + [this] (TextEditorWidget *w) { w->selectWordUnderCursor(); }, true, + tr("Select Word Under Cursor")); // register GOTO Actions registerAction(GOTO_LINE_START, diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 8b8180c407d..f68b41cc0db 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -127,6 +127,7 @@ const char GOTO_BLOCK_END[] = "TextEditor.GotoBlockEnd"; const char GOTO_BLOCK_END_WITH_SELECTION[] = "TextEditor.GotoBlockEndWithSelection"; const char SELECT_BLOCK_UP[] = "TextEditor.SelectBlockUp"; const char SELECT_BLOCK_DOWN[] = "TextEditor.SelectBlockDown"; +const char SELECT_WORD_UNDER_CURSOR[] = "TextEditor.SelectWordUnderCursor"; const char VIEW_PAGE_UP[] = "TextEditor.viewPageUp"; const char VIEW_PAGE_DOWN[] = "TextEditor.viewPageDown"; const char VIEW_LINE_UP[] = "TextEditor.viewLineUp";