TextEditor: add macro variable containing the word under cursor

Fixes: QTCREATORBUG-24836
Change-Id: Ib872fd12e5842bdb752dd3969ef9c5eb9dd2f650
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2020-10-26 12:06:59 +01:00
parent 48a6f8ad82
commit d03f723060

View File

@@ -67,6 +67,7 @@ static const char kCurrentDocumentColumn[] = "CurrentDocument:Column";
static const char kCurrentDocumentRowCount[] = "CurrentDocument:RowCount";
static const char kCurrentDocumentColumnCount[] = "CurrentDocument:ColumnCount";
static const char kCurrentDocumentFontSize[] = "CurrentDocument:FontSize";
static const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor";
class TextEditorPluginPrivate : public QObject
{
@@ -234,6 +235,15 @@ void TextEditorPlugin::extensionsInitialized()
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
return editor ? editor->widget()->font().pointSize() : 0;
});
expander->registerVariable(kCurrentDocumentWordUnderCursor,
tr("Word under the current document's text cursor."),
[]() {
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
if (!editor)
return QString();
return Text::wordUnderCursor(editor->editorWidget()->textCursor());
});
}
LineNumberFilter *TextEditorPlugin::lineNumberFilter()