KTextEditor

katescriptdocument.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Paul Giannaros <paul@giannaros.org>
3 SPDX-FileCopyrightText: 2009-2018 Dominik Haumann <dhaumann@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "katescriptdocument.h"
9
10#include "katebuffer.h"
11#include "kateconfig.h"
12#include "katedocument.h"
13#include "katehighlight.h"
14#include "katepartdebug.h"
15#include "katescript.h"
16#include "scriptcursor.h"
17#include "scriptrange.h"
18
19#include <QJSEngine>
20#include <ktexteditor/documentcursor.h>
21
22KateScriptDocument::KateScriptDocument(QJSEngine *engine, QObject *parent)
23 : QObject(parent)
24 , m_document(nullptr)
25 , m_engine(engine)
26{
27}
28
29void KateScriptDocument::setDocument(KTextEditor::DocumentPrivate *document)
30{
31 m_document = document;
32}
33
34KTextEditor::DocumentPrivate *KateScriptDocument::document()
35{
36 return m_document;
37}
38
39int KateScriptDocument::defStyleNum(int line, int column)
40{
41 return m_document->defStyleNum(line, column);
42}
43
44int KateScriptDocument::defStyleNum(const QJSValue &jscursor)
45{
46 const auto cursor = cursorFromScriptValue(jscursor);
47 return defStyleNum(cursor.line(), cursor.column());
48}
49
50bool KateScriptDocument::isCode(int line, int column)
51{
52 const int defaultStyle = defStyleNum(line, column);
53 return _isCode(defaultStyle);
54}
55
56bool KateScriptDocument::isCode(const QJSValue &jscursor)
57{
58 const auto cursor = cursorFromScriptValue(jscursor);
59 return isCode(cursor.line(), cursor.column());
60}
61
62bool KateScriptDocument::isComment(int line, int column)
63{
64 return m_document->isComment(line, column);
65}
66
67bool KateScriptDocument::isComment(const QJSValue &jscursor)
68{
69 const auto cursor = cursorFromScriptValue(jscursor);
70 return isComment(cursor.line(), cursor.column());
71}
72
73bool KateScriptDocument::isString(int line, int column)
74{
75 const int defaultStyle = defStyleNum(line, column);
76 return defaultStyle == KSyntaxHighlighting::Theme::TextStyle::String;
77}
78
79bool KateScriptDocument::isString(const QJSValue &jscursor)
80{
81 const auto cursor = cursorFromScriptValue(jscursor);
82 return isString(cursor.line(), cursor.column());
83}
84
85bool KateScriptDocument::isRegionMarker(int line, int column)
86{
87 const int defaultStyle = defStyleNum(line, column);
88 return defaultStyle == KSyntaxHighlighting::Theme::TextStyle::RegionMarker;
89}
90
91bool KateScriptDocument::isRegionMarker(const QJSValue &jscursor)
92{
93 const auto cursor = cursorFromScriptValue(jscursor);
94 return isRegionMarker(cursor.line(), cursor.column());
95}
96
97bool KateScriptDocument::isChar(int line, int column)
98{
99 const int defaultStyle = defStyleNum(line, column);
100 return defaultStyle == KSyntaxHighlighting::Theme::TextStyle::Char;
101}
102
103bool KateScriptDocument::isChar(const QJSValue &jscursor)
104{
105 const auto cursor = cursorFromScriptValue(jscursor);
106 return isChar(cursor.line(), cursor.column());
107}
108
109bool KateScriptDocument::isOthers(int line, int column)
110{
111 const int defaultStyle = defStyleNum(line, column);
112 return defaultStyle == KSyntaxHighlighting::Theme::TextStyle::Others;
113}
114
115bool KateScriptDocument::isOthers(const QJSValue &jscursor)
116{
117 const auto cursor = cursorFromScriptValue(jscursor);
118 return isOthers(cursor.line(), cursor.column());
119}
120
121int KateScriptDocument::firstVirtualColumn(int line)
122{
123 const int tabWidth = m_document->config()->tabWidth();
124 const auto textLine = m_document->plainKateTextLine(line);
125 if (textLine.firstChar() == -1) {
126 return -1;
127 }
128 return textLine.indentDepth(tabWidth);
129}
130
131int KateScriptDocument::lastVirtualColumn(int line)
132{
133 const int tabWidth = m_document->config()->tabWidth();
134 const auto textLine = m_document->plainKateTextLine(line);
135 const auto lastPos = textLine.lastChar();
136 if (lastPos == -1) {
137 return -1;
138 }
139 return textLine.toVirtualColumn(lastPos, tabWidth);
140}
141
142int KateScriptDocument::toVirtualColumn(int line, int column)
143{
144 const int tabWidth = m_document->config()->tabWidth();
145 const auto textLine = m_document->plainKateTextLine(line);
146 if (column < 0 || column > textLine.length()) {
147 return -1;
148 }
149 return textLine.toVirtualColumn(column, tabWidth);
150}
151
152int KateScriptDocument::toVirtualColumn(const QJSValue &jscursor)
153{
154 const auto cursor = cursorFromScriptValue(jscursor);
155 return toVirtualColumn(cursor.line(), cursor.column());
156}
157
158QJSValue KateScriptDocument::toVirtualCursor(int line, int column)
159{
160 const KTextEditor::Cursor cursor(line, toVirtualColumn(line, column));
161 return cursorToScriptValue(m_engine, cursor);
162}
163
164QJSValue KateScriptDocument::toVirtualCursor(const QJSValue &jscursor)
165{
166 const auto cursor = cursorFromScriptValue(jscursor);
167 return toVirtualCursor(cursor.line(), cursor.column());
168}
169
170int KateScriptDocument::fromVirtualColumn(int line, int virtualColumn)
171{
172 const int tabWidth = m_document->config()->tabWidth();
173 const auto textLine = m_document->plainKateTextLine(line);
174 if (virtualColumn < 0 || virtualColumn > textLine.virtualLength(tabWidth)) {
175 return -1;
176 }
177 return textLine.fromVirtualColumn(virtualColumn, tabWidth);
178}
179
180int KateScriptDocument::fromVirtualColumn(const QJSValue &jscursor)
181{
182 const auto cursor = cursorFromScriptValue(jscursor);
183 return fromVirtualColumn(cursor.line(), cursor.column());
184}
185
186QJSValue KateScriptDocument::fromVirtualCursor(int line, int column)
187{
188 const KTextEditor::Cursor cursor(line, fromVirtualColumn(line, column));
189 return cursorToScriptValue(m_engine, cursor);
190}
191
192QJSValue KateScriptDocument::fromVirtualCursor(const QJSValue &jscursor)
193{
194 const auto cursor = cursorFromScriptValue(jscursor);
195 return fromVirtualCursor(cursor.line(), cursor.column());
196}
197
198KTextEditor::Cursor KateScriptDocument::rfindInternal(int line, int column, const QString &text, int attribute)
199{
200 KTextEditor::DocumentCursor cursor(document(), line, column);
201 const int start = cursor.line();
202
203 do {
204 const auto textLine = m_document->plainKateTextLine(cursor.line());
205
206 if (cursor.line() != start) {
207 cursor.setColumn(textLine.length());
208 } else if (column >= textLine.length()) {
209 cursor.setColumn(qMax(textLine.length(), 0));
210 }
211
212 int foundAt;
213 while ((foundAt = QStringView(textLine.text()).left(cursor.column()).lastIndexOf(text)) >= 0) {
214 bool hasStyle = true;
215 if (attribute != -1) {
216 const KSyntaxHighlighting::Theme::TextStyle ds = m_document->highlight()->defaultStyleForAttribute(textLine.attribute(foundAt));
217 hasStyle = (ds == attribute);
218 }
219
220 if (hasStyle) {
221 return KTextEditor::Cursor(cursor.line(), foundAt);
222 } else {
223 cursor.setColumn(foundAt);
224 }
225 }
226 } while (cursor.gotoPreviousLine());
227
229}
230
231KTextEditor::Cursor KateScriptDocument::rfind(KTextEditor::Cursor cursor, const QString &text, int attribute)
232{
233 return rfindInternal(cursor.line(), cursor.column(), text, attribute);
234}
235
236QJSValue KateScriptDocument::rfind(int line, int column, const QString &text, int attribute)
237{
238 return cursorToScriptValue(m_engine, rfindInternal(line, column, text, attribute));
239}
240
241QJSValue KateScriptDocument::rfind(const QJSValue &jscursor, const QString &text, int attribute)
242{
243 KTextEditor::Cursor cursor = cursorFromScriptValue(jscursor);
244 return cursorToScriptValue(m_engine, rfind(cursor, text, attribute));
245}
246
247KTextEditor::Cursor KateScriptDocument::anchorInternal(int line, int column, QChar character)
248{
249 QChar lc;
250 QChar rc;
251 if (character == QLatin1Char('(') || character == QLatin1Char(')')) {
252 lc = QLatin1Char('(');
253 rc = QLatin1Char(')');
254 } else if (character == QLatin1Char('{') || character == QLatin1Char('}')) {
255 lc = QLatin1Char('{');
256 rc = QLatin1Char('}');
257 } else if (character == QLatin1Char('[') || character == QLatin1Char(']')) {
258 lc = QLatin1Char('[');
259 rc = QLatin1Char(']');
260 } else {
261 qCDebug(LOG_KTE) << "invalid anchor character:" << character << " allowed are: (){}[]";
263 }
264
265 auto *highlighter = m_document->highlight();
266 auto isCodePos = [highlighter](const Kate::TextLine &currentLine, int i) {
267 const KSyntaxHighlighting::Theme::TextStyle ds = highlighter->defaultStyleForAttribute(currentLine.attribute(i));
268 return _isCode(ds);
269 };
270
271 // Move backwards char by char and find the opening character
272 int count = 1;
273 for (int l = line; l >= 0; --l) {
274 const Kate::TextLine currentLine = document()->buffer().plainLine(l);
275 const QString &lineText = currentLine.text();
276 if (l < line) {
277 // If the line is first line, we use the column
278 // specified by the caller of this function
279 // otherwise we start at line length
280 column = lineText.length();
281 }
282 for (int i = column - 1; i >= 0; --i) {
283 const QChar ch = lineText[i];
284 if (ch == lc && isCodePos(currentLine, i)) {
285 --count;
286 } else if (ch == rc && isCodePos(currentLine, i)) {
287 ++count;
288 }
289
290 if (count == 0) {
291 return KTextEditor::Cursor(l, i);
292 }
293 }
294 }
295
297}
298
299KTextEditor::Cursor KateScriptDocument::anchor(KTextEditor::Cursor cursor, QChar character)
300{
301 return anchorInternal(cursor.line(), cursor.column(), character);
302}
303
304QJSValue KateScriptDocument::anchor(int line, int column, QChar character)
305{
306 return cursorToScriptValue(m_engine, anchorInternal(line, column, character));
307}
308
309QJSValue KateScriptDocument::anchor(const QJSValue &jscursor, QChar character)
310{
311 KTextEditor::Cursor cursor = cursorFromScriptValue(jscursor);
312 return anchor(cursor.line(), cursor.column(), character);
313}
314
315bool KateScriptDocument::startsWith(int line, const QString &pattern, bool skipWhiteSpaces)
316{
317 Kate::TextLine textLine = m_document->plainKateTextLine(line);
318
319 if (skipWhiteSpaces) {
320 return textLine.matchesAt(textLine.firstChar(), pattern);
321 }
322
323 return textLine.startsWith(pattern);
324}
325
326bool KateScriptDocument::endsWith(int line, const QString &pattern, bool skipWhiteSpaces)
327{
328 Kate::TextLine textLine = m_document->plainKateTextLine(line);
329
330 if (skipWhiteSpaces) {
331 return textLine.matchesAt(textLine.lastChar() - pattern.length() + 1, pattern);
332 }
333
334 return textLine.endsWith(pattern);
335}
336
337QString KateScriptDocument::fileName()
338{
339 return m_document->documentName();
340}
341
342QString KateScriptDocument::url()
343{
344 return m_document->url().toString();
345}
346
347QString KateScriptDocument::mimeType()
348{
349 return m_document->mimeType();
350}
351
352QString KateScriptDocument::encoding()
353{
354 return m_document->encoding();
355}
356
357QString KateScriptDocument::highlightingMode()
358{
359 return m_document->highlightingMode();
360}
361
362QStringList KateScriptDocument::embeddedHighlightingModes()
363{
364 return m_document->embeddedHighlightingModes();
365}
366
367QString KateScriptDocument::highlightingModeAt(const QJSValue &jspos)
368{
369 return m_document->highlightingModeAt(cursorFromScriptValue(jspos));
370}
371
372bool KateScriptDocument::isModified()
373{
374 return m_document->isModified();
375}
376
377QString KateScriptDocument::text()
378{
379 return m_document->text();
380}
381
382QString KateScriptDocument::text(int fromLine, int fromColumn, int toLine, int toColumn)
383{
384 const KTextEditor::Range range(fromLine, fromColumn, toLine, toColumn);
385 return m_document->text(range);
386}
387
388QString KateScriptDocument::text(const QJSValue &jsfrom, const QJSValue &jsto)
389{
390 const KTextEditor::Cursor from = cursorFromScriptValue(jsfrom);
391 const KTextEditor::Cursor to = cursorFromScriptValue(jsto);
392 return text(from.line(), from.column(), to.line(), to.column());
393}
394
395QString KateScriptDocument::text(const QJSValue &jsrange)
396{
397 const auto range = rangeFromScriptValue(jsrange);
398 return text(range.start().line(), range.start().column(), range.end().line(), range.end().column());
399}
400
401QString KateScriptDocument::line(int line)
402{
403 return m_document->line(line);
404}
405
406QString KateScriptDocument::wordAt(int line, int column)
407{
408 const KTextEditor::Cursor cursor(line, column);
409 return m_document->wordAt(cursor);
410}
411
412QString KateScriptDocument::wordAt(const QJSValue &jscursor)
413{
414 const auto cursor = cursorFromScriptValue(jscursor);
415 return wordAt(cursor.line(), cursor.column());
416}
417
418QJSValue KateScriptDocument::wordRangeAt(int line, int column)
419{
420 const KTextEditor::Cursor cursor(line, column);
421 return rangeToScriptValue(m_engine, m_document->wordRangeAt(cursor));
422}
423
424QJSValue KateScriptDocument::wordRangeAt(const QJSValue &jscursor)
425{
426 const auto cursor = cursorFromScriptValue(jscursor);
427 return wordRangeAt(cursor.line(), cursor.column());
428}
429
430QString KateScriptDocument::charAt(int line, int column)
431{
432 const KTextEditor::Cursor cursor(line, column);
433 const QChar c = m_document->characterAt(cursor);
434 return c.isNull() ? QString() : QString(c);
435}
436
437QString KateScriptDocument::charAt(const QJSValue &jscursor)
438{
439 const auto cursor = cursorFromScriptValue(jscursor);
440 return charAt(cursor.line(), cursor.column());
441}
442
443QString KateScriptDocument::firstChar(int line)
444{
445 Kate::TextLine textLine = m_document->plainKateTextLine(line);
446 // check for isNull(), as the returned character then would be "\0"
447 const QChar c = textLine.at(textLine.firstChar());
448 return c.isNull() ? QString() : QString(c);
449}
450
451QString KateScriptDocument::lastChar(int line)
452{
453 Kate::TextLine textLine = m_document->plainKateTextLine(line);
454 // check for isNull(), as the returned character then would be "\0"
455 const QChar c = textLine.at(textLine.lastChar());
456 return c.isNull() ? QString() : QString(c);
457}
458
459bool KateScriptDocument::isSpace(int line, int column)
460{
461 const KTextEditor::Cursor cursor(line, column);
462 return m_document->characterAt(cursor).isSpace();
463}
464
465bool KateScriptDocument::isSpace(const QJSValue &jscursor)
466{
467 const auto cursor = cursorFromScriptValue(jscursor);
468 return isSpace(cursor.line(), cursor.column());
469}
470
471bool KateScriptDocument::matchesAt(int line, int column, const QString &s)
472{
473 Kate::TextLine textLine = m_document->plainKateTextLine(line);
474 return textLine.matchesAt(column, s);
475}
476
477bool KateScriptDocument::matchesAt(const QJSValue &jscursor, const QString &s)
478{
479 const auto cursor = cursorFromScriptValue(jscursor);
480 return matchesAt(cursor.line(), cursor.column(), s);
481}
482
483bool KateScriptDocument::setText(const QString &s)
484{
485 return m_document->setText(s);
486}
487
488bool KateScriptDocument::clear()
489{
490 return m_document->clear();
491}
492
493bool KateScriptDocument::truncate(int line, int column)
494{
495 Kate::TextLine textLine = m_document->plainKateTextLine(line);
496 if (textLine.text().size() < column) {
497 return false;
498 }
499 return removeText(line, column, line, textLine.text().size() - column);
500}
501
502bool KateScriptDocument::truncate(const QJSValue &jscursor)
503{
504 const auto cursor = cursorFromScriptValue(jscursor);
505 return truncate(cursor.line(), cursor.column());
506}
507
508bool KateScriptDocument::insertText(int line, int column, const QString &s)
509{
510 KTextEditor::Cursor cursor(line, column);
511 return m_document->insertText(cursor, s);
512}
513
514bool KateScriptDocument::insertText(const QJSValue &jscursor, const QString &s)
515{
516 const auto cursor = cursorFromScriptValue(jscursor);
517 return insertText(cursor.line(), cursor.column(), s);
518}
519
520bool KateScriptDocument::removeText(int fromLine, int fromColumn, int toLine, int toColumn)
521{
522 const KTextEditor::Range range(fromLine, fromColumn, toLine, toColumn);
523 return m_document->removeText(range);
524}
525
526bool KateScriptDocument::removeText(const QJSValue &jsfrom, const QJSValue &jsto)
527{
528 const KTextEditor::Cursor from = cursorFromScriptValue(jsfrom);
529 const KTextEditor::Cursor to = cursorFromScriptValue(jsto);
530 return removeText(from.line(), from.column(), to.line(), to.column());
531}
532
533bool KateScriptDocument::removeText(const QJSValue &jsrange)
534{
535 const auto range = rangeFromScriptValue(jsrange);
536 return removeText(range.start().line(), range.start().column(), range.end().line(), range.end().column());
537}
538
539bool KateScriptDocument::insertLine(int line, const QString &s)
540{
541 return m_document->insertLine(line, s);
542}
543
544bool KateScriptDocument::removeLine(int line)
545{
546 return m_document->removeLine(line);
547}
548
549bool KateScriptDocument::wrapLine(int line, int column)
550{
551 return m_document->editWrapLine(line, column);
552}
553
554bool KateScriptDocument::wrapLine(const QJSValue &jscursor)
555{
556 const auto cursor = cursorFromScriptValue(jscursor);
557 return wrapLine(cursor.line(), cursor.column());
558}
559
560void KateScriptDocument::joinLines(int startLine, int endLine)
561{
562 m_document->joinLines(startLine, endLine);
563}
564
565int KateScriptDocument::lines()
566{
567 return m_document->lines();
568}
569
570bool KateScriptDocument::isLineModified(int line)
571{
572 return m_document->isLineModified(line);
573}
574
575bool KateScriptDocument::isLineSaved(int line)
576{
577 return m_document->isLineSaved(line);
578}
579
580bool KateScriptDocument::isLineTouched(int line)
581{
582 return m_document->isLineTouched(line);
583}
584
585int KateScriptDocument::findTouchedLine(int startLine, bool down)
586{
587 return m_document->findTouchedLine(startLine, down);
588}
589
590int KateScriptDocument::length()
591{
592 return m_document->totalCharacters();
593}
594
595int KateScriptDocument::lineLength(int line)
596{
597 return m_document->lineLength(line);
598}
599
600void KateScriptDocument::editBegin()
601{
602 m_document->editStart();
603}
604
605void KateScriptDocument::editEnd()
606{
607 m_document->editEnd();
608}
609
610bool KateScriptDocument::isValidTextPosition(int line, int column)
611{
612 return m_document->isValidTextPosition(KTextEditor::Cursor(line, column));
613}
614
615bool KateScriptDocument::isValidTextPosition(const QJSValue &cursor)
616{
617 return m_document->isValidTextPosition(cursorFromScriptValue(cursor));
618}
619
620int KateScriptDocument::firstColumn(int line)
621{
622 Kate::TextLine textLine = m_document->plainKateTextLine(line);
623 return textLine.firstChar();
624}
625
626int KateScriptDocument::lastColumn(int line)
627{
628 Kate::TextLine textLine = m_document->plainKateTextLine(line);
629 return textLine.lastChar();
630}
631
632int KateScriptDocument::prevNonSpaceColumn(int line, int column)
633{
634 Kate::TextLine textLine = m_document->plainKateTextLine(line);
635 return textLine.previousNonSpaceChar(column);
636}
637
638int KateScriptDocument::prevNonSpaceColumn(const QJSValue &jscursor)
639{
640 const auto cursor = cursorFromScriptValue(jscursor);
641 return prevNonSpaceColumn(cursor.line(), cursor.column());
642}
643
644int KateScriptDocument::nextNonSpaceColumn(int line, int column)
645{
646 Kate::TextLine textLine = m_document->plainKateTextLine(line);
647 return textLine.nextNonSpaceChar(column);
648}
649
650int KateScriptDocument::nextNonSpaceColumn(const QJSValue &jscursor)
651{
652 const auto cursor = cursorFromScriptValue(jscursor);
653 return nextNonSpaceColumn(cursor.line(), cursor.column());
654}
655
656int KateScriptDocument::prevNonEmptyLine(int line)
657{
658 const int startLine = line;
659 for (int currentLine = startLine; currentLine >= 0; --currentLine) {
660 Kate::TextLine textLine = m_document->plainKateTextLine(currentLine);
661 if (textLine.firstChar() != -1) {
662 return currentLine;
663 }
664 }
665 return -1;
666}
667
668int KateScriptDocument::nextNonEmptyLine(int line)
669{
670 const int startLine = line;
671 for (int currentLine = startLine; currentLine < m_document->lines(); ++currentLine) {
672 Kate::TextLine textLine = m_document->plainKateTextLine(currentLine);
673 if (textLine.firstChar() != -1) {
674 return currentLine;
675 }
676 }
677 return -1;
678}
679
680bool KateScriptDocument::isInWord(const QString &character, int attribute)
681{
682 return m_document->highlight()->isInWord(character.at(0), attribute);
683}
684
685bool KateScriptDocument::canBreakAt(const QString &character, int attribute)
686{
687 return m_document->highlight()->canBreakAt(character.at(0), attribute);
688}
689
690bool KateScriptDocument::canComment(int startAttribute, int endAttribute)
691{
692 return m_document->highlight()->canComment(startAttribute, endAttribute);
693}
694
695QString KateScriptDocument::commentMarker(int attribute)
696{
697 return m_document->highlight()->getCommentSingleLineStart(attribute);
698}
699
700QString KateScriptDocument::commentStart(int attribute)
701{
702 return m_document->highlight()->getCommentStart(attribute);
703}
704
705QString KateScriptDocument::commentEnd(int attribute)
706{
707 return m_document->highlight()->getCommentEnd(attribute);
708}
709
710QJSValue KateScriptDocument::documentRange()
711{
712 return rangeToScriptValue(m_engine, m_document->documentRange());
713}
714
715QJSValue KateScriptDocument::documentEnd()
716{
717 return cursorToScriptValue(m_engine, m_document->documentEnd());
718}
719
720int KateScriptDocument::attribute(int line, int column)
721{
722 Kate::TextLine textLine = m_document->kateTextLine(line);
723 return textLine.attribute(column);
724}
725
726int KateScriptDocument::attribute(const QJSValue &jscursor)
727{
728 const auto cursor = cursorFromScriptValue(jscursor);
729 return attribute(cursor.line(), cursor.column());
730}
731
732bool KateScriptDocument::isAttribute(int line, int column, int attr)
733{
734 return attr == attribute(line, column);
735}
736
737bool KateScriptDocument::isAttribute(const QJSValue &jscursor, int attr)
738{
739 const auto cursor = cursorFromScriptValue(jscursor);
740 return isAttribute(cursor.line(), cursor.column(), attr);
741}
742
744{
745 return m_document->highlight()->nameForAttrib(document()->plainKateTextLine(line).attribute(column));
746}
747
749{
750 const auto cursor = cursorFromScriptValue(jscursor);
751 return attributeName(cursor.line(), cursor.column());
752}
753
754bool KateScriptDocument::isAttributeName(int line, int column, const QString &name)
755{
756 return name == attributeName(line, column);
757}
758
759bool KateScriptDocument::isAttributeName(const QJSValue &jscursor, const QString &name)
760{
761 const auto cursor = cursorFromScriptValue(jscursor);
762 return isAttributeName(cursor.line(), cursor.column(), name);
763}
764
765QString KateScriptDocument::variable(const QString &s)
766{
767 return m_document->variable(s);
768}
769
770void KateScriptDocument::setVariable(const QString &s, const QString &v)
771{
772 m_document->setVariable(s, v);
773}
774
775bool KateScriptDocument::_isCode(int defaultStyle)
776{
778 return (defaultStyle != S::Comment && defaultStyle != S::Alert && defaultStyle != S::String && defaultStyle != S::RegionMarker && defaultStyle != S::Char
779 && defaultStyle != S::Others);
780}
781
782void KateScriptDocument::indent(const QJSValue &jsrange, int change)
783{
784 const auto range = rangeFromScriptValue(jsrange);
785 m_document->indent(range, change);
786}
787
788#include "moc_katescriptdocument.cpp"
bool isModified() const
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
static constexpr Cursor invalid() noexcept
Returns an invalid cursor.
Definition cursor.h:112
A Cursor which is bound to a specific Document.
Backend of KTextEditor::Document related public KTextEditor interfaces.
KTextEditor::Cursor documentEnd() const override
End position of the document.
void joinLines(uint first, uint last)
Unwrap a range of lines.
virtual QString variable(const QString &name) const
Returns the value for the variable name.
QString text(KTextEditor::Range range, bool blockwise=false) const override
Get the document content within the given range.
bool isLineModified(int line) const override
Check whether line currently contains unsaved data.
qsizetype totalCharacters() const override
Get the count of characters in the document.
QString highlightingMode() const override
Return the name of the currently used mode.
QString line(int line) const override
Get a single text line.
QString mimeType() override
Tries to detect mime-type based on file name and content of buffer.
QChar characterAt(KTextEditor::Cursor position) const override
Get the character at text position cursor.
QString documentName() const override
Get this document's name.
bool isLineSaved(int line) const override
Check whether line currently contains only saved text.
KateBuffer & buffer()
Get access to buffer of this document.
bool isLineTouched(int line) const override
Check whether line was touched since the file was opened.
int lines() const override
Get the count of lines of the document.
bool editStart()
Enclose editor actions with editStart() and editEnd() to group them.
KSyntaxHighlighting::Theme::TextStyle defStyleNum(int line, int column)
KateDocumentConfig * config()
Configuration.
bool editWrapLine(int line, int col, bool newLine=true, bool *newLineAdded=nullptr, bool notify=true)
Wrap line.
QString highlightingModeAt(KTextEditor::Cursor position) override
Get the highlight mode used at a given position in the document.
Kate::TextLine plainKateTextLine(int i)
Return line lineno.
bool isValidTextPosition(KTextEditor::Cursor cursor) const override
Get whether cursor is a valid text position.
QStringList embeddedHighlightingModes() const override
Get all available highlighting modes for the current document.
Kate::TextLine kateTextLine(int i)
Same as plainKateTextLine(), except that it is made sure the line is highlighted.
QString encoding() const override
Get the current chosen encoding.
bool editEnd()
End a editor operation.
virtual void setVariable(const QString &name, const QString &value)
Set the variable name to value.
int findTouchedLine(int startLine, bool down)
Find the next modified/saved line, starting at startLine.
QString wordAt(KTextEditor::Cursor cursor) const override
Get the word at the text position cursor.
int lineLength(int line) const override
Get the length of a given line in characters.
KTextEditor::Range wordRangeAt(KTextEditor::Cursor cursor) const override
Get the text range for the word located under the text position cursor.
Range documentRange() const
A Range which encompasses the whole document.
Definition document.h:785
An object representing a section of text, from one Cursor to another.
Kate::TextLine plainLine(int lineno)
Return line lineno.
Definition katebuffer.h:158
Q_INVOKABLE bool isAttributeName(int line, int column, const QString &name)
Return true is the name of the syntax attribute equals name.
Q_INVOKABLE bool isAttribute(int line, int column, int attr)
Return true if the highlight attribute equals attr.
Q_INVOKABLE int attribute(int line, int column)
Get the syntax highlighting attribute at a given position in the document.
Q_INVOKABLE QString attributeName(int line, int column)
Get the name of the syntax highlighting attribute at the given position.
Class representing a single text line.
int attribute(int pos) const
Gets the attribute at the given position use KRenderer::attributes to get the KTextAttribute for this...
const QString & text() const
Accessor to the text contained in this line.
bool endsWith(const QString &match) const
Returns true, if the line ends with match, otherwise returns false.
int indentDepth(int tabWidth) const
Returns the indentation depth with each tab expanded into tabWidth characters.
int previousNonSpaceChar(int pos) const
Find the position of the previous char that is not a space.
bool startsWith(const QString &match) const
Returns true, if the line starts with match, otherwise returns false.
int lastChar() const
Returns the position of the last non-whitespace character.
QChar at(int column) const
Returns the character at the given column.
int firstChar() const
Returns the position of the first non-whitespace character.
int toVirtualColumn(int column, int tabWidth) const
Returns the column with each tab expanded into tabWidth characters.
bool matchesAt(int column, const QString &match) const
Returns true, if match equals to the text at position column, otherwise returns false.
int nextNonSpaceChar(int pos) const
Find the position of the next char that is not a space.
int fromVirtualColumn(int column, int tabWidth) const
Returns the "real" column where each tab only counts one character.
Q_SCRIPTABLE Q_NOREPLY void start()
bool isNull() const const
bool isSpace(char32_t ucs4)
const QChar at(qsizetype position) const const
qsizetype length() const const
qsizetype size() const const
QStringView left(qsizetype length) const const
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs) const const
QString toString(FormattingOptions options) 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.