From fd0f8dc897c46269ae37830583362c2227ad27cb Mon Sep 17 00:00:00 2001 From: Lukasz Papierkowski Date: Tue, 24 Sep 2024 18:16:29 +0200 Subject: [PATCH] LUA: Add hasSuggestionLocked() method to TextEditor and clenaup Change-Id: Iff0c1af586b69c930c55327f70a513ef94a5f879 Reviewed-by: Artur Twardy Reviewed-by: Marcus Tillmanns --- src/plugins/lua/bindings/texteditor.cpp | 15 +++++---------- src/plugins/lua/meta/texteditor.lua | 14 ++++---------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/plugins/lua/bindings/texteditor.cpp b/src/plugins/lua/bindings/texteditor.cpp index fc7e2633712..81fbbbefc8d 100644 --- a/src/plugins/lua/bindings/texteditor.cpp +++ b/src/plugins/lua/bindings/texteditor.cpp @@ -149,16 +149,6 @@ void setupTextEditorModule() return TextEditor::BaseTextEditor::currentTextEditor(); }; - result["currentSuggestion"] = []() -> TextEditor::CyclicSuggestion * { - if (const auto *textEditor = TextEditor::BaseTextEditor::currentTextEditor()) { - if (const TextEditor::TextEditorWidget *widget = textEditor->editorWidget()) - return dynamic_cast(widget->currentSuggestion()); - } - return nullptr; - }; - - result.new_usertype("CyclicSuggestion", sol::no_constructor); - result.new_usertype( "MultiTextCursor", sol::no_constructor, @@ -249,6 +239,11 @@ void setupTextEditorModule() [](const TextEditorPtr &textEditor) { QTC_ASSERT(textEditor, throw sol::error("TextEditor is not valid")); return textEditor->editorWidget()->multiTextCursor(); + }, + "hasLockedSuggestion", + [](const TextEditorPtr &textEditor) { + QTC_ASSERT(textEditor, throw sol::error("TextEditor is not valid")); + return textEditor->editorWidget()->suggestionVisible(); }); result.new_usertype( diff --git a/src/plugins/lua/meta/texteditor.lua b/src/plugins/lua/meta/texteditor.lua index ebf1d0e6ad0..11c825d1124 100644 --- a/src/plugins/lua/meta/texteditor.lua +++ b/src/plugins/lua/meta/texteditor.lua @@ -60,13 +60,6 @@ local Suggestion = {} ---@return Suggestion suggestion The created suggestion. function Suggestion:create(startLine, startCharacter, endLine, endCharacter, text) end ----@class CyclicSuggestion -local CyclicSuggestion = {} - ----@return boolean True if the suggestion is locked, false otherwise. ----Suggestion is locked when the user selects it and already started applying it partially. -function CyclicSuggestion:isLocked() end - ---@class TextDocument local TextDocument = {} @@ -106,12 +99,13 @@ function TextEditor:cursor() end ---@param position integer The position in the document where the widget should appear. function TextEditor:addFloatingWidget(widget, position) end +---Checks if the current suggestion is locked. The suggestion is locked when the user can use it. +---@return boolean True if the suggestion is locked, false otherwise. +function TextEditor:hasLockedSuggestion() 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 ----Returns the current suggestion of the current editor if available. ----@return CyclicSuggestion|nil suggestion The current suggestion if available. Otherwise nil. -function textEditor.currentSuggestion() end return textEditor