KTextEditor

scriptcursor.h
1/*
2 SPDX-FileCopyrightText: 2017 Allan Sandfeld Jensen <kde@carewolf.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KTEXTEDITOR_SCRIPTCURSOR_H
8#define KTEXTEDITOR_SCRIPTCURSOR_H
9
10#include <QJSEngine>
11#include <QJSValue>
12
13#include "ktexteditor/cursor.h"
14
15inline QJSValue cursorToScriptValue(QJSEngine *engine, const KTextEditor::Cursor cursor)
16{
17 const auto result = engine->globalObject().property(QStringLiteral("Cursor")).callAsConstructor(QJSValueList() << cursor.line() << cursor.column());
18 Q_ASSERT(!result.isError());
19 return result;
20}
21
22inline KTextEditor::Cursor cursorFromScriptValue(const QJSValue &obj)
23{
24 const auto line = obj.property(QStringLiteral("line"));
25 const auto column = obj.property(QStringLiteral("column"));
26 return KTextEditor::Cursor(line.toInt(), column.toInt());
27}
28
29#endif
The Cursor represents a position in a Document.
Definition cursor.h:75
constexpr int column() const noexcept
Retrieve the column on which this cursor is situated.
Definition cursor.h:192
constexpr int line() const noexcept
Retrieve the line on which this cursor is situated.
Definition cursor.h:174
QJSValue globalObject() const const
QJSValue callAsConstructor(const QJSValueList &args)
QJSValue property(const QString &name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Feb 24 2024 20:00:58 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.