KTextEditor

scriptrange.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_SCRIPTRANGE_H
8#define KTEXTEDITOR_SCRIPTRANGE_H
9
10#include <QJSEngine>
11#include <QJSValue>
12
13#include "ktexteditor/range.h"
14#include "scriptcursor.h"
15
16inline QJSValue rangeToScriptValue(QJSEngine *engine, KTextEditor::Range range)
17{
18 const auto result = engine->globalObject()
19 .property(QStringLiteral("Range"))
20 .callAsConstructor(QJSValueList() << range.start().line() << range.start().column() << range.end().line() << range.end().column());
21 Q_ASSERT(!result.isError());
22 return result;
23}
24
25inline KTextEditor::Range rangeFromScriptValue(const QJSValue &obj)
26{
27 const auto start = cursorFromScriptValue(obj.property(QStringLiteral("start")));
28 const auto end = cursorFromScriptValue(obj.property(QStringLiteral("end")));
29 return KTextEditor::Range(start, end);
30}
31
32#endif
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
An object representing a section of text, from one Cursor to another.
constexpr Cursor end() const noexcept
Get the end position of this range.
constexpr Cursor start() const noexcept
Get the start position of this range.
Q_SCRIPTABLE Q_NOREPLY void start()
const QList< QKeySequence > & end()
QJSValue globalObject() const const
QJSValue callAsConstructor(const QJSValueList &args) const const
QJSValue property(const QString &name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 11:53:31 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.