KTextEditor

katetextblock.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2010 Christoph Cullmann <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef KATE_TEXTBLOCK_H
22 #define KATE_TEXTBLOCK_H
23 
24 #include <unordered_set>
25 
26 #include <QSet>
27 #include <QVector>
28 
29 #include "katetextline.h"
30 #include <ktexteditor/cursor.h>
31 #include <ktexteditor_export.h>
32 
33 namespace Kate
34 {
35 class TextBuffer;
36 class TextCursor;
37 class TextRange;
38 
44 class KTEXTEDITOR_EXPORT TextBlock
45 {
46 public:
52  TextBlock(TextBuffer *buffer, int startLine);
53 
57  ~TextBlock();
58 
63  int startLine() const
64  {
65  return m_startLine;
66  }
67 
72  void setStartLine(int startLine);
73 
79  TextLine line(int line) const;
80 
85  void appendLine(const QString &textOfLine);
86 
90  void clearLines();
91 
96  int lines() const
97  {
98  return m_lines.size();
99  }
100 
105  void text(QString &text) const;
106 
112  void wrapLine(const KTextEditor::Cursor &position, int fixStartLinesStartIndex);
113 
120  void unwrapLine(int line, TextBlock *previousBlock, int fixStartLinesStartIndex);
121 
127  void insertText(const KTextEditor::Cursor &position, const QString &text);
128 
134  void removeText(const KTextEditor::Range &range, QString &removedText);
135 
140  void debugPrint(int blockIndex) const;
141 
148  TextBlock *splitBlock(int fromLine);
149 
154  void mergeBlock(TextBlock *targetBlock);
155 
161  void deleteBlockContent();
162 
168  void clearBlockContent(TextBlock *targetBlock);
169 
176  {
177  return QList<QSet<TextRange *>>() << m_uncachedRanges << cachedRangesForLine(line);
178  }
179 
185  bool containsRange(TextRange *range) const
186  {
187  return m_cachedLineForRanges.contains(range) || m_uncachedRanges.contains(range);
188  }
189 
193  void markModifiedLinesAsSaved();
194 
200  {
201  m_cursors.insert(cursor);
202  }
203 
209  {
210  m_cursors.erase(cursor);
211  }
212 
218  void updateRange(TextRange *range);
219 
224  void removeRange(TextRange *range);
225 
233  {
234  line -= m_startLine;
235  if (line >= 0 && line < m_cachedRangesForLine.size()) {
236  return m_cachedRangesForLine[line];
237  } else {
238  return QSet<TextRange *>();
239  }
240  }
241 
242 private:
246  TextBuffer *m_buffer;
247 
252  std::vector<Kate::TextLine> m_lines;
253 
257  int m_startLine;
258 
263  std::unordered_set<TextCursor *> m_cursors;
264 
269  QVector<QSet<TextRange *>> m_cachedRangesForLine;
270 
274  QHash<TextRange *, int> m_cachedLineForRanges;
275 
279  QSet<TextRange *> m_uncachedRanges;
280 };
281 
282 }
283 
284 #endif
QSet< TextRange * > cachedRangesForLine(int line) const
Return all ranges in this block which might intersect the given line and only span one line...
void removeCursor(Kate::TextCursor *cursor)
Remove cursor from this block.
int lines() const
Number of lines in this block.
Definition: katetextblock.h:96
The Cursor represents a position in a Document.
Definition: cursor.h:85
int startLine() const
Start line of this block.
Definition: katetextblock.h:63
void insertCursor(Kate::TextCursor *cursor)
Insert cursor into this block.
bool containsRange(TextRange *range) const
Is the given range contained in this block?
QList< QSet< TextRange * > > rangesForLine(int line) const
Return all ranges in this block which might intersect the given line.
An object representing a section of text, from one Cursor to another.
Class representing a &#39;clever&#39; text cursor.
Class representing a text buffer.
Class representing a &#39;clever&#39; text range.
Definition: katetextrange.h:46
Class representing a text block.
Definition: katetextblock.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:00:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.