1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef TEXTCURSOR_H
5#define TEXTCURSOR_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qstring.h>
19
20namespace Utils {
21
22class TextDocument;
23class TextBlock;
24
25class TextCursor
26{
27public:
28 enum MoveOperation {
29 NoMove,
30 Start,
31 PreviousCharacter,
32 End,
33 NextCharacter,
34 };
35
36 enum MoveMode { MoveAnchor, KeepAnchor };
37
38 enum SelectionType { Document };
39
40 TextCursor();
41 TextCursor(const TextBlock &block);
42 TextCursor(TextDocument *document);
43
44 bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
45 int position() const;
46 void setPosition(int pos, MoveMode mode = MoveAnchor);
47 QString selectedText() const;
48 void clearSelection();
49 int anchor() const;
50 TextDocument *document() const;
51 void insertText(const QString &text);
52 TextBlock block() const;
53 int positionInBlock() const;
54 int blockNumber() const;
55
56 void select(SelectionType selection);
57
58 bool hasSelection() const;
59
60 void removeSelectedText();
61 int selectionEnd() const;
62
63 bool isNull() const;
64
65private:
66 TextDocument *m_document = nullptr;
67 int m_position = 0;
68 int m_anchor = 0;
69};
70} // namespace Utils
71
72#endif // TEXTCURSOR_H
73

source code of qtdeclarative/src/qmlls/qtextcursor_p.h