8#include "katescriptview.h"
10#include "katedocument.h"
11#include "kateglobal.h"
13#include "scriptcursor.h"
14#include "scriptrange.h"
16#include <KLocalizedString>
17#include <KTextEditor/Command>
28void KateScriptView::setView(KTextEditor::ViewPrivate *view)
33KTextEditor::ViewPrivate *KateScriptView::view()
38void KateScriptView::copy()
43void KateScriptView::cut()
48void KateScriptView::paste()
53QJSValue KateScriptView::cursorPosition()
55 return cursorToScriptValue(m_engine, m_view->cursorPosition());
58QJSValue KateScriptView::cursorPositions()
63 for (
int i = 0; i < cursors.size(); ++i) {
64 jsArray.
setProperty(i, cursorToScriptValue(m_engine, cursors[i]));
72 m_view->setCursorPosition(cursor);
77 const auto cursor = cursorFromScriptValue(jscursor);
78 m_view->setCursorPosition(cursor);
81void KateScriptView::setCursorPositions(
const QJSValue &cursors)
85 const int length = cursors.
property(QStringLiteral(
"length")).
toInt();
86 for (
int i = 0; i < length; ++i) {
92QJSValue KateScriptView::virtualCursorPosition()
94 return cursorToScriptValue(m_engine, m_view->cursorPositionVirtual());
97void KateScriptView::setVirtualCursorPosition(
int line,
int column)
100 m_view->setCursorPositionVisual(cursor);
103void KateScriptView::setVirtualCursorPosition(
const QJSValue &jscursor)
105 const auto cursor = cursorFromScriptValue(jscursor);
106 setVirtualCursorPosition(cursor.line(), cursor.column());
109QString KateScriptView::selectedText()
111 return m_view->selectionText();
114bool KateScriptView::hasSelection()
116 return m_view->selection();
121 return rangeToScriptValue(m_engine, m_view->selectionRange());
124QJSValue KateScriptView::selections()
127 const auto ranges = m_view->selectionRanges();
129 for (
int i = 0; i < ranges.size(); ++i) {
130 jsArray.
setProperty(i, rangeToScriptValue(m_engine, ranges[i]));
135void KateScriptView::setSelection(
const QJSValue &jsrange)
137 m_view->setSelection(rangeFromScriptValue(jsrange));
140void KateScriptView::setSelections(
const QJSValue &ranges)
144 const int length = ranges.
property(QStringLiteral(
"length")).
toInt();
145 for (
int i = 0; i < length; ++i) {
148 m_view->setSelections(unboxedRanges);
151void KateScriptView::removeSelectedText()
153 m_view->removeSelectedText();
156void KateScriptView::selectAll()
161void KateScriptView::clearSelection()
163 m_view->clearSelection();
166void KateScriptView::setBlockSelection(
bool on)
168 m_view->setBlockSelection(on);
171bool KateScriptView::blockSelection()
173 return m_view->blockSelection();
176void KateScriptView::align(
const QJSValue &jsrange)
178 const auto range = rangeFromScriptValue(jsrange);
179 m_view->doc()->align(m_view, range);
182void KateScriptView::alignOn(
const QJSValue &jsrange,
const QJSValue &pattern)
187 const auto range = rangeFromScriptValue(jsrange);
188 m_view->doc()->alignOn(range, pattern.
toString(), m_view->blockSelection());
195 return rangeToScriptValue(m_engine, match);
203 const auto range = rangeFromScriptValue(jsrange);
207 message =
i18n(
"Command not found: %1", command);
209 const auto cmdLine = args.
isEmpty() ? (command) : (command +
QLatin1Char(
' ') + args);
210 ok = cmd->exec(m_view, cmdLine, message, range);
215 object.setProperty(QStringLiteral(
"status"), message);
219#include "moc_katescriptview.cpp"
The Cursor represents a position in a Document.
KTextEditor::Command * queryCommand(const QString &cmd) const override
query for command
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
An object representing a section of text, from one Cursor to another.
void setCursorPositions(const QList< KTextEditor::Cursor > &positions)
Set the view's new cursors to positions.
QList< KTextEditor::Cursor > cursorPositions() const
Get the view's current cursor positions.
KateScriptView(QJSEngine *, QObject *parent=nullptr)
Properties are accessible with a nicer syntax from JavaScript.
Q_INVOKABLE void setCursorPosition(int line, int column)
Set the cursor position in the view.
QString i18n(const char *text, const TYPE &arg...)
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
@ Default
Default settings.
@ Backwards
Searches in backward direction.
QJSValue newArray(uint length)
bool isString() const const
QJSValue property(const QString &name) const const
void setProperty(const QString &name, const QJSValue &value)
qint32 toInt() const const
QString toString() const const
void append(QList< T > &&value)
bool isEmpty() const const