forked from qt-creator/qt-creator
Lua: Add TextEditor::currentEditor
Change-Id: I4a2e4703bca2b557aac4240d7bc2519f7b50217b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -97,10 +97,14 @@ void addTextEditorModule()
|
|||||||
{
|
{
|
||||||
TextEditorRegistry::instance();
|
TextEditorRegistry::instance();
|
||||||
|
|
||||||
LuaEngine::registerProvider("TextDocument", [](sol::state_view lua) -> sol::object {
|
LuaEngine::registerProvider("TextEditor", [](sol::state_view lua) -> sol::object {
|
||||||
sol::table documents = lua.create_table();
|
sol::table result = lua.create_table();
|
||||||
|
|
||||||
documents.new_usertype<Utils::MultiTextCursor>(
|
result["currentEditor"] = []() -> TextEditor::BaseTextEditor * {
|
||||||
|
return TextEditor::BaseTextEditor::currentTextEditor();
|
||||||
|
};
|
||||||
|
|
||||||
|
result.new_usertype<Utils::MultiTextCursor>(
|
||||||
"MultiTextCursor",
|
"MultiTextCursor",
|
||||||
sol::no_constructor,
|
sol::no_constructor,
|
||||||
"mainCursor",
|
"mainCursor",
|
||||||
@@ -108,7 +112,7 @@ void addTextEditorModule()
|
|||||||
"cursors",
|
"cursors",
|
||||||
&Utils::MultiTextCursor::cursors);
|
&Utils::MultiTextCursor::cursors);
|
||||||
|
|
||||||
documents.new_usertype<QTextCursor>(
|
result.new_usertype<QTextCursor>(
|
||||||
"TextCursor",
|
"TextCursor",
|
||||||
sol::no_constructor,
|
sol::no_constructor,
|
||||||
"position",
|
"position",
|
||||||
@@ -118,7 +122,7 @@ void addTextEditorModule()
|
|||||||
"columnNumber",
|
"columnNumber",
|
||||||
&QTextCursor::columnNumber);
|
&QTextCursor::columnNumber);
|
||||||
|
|
||||||
documents.new_usertype<TextEditor::BaseTextEditor>(
|
result.new_usertype<TextEditor::BaseTextEditor>(
|
||||||
"TextEditor",
|
"TextEditor",
|
||||||
sol::no_constructor,
|
sol::no_constructor,
|
||||||
"document",
|
"document",
|
||||||
@@ -128,7 +132,7 @@ void addTextEditorModule()
|
|||||||
return textEditor->editorWidget()->multiTextCursor();
|
return textEditor->editorWidget()->multiTextCursor();
|
||||||
});
|
});
|
||||||
|
|
||||||
documents.new_usertype<TextEditor::TextDocument>(
|
result.new_usertype<TextEditor::TextDocument>(
|
||||||
"TextDocument",
|
"TextDocument",
|
||||||
sol::no_constructor,
|
sol::no_constructor,
|
||||||
"file",
|
"file",
|
||||||
@@ -147,7 +151,7 @@ void addTextEditorModule()
|
|||||||
"blockCount",
|
"blockCount",
|
||||||
[](TextEditor::TextDocument *document) { return document->document()->blockCount(); });
|
[](TextEditor::TextDocument *document) { return document->document()->blockCount(); });
|
||||||
|
|
||||||
return documents;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
LuaEngine::registerHook("editors.text.currentChanged", [](sol::function func, QObject *guard) {
|
LuaEngine::registerHook("editors.text.currentChanged", [](sol::function func, QObject *guard) {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
---@meta TextEditor
|
---@meta TextEditor
|
||||||
|
local textEditor = {}
|
||||||
|
|
||||||
---@class TextCursor
|
---@class TextCursor
|
||||||
---@field position integer The position of the cursor.
|
---@field position integer The position of the cursor.
|
||||||
@@ -39,4 +40,8 @@ function TextEditor:document() end
|
|||||||
---@return MultiTextCursor cursor The cursor of the editor.
|
---@return MultiTextCursor cursor The cursor of the editor.
|
||||||
function TextEditor:cursor() end
|
function TextEditor:cursor() end
|
||||||
|
|
||||||
return TextDocument
|
---Returns the current editor or nil.
|
||||||
|
---@return TextEditor|nil editor The currently active editor or nil if there is none.
|
||||||
|
function textEditor.currentEditor() end
|
||||||
|
|
||||||
|
return textEditor
|
||||||
|
Reference in New Issue
Block a user