KTextEditor

katetextcursor.h
1 /*
2  SPDX-FileCopyrightText: 2010 Christoph Cullmann <[email protected]>
3 
4  Based on code of the SmartCursor/Range by:
5  SPDX-FileCopyrightText: 2003-2005 Hamish Rodda <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KATE_TEXTCURSOR_H
11 #define KATE_TEXTCURSOR_H
12 
13 #include <ktexteditor/movingcursor.h>
14 
15 #include "katetextblock.h"
16 #include <ktexteditor_export.h>
17 
18 namespace Kate
19 {
20 class TextBuffer;
21 class TextBlock;
22 class TextRange;
23 
29 class KTEXTEDITOR_EXPORT TextCursor : public KTextEditor::MovingCursor
30 {
31  // range wants direct access to some internals
32  friend class TextRange;
33 
34  // this is a friend, because this is needed to efficiently transfer cursors from on to an other block
35  friend class TextBlock;
36 
37 private:
45  TextCursor(TextBuffer &buffer, TextRange *range, const KTextEditor::Cursor &position, InsertBehavior insertBehavior);
46 
47 public:
54  TextCursor(TextBuffer &buffer, const KTextEditor::Cursor &position, InsertBehavior insertBehavior);
55 
59  ~TextCursor() override;
60 
65  void setInsertBehavior(InsertBehavior insertBehavior) override
66  {
67  m_moveOnInsert = insertBehavior == MoveOnInsert;
68  }
69 
74  InsertBehavior insertBehavior() const override
75  {
76  return m_moveOnInsert ? MoveOnInsert : StayOnInsert;
77  }
78 
83  KTextEditor::Document *document() const override;
84 
90  void setPosition(const TextCursor &position);
91 
97  void setPosition(const KTextEditor::Cursor &position) override;
98 
107  void setPosition(int line, int column)
108  {
110  }
111 
116  int line() const override;
117 
123  int lineInternal() const
124  {
125  // invalid cursor have no block
126  if (!m_block) {
127  return -1;
128  }
129 
130  // else, calculate real line
131  return m_block->startLine() + m_line;
132  }
133 
138  int column() const override
139  {
140  return m_column;
141  }
142 
147  int columnInternal() const
148  {
149  return m_column;
150  }
151 
156  KTextEditor::MovingRange *range() const override;
157 
163  {
164  return m_range;
165  }
166 
171  TextBlock *block() const
172  {
173  return m_block;
174  }
175 
180  int lineInBlock() const
181  {
182  if (m_block) {
183  return m_line;
184  }
185  return -1;
186  }
187 
188 private:
192  TextCursor(const TextCursor &);
193 
197  TextCursor &operator=(const TextCursor &);
198 
207  void setPosition(const KTextEditor::Cursor &position, bool init);
208 
209 private:
214  TextBuffer &m_buffer;
215 
221  TextRange *const m_range;
222 
226  TextBlock *m_block;
227 
231  int m_line;
232 
236  int m_column;
237 
241  bool m_moveOnInsert;
242 };
243 
244 }
245 
246 #endif
void setPosition(int line, int column)
This is an overloaded member function, provided for convenience. It differs from the above function o...
TextBlock * block() const
Get block this cursor belongs to, if any.
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:54
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:144
int lineInternal() const
Non-virtual version of line(), which is faster.
The Cursor represents a position in a Document.
Definition: cursor.h:71
InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move...
Definition: movingcursor.h:64
A KParts derived class representing a text document.
Definition: document.h:185
int lineInBlock() const
Get offset into block this cursor belongs to, if any.
InsertBehavior insertBehavior() const override
Get current insert behavior.
QCA_EXPORT void init()
Kate::TextRange * kateRange() const
Get range this cursor belongs to, if any.
Class representing a &#39;clever&#39; text cursor.
int column() const override
Retrieve the column on which this cursor is situated.
void setInsertBehavior(InsertBehavior insertBehavior) override
Set insert behavior.
Class representing a text buffer.
virtual void setPosition(const KTextEditor::Cursor &position)=0
Set the current cursor position to position.
int columnInternal() const
Non-virtual version of column(), which is faster.
Class representing a &#39;clever&#39; text range.
Definition: katetextrange.h:32
Class representing a text block.
Definition: katetextblock.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 27 2021 22:56:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.