KTextEditor

katetexthistory.h
1 /*
2  SPDX-FileCopyrightText: 2013 Christoph Cullmann <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KATE_TEXTHISTORY_H
8 #define KATE_TEXTHISTORY_H
9 
10 #include <vector>
11 
12 #include <ktexteditor/range.h>
13 
14 #include "katetextrange.h"
15 #include <ktexteditor_export.h>
16 
17 namespace Kate
18 {
19 class TextBuffer;
20 
24 class KTEXTEDITOR_EXPORT TextHistory
25 {
26  friend class TextBuffer;
27  friend class TextBlock;
28 
29 public:
34  qint64 revision() const;
35 
40  qint64 lastSavedRevision() const
41  {
42  return m_lastSavedRevision;
43  }
44 
50  void lockRevision(qint64 revision);
51 
56  void unlockRevision(qint64 revision);
57 
66  void transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1);
67 
76  void transformRange(KTextEditor::Range &range,
79  qint64 fromRevision,
80  qint64 toRevision = -1);
81 
82 private:
86  class Entry
87  {
88  public:
95  void transformCursor(int &line, int &column, bool moveOnInsert) const;
96 
103  void reverseTransformCursor(int &line, int &column, bool moveOnInsert) const;
104 
108  enum Type { NoChange, WrapLine, UnwrapLine, InsertText, RemoveText };
109 
113  Entry()
114  {
115  }
116 
120  unsigned int referenceCounter = 0;
121 
125  Type type = NoChange;
126 
130  int line = -1;
131 
135  int column = -1;
136 
140  int length = -1;
141 
145  int oldLineLength = -1;
146  };
147 
152  explicit TextHistory(TextBuffer &buffer);
153 
157  ~TextHistory();
158 
162  void clear();
163 
167  void setLastSavedRevision();
168 
173  void wrapLine(const KTextEditor::Cursor &position);
174 
180  void unwrapLine(int line, int oldLineLength);
181 
188  void insertText(const KTextEditor::Cursor &position, int length, int oldLineLength);
189 
195  void removeText(const KTextEditor::Range &range, int oldLineLength);
196 
201  void addEntry(const Entry &entry);
202 
203 private:
207  TextBuffer &m_buffer;
208 
212  qint64 m_lastSavedRevision;
213 
218  std::vector<Entry> m_historyEntries;
219 
223  qint64 m_firstHistoryEntryRevision;
224 };
225 
226 }
227 
228 #endif
qint64 lastSavedRevision() const
Last revision the buffer got successful saved.
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:166
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
An object representing a section of text, from one Cursor to another.
Class representing the editing history of a TextBuffer.
Class representing a text buffer.
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 Tue Jan 26 2021 22:57:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.