Lua: add bindings to insert text into editor/cursors

Change-Id: Ia2b97c08be352bfa7d97141f863ffc41861a30eb
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2024-10-10 14:56:41 +02:00
parent 0b17389db1
commit 0fefc7886a
2 changed files with 25 additions and 1 deletions

View File

@@ -166,7 +166,11 @@ void setupTextEditorModule()
"mainCursor",
&MultiTextCursor::mainCursor,
"cursors",
[](MultiTextCursor *self) { return sol::as_table(self->cursors()); });
[](MultiTextCursor *self) { return sol::as_table(self->cursors()); },
"insertText",
[](MultiTextCursor *self, const QString &text) {
self->insertText(text);
});
result.new_usertype<Position>(
"Position",
@@ -222,6 +226,10 @@ void setupTextEditorModule()
ret.end.line = endBlock.blockNumber();
ret.end.column = endPos - endBlock.position() - 1;
return ret;
},
"insertText",
[](QTextCursor *textCursor, const QString &text) {
textCursor->insertText(text);
});
result.new_usertype<BaseTextEditor>(
@@ -255,6 +263,10 @@ void setupTextEditorModule()
[](const TextEditorPtr &textEditor) {
QTC_ASSERT(textEditor, throw sol::error("TextEditor is not valid"));
return textEditor->editorWidget()->suggestionVisible();
},
"insertText",
[](TextEditorPtr editor, const QString &text) {
editor->editorWidget()->multiTextCursor().insertText(text);
});
result.new_usertype<TextSuggestion::Data>(

View File

@@ -38,6 +38,10 @@ function TextCursor:selectedText() end
---@return Range selectionRange The range of selected text of the cursor.
function TextCursor:selectionRange() end
---Inserts the passed text at the cursors position overwriting any selected text.
---@param text string The text to insert.
function TextCursor:insertText(text) end
---@class MultiTextCursor
local MultiTextCursor = {}
@@ -49,6 +53,10 @@ function MultiTextCursor:mainCursor() end
---@return TextCursor[] cursors The cursors.
function MultiTextCursor:cursors() end
---Inserts the passed text at all cursor positions overwriting any selected text.
---@param text string The text to insert.
function MultiTextCursor:insertText(text) end
---@class Suggestion
local Suggestion = {}
@@ -106,6 +114,10 @@ function TextEditor:addFloatingWidget(widget, position) end
---@return boolean True if the suggestion is locked, false otherwise.
function TextEditor:hasLockedSuggestion() end
---Inserts the passed text at all cursor positions overwriting any selected text.
---@param text string The text to insert.
function TextEditor:insertText(text) end
---Returns the current editor or nil.
---@return TextEditor|nil editor The currently active editor or nil if there is none.
function textEditor.currentEditor() end