forked from qt-creator/qt-creator
LUA: Add TextCursor's movePosition and create within TextEditor
Change-Id: Ic4fd9c65c92641c4267cd2fdb3937746c2065baa Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -240,9 +240,21 @@ void setupTextEditorModule()
|
||||
"to",
|
||||
sol::property(&Range::end, &Range::end));
|
||||
|
||||
result.new_usertype<QTextCursor>(
|
||||
auto textCursorType = result.new_usertype<QTextCursor>(
|
||||
"TextCursor",
|
||||
sol::no_constructor,
|
||||
"create",
|
||||
sol::overload(
|
||||
[]() {
|
||||
return QTextCursor();
|
||||
},
|
||||
[](QTextDocument *doc) {
|
||||
return QTextCursor(doc);
|
||||
},
|
||||
[](const QTextCursor &other) {
|
||||
return QTextCursor(other);
|
||||
}
|
||||
),
|
||||
"position",
|
||||
&QTextCursor::position,
|
||||
"blockNumber",
|
||||
@@ -279,7 +291,55 @@ void setupTextEditorModule()
|
||||
return ret;
|
||||
},
|
||||
"insertText",
|
||||
[](QTextCursor *textCursor, const QString &text) { textCursor->insertText(text); });
|
||||
[](QTextCursor *textCursor, const QString &text) { textCursor->insertText(text); },
|
||||
"movePosition",
|
||||
sol::overload(
|
||||
[](QTextCursor *cursor, QTextCursor::MoveOperation op) {
|
||||
cursor->movePosition(op);
|
||||
},
|
||||
[](QTextCursor *cursor, QTextCursor::MoveOperation op, QTextCursor::MoveMode mode) {
|
||||
cursor->movePosition(op, mode);
|
||||
},
|
||||
[](QTextCursor *cursor, QTextCursor::MoveOperation op, QTextCursor::MoveMode mode, int n) {
|
||||
cursor->movePosition(op, mode, n);
|
||||
}
|
||||
));
|
||||
|
||||
textCursorType["MoveMode"] = lua.create_table_with(
|
||||
"MoveAnchor", QTextCursor::MoveAnchor,
|
||||
"KeepAnchor", QTextCursor::KeepAnchor
|
||||
);
|
||||
|
||||
textCursorType["MoveOperation"] = lua.create_table_with(
|
||||
"NoMove", QTextCursor::NoMove,
|
||||
|
||||
"Start", QTextCursor::Start,
|
||||
"Up", QTextCursor::Up,
|
||||
"StartOfLine", QTextCursor::StartOfLine,
|
||||
"StartOfBlock", QTextCursor::StartOfBlock,
|
||||
"StartOfWord", QTextCursor::StartOfWord,
|
||||
"PreviousBlock", QTextCursor::PreviousBlock,
|
||||
"PreviousCharacter",QTextCursor::PreviousCharacter,
|
||||
"PreviousWord", QTextCursor::PreviousWord,
|
||||
"Left", QTextCursor::Left,
|
||||
"WordLeft", QTextCursor::WordLeft,
|
||||
|
||||
"End", QTextCursor::End,
|
||||
"Down", QTextCursor::Down,
|
||||
"EndOfLine", QTextCursor::EndOfLine,
|
||||
"EndOfWord", QTextCursor::EndOfWord,
|
||||
"EndOfBlock", QTextCursor::EndOfBlock,
|
||||
"NextBlock", QTextCursor::NextBlock,
|
||||
"NextCharacter", QTextCursor::NextCharacter,
|
||||
"NextWord", QTextCursor::NextWord,
|
||||
"Right", QTextCursor::Right,
|
||||
"WordRight", QTextCursor::WordRight,
|
||||
|
||||
"NextCell", QTextCursor::NextCell,
|
||||
"PreviousCell", QTextCursor::PreviousCell,
|
||||
"NextRow", QTextCursor::NextRow,
|
||||
"PreviousRow", QTextCursor::PreviousRow
|
||||
);
|
||||
|
||||
using LayoutOrWidget = std::variant<Layouting::Layout *, Layouting::Widget *, QWidget *>;
|
||||
|
||||
|
@@ -18,6 +18,63 @@ local Range = {}
|
||||
---@class TextCursor
|
||||
local TextCursor = {}
|
||||
|
||||
---@enum TextCursor.MoveOperation
|
||||
---Move operations for a TextCursor.
|
||||
TextCursor.MoveOperation = {
|
||||
NoMove = 0,
|
||||
|
||||
Start = 0,
|
||||
Up = 0,
|
||||
StartOfLine = 0,
|
||||
StartOfBlock = 0,
|
||||
StartOfWord = 0,
|
||||
PreviousBlock = 0,
|
||||
PreviousCharacter = 0,
|
||||
PreviousWord = 0,
|
||||
Left = 0,
|
||||
WordLeft = 0,
|
||||
|
||||
End = 0,
|
||||
Down = 0,
|
||||
EndOfLine = 0,
|
||||
EndOfWord = 0,
|
||||
EndOfBlock = 0,
|
||||
NextBlock = 0,
|
||||
NextCharacter = 0,
|
||||
NextWord = 0,
|
||||
Right = 0,
|
||||
WordRight = 0,
|
||||
|
||||
NextCell = 0,
|
||||
PreviousCell = 0,
|
||||
NextRow = 0,
|
||||
PreviousRow = 0
|
||||
}
|
||||
|
||||
---@enum TextCursor.MoveMode
|
||||
---Specifies how the cursor moves (with or without anchoring the selection).
|
||||
TextCursor.MoveMode = {
|
||||
MoveAnchor = 0,
|
||||
KeepAnchor = 0
|
||||
}
|
||||
|
||||
---Creates a new `TextCursor` object.
|
||||
---
|
||||
---**Overload 1**: `TextCursor.create()`
|
||||
--- No parameters. Creates a default-constructed cursor.
|
||||
---
|
||||
---**Overload 2**: `TextCursor.create(doc)`
|
||||
--- - `doc`: A `QTextDocument*` (or usertype) from which to create the cursor.
|
||||
---
|
||||
---**Overload 3**: `TextCursor.create(other)`
|
||||
--- - `other`: Another `TextCursor` to copy.
|
||||
---
|
||||
---@overload fun(): TextCursor
|
||||
---@overload fun(doc: any): TextCursor
|
||||
---@overload fun(other: TextCursor): TextCursor
|
||||
---@return TextCursor
|
||||
function TextCursor.create(...) end
|
||||
|
||||
---Returns the position of the cursor.
|
||||
---@return integer position The position of the cursor.
|
||||
function TextCursor:position() end
|
||||
@@ -46,6 +103,27 @@ function TextCursor:selectionRange() end
|
||||
---@param text string The text to insert.
|
||||
function TextCursor:insertText(text) end
|
||||
|
||||
---Moves the cursor using a specified operation, and optionally a mode and/or repetition count.
|
||||
---
|
||||
---**Overload 1**: `cursor:movePosition(operation)`
|
||||
--- - `operation`: A `TextCursor.MoveOperation`.
|
||||
--- - Moves once, using the default mode `MoveAnchor`.
|
||||
---
|
||||
---**Overload 2**: `cursor:movePosition(operation, mode)`
|
||||
--- - `operation`: A `TextCursor.MoveOperation`.
|
||||
--- - `mode`: A `TextCursor.MoveMode` (e.g. `MoveAnchor` or `KeepAnchor`).
|
||||
---
|
||||
---**Overload 3**: `cursor:movePosition(operation, mode, n)`
|
||||
--- - `operation`: A `TextCursor.MoveOperation`.
|
||||
--- - `mode`: A `TextCursor.MoveMode`.
|
||||
--- - `n`: Number of times to repeat the move.
|
||||
---
|
||||
---@overload fun(operation: TextCursor.MoveOperation)
|
||||
---@overload fun(operation: TextCursor.MoveOperation, mode: TextCursor.MoveMode)
|
||||
---@overload fun(operation: TextCursor.MoveOperation, mode: TextCursor.MoveMode, n: integer)
|
||||
function TextCursor:movePosition(operation, mode, n) end
|
||||
|
||||
|
||||
---@class MultiTextCursor
|
||||
local MultiTextCursor = {}
|
||||
|
||||
|
Reference in New Issue
Block a user