KTextEditor

katetexthistory.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2013 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_TEXTHISTORY_H
22 #define KATE_TEXTHISTORY_H
23 
24 #include <vector>
25 
26 #include <ktexteditor/range.h>
27 
28 #include "katetextrange.h"
29 #include <ktexteditor_export.h>
30 
31 namespace Kate
32 {
33 class TextBuffer;
34 
38 class KTEXTEDITOR_EXPORT TextHistory
39 {
40  friend class TextBuffer;
41  friend class TextBlock;
42 
43 public:
48  qint64 revision() const;
49 
54  qint64 lastSavedRevision() const
55  {
56  return m_lastSavedRevision;
57  }
58 
64  void lockRevision(qint64 revision);
65 
70  void unlockRevision(qint64 revision);
71 
80  void transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1);
81 
90  void transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision = -1);
91 
92 private:
96  class Entry
97  {
98  public:
105  void transformCursor(int &line, int &column, bool moveOnInsert) const;
106 
113  void reverseTransformCursor(int &line, int &column, bool moveOnInsert) const;
114 
118  enum Type { NoChange, WrapLine, UnwrapLine, InsertText, RemoveText };
119 
123  Entry()
124  {
125  }
126 
130  unsigned int referenceCounter = 0;
131 
135  Type type = NoChange;
136 
140  int line = -1;
141 
145  int column = -1;
146 
150  int length = -1;
151 
155  int oldLineLength = -1;
156  };
157 
162  explicit TextHistory(TextBuffer &buffer);
163 
167  ~TextHistory();
168 
172  void clear();
173 
177  void setLastSavedRevision();
178 
183  void wrapLine(const KTextEditor::Cursor &position);
184 
190  void unwrapLine(int line, int oldLineLength);
191 
198  void insertText(const KTextEditor::Cursor &position, int length, int oldLineLength);
199 
205  void removeText(const KTextEditor::Range &range, int oldLineLength);
206 
211  void addEntry(const Entry &entry);
212 
213 private:
217  TextBuffer &m_buffer;
218 
222  qint64 m_lastSavedRevision;
223 
228  std::vector<Entry> m_historyEntries;
229 
233  qint64 m_firstHistoryEntryRevision;
234 };
235 
236 }
237 
238 #endif
qint64 lastSavedRevision() const
Last revision the buffer got successful saved.
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:179
The Cursor represents a position in a Document.
Definition: cursor.h:85
InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move...
Definition: movingcursor.h:78
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: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.