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
20QT_BEGIN_NAMESPACE
21
22namespace Utils {
23
24class TextDocument;
25class TextBlock;
26
27class TextCursor
28{
29public:
30 enum MoveOperation {
31 NoMove,
32 Start,
33 PreviousCharacter,
34 End,
35 NextCharacter,
36 };
37
38 enum MoveMode { MoveAnchor, KeepAnchor };
39
40 enum SelectionType { Document };
41
42 TextCursor();
43 TextCursor(const TextBlock &block);
44 TextCursor(TextDocument *document);
45
46 bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
47 int position() const;
48 void setPosition(int pos, MoveMode mode = MoveAnchor);
49 QString selectedText() const;
50 void clearSelection();
51 int anchor() const;
52 TextDocument *document() const;
53 void insertText(const QString &text);
54 TextBlock block() const;
55 int positionInBlock() const;
56 int blockNumber() const;
57
58 void select(SelectionType selection);
59
60 bool hasSelection() const;
61
62 void removeSelectedText();
63 int selectionEnd() const;
64
65 bool isNull() const;
66
67private:
68 TextDocument *m_document = nullptr;
69 int m_position = 0;
70 int m_anchor = 0;
71};
72} // namespace Utils
73
74QT_END_NAMESPACE
75
76#endif // TEXTCURSOR_H
77

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