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(args: 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: obj.property(QStringLiteral("start")));
28 const auto end = cursorFromScriptValue(obj: obj.property(QStringLiteral("end")));
29 return KTextEditor::Range(start, end);
30}
31
32#endif
33

source code of ktexteditor/src/script/scriptrange.h