[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    KDE/kdelibs/kate/document
From:       Dominik Haumann <dhdev () gmx ! de>
Date:       2008-04-29 17:13:57
Message-ID: 1209489237.050233.19442.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 802510 by dhaumann:

Make undo merging work again.

Please test and review - thanks.
CCMAIL: kwrite-devel@kde.org


 M  +4 -5      katedocument.cpp  
 M  +27 -53    kateundo.cpp  
 M  +18 -11    kateundo.h  


--- trunk/KDE/kdelibs/kate/document/katedocument.cpp #802509:802510
@@ -1245,11 +1245,10 @@
 void KateDocument::editAddUndo (int type, uint line, uint col, uint len, const QString &text)
 {
   if (editIsRunning && editWithUndo && m_editCurrentUndo) {
-    // make sure it's only added once - doesn't make sense to add it ever and ever again
-    if(activeKateView() && !m_editCurrentUndo->contains(KateUndoGroup::editCursorMove)) {
-      const KTextEditor::Cursor c = activeKateView()->cursorPosition();
-      m_editCurrentUndo->addItem(KateUndoGroup::editCursorMove, c.line(), c.column(), 0, QString());
-      m_editCurrentUndo->addItem(activeKateView()->selectionRange());
+    // save selection and cursor position
+    if (KateView *view = activeKateView()) {
+      m_editCurrentUndo->setCursorPosition(view->cursorPosition());
+      m_editCurrentUndo->setSelection(view->selectionRange());
     }
     m_editCurrentUndo->addItem(static_cast<KateUndoGroup::UndoType>(type), line, col, len, text);
 
--- trunk/KDE/kdelibs/kate/document/kateundo.cpp #802509:802510
@@ -41,12 +41,6 @@
     KateUndo (KateUndoGroup::UndoType type, uint line, uint col, uint len, const QString &text);
 
     /**
-      * Constructor, type is selectionRange
-      * @param selection selection to remember
-      */
-    KateUndo (const KTextEditor::Range &selection);
-
-    /**
      * Destructor
      */
     ~KateUndo ();
@@ -110,11 +104,6 @@
      */
     inline const QString& text() const { return m_text; }
 
-    /**
-     * saved selection
-     * @return selection
-     */
-    inline const KTextEditor::Range &selection() const { return m_selection; }
   private:
     /**
      * type
@@ -140,11 +129,6 @@
      * text
      */
     QString m_text;
-
-    /**
-     * selection
-     */
-    KTextEditor::Range m_selection;
 };
 
 KateUndo::KateUndo (KateUndoGroup::UndoType type, uint line, uint col, uint len, const QString &text)
@@ -156,12 +140,6 @@
 {
 }
 
-KateUndo::KateUndo (const KTextEditor::Range &selection)
-: m_type (KateUndoGroup::selectionRange),
-  m_selection (selection)
-{
-}
-
 KateUndo::~KateUndo ()
 {
 }
@@ -225,14 +203,6 @@
     case KateUndoGroup::editMarkLineAutoWrapped:
       doc->editMarkLineAutoWrapped (m_line, m_col == 0);
       break;
-    case KateUndoGroup::editCursorMove:
-      if(doc->activeKateView())
-        doc->activeKateView()->editSetCursor (KTextEditor::Cursor(m_line, m_col));
-      break;
-    case KateUndoGroup::selectionRange:
-      if(doc->activeKateView())
-        doc->activeKateView()->setSelection (selection());
-      break;
     default:
       kDebug(13020) << "Unknown KateUndoGroup enum:" << static_cast<int>(m_type);
       break;
@@ -263,14 +233,6 @@
     case KateUndoGroup::editMarkLineAutoWrapped:
       doc->editMarkLineAutoWrapped (m_line, m_col == 1);
       break;
-    case KateUndoGroup::editCursorMove:
-      if(doc->activeKateView())
-        doc->activeKateView()->editSetCursor (KTextEditor::Cursor(m_line, m_col));
-      break;
-    case KateUndoGroup::selectionRange:
-      if(doc->activeKateView())
-        doc->activeKateView()->setSelection (selection());
-      break;
     default:
       kDebug(13020) << "Unknown KateUndoGroup enum:" << static_cast<int>(m_type);
       break;
@@ -278,7 +240,10 @@
 }
 
 KateUndoGroup::KateUndoGroup (KateDocument *doc)
-: m_doc (doc),m_safePoint(false)
+  : m_doc (doc)
+  , m_safePoint(false)
+  , m_selection(-1, -1, -1, -1)
+  , m_cursor(-1, -1)
 {
 }
 
@@ -297,6 +262,13 @@
   for (int i=m_items.size()-1; i >= 0; --i)
     m_items[i]->undo(m_doc);
 
+  if (KateView *view = m_doc->activeKateView()) {
+    if (m_selection.isValid())
+      view->setSelection(m_selection);
+    if (m_cursor.isValid())
+      view->editSetCursor(m_cursor);
+  }
+
   m_doc->editEnd ();
 }
 
@@ -310,6 +282,13 @@
   for (int i=0; i < m_items.size(); ++i)
     m_items[i]->redo(m_doc);
 
+  if (KateView *view = m_doc->activeKateView()) {
+    if (m_selection.isValid())
+      view->setSelection(m_selection);
+    if (m_cursor.isValid())
+      view->editSetCursor(m_cursor);
+  }
+
   m_doc->editEnd ();
 }
 
@@ -318,11 +297,18 @@
   addItem(new KateUndo(type, line, col, len, text));
 }
 
-void KateUndoGroup::addItem (const KTextEditor::Range &selection)
+void KateUndoGroup::setSelection(const KTextEditor::Range &selection)
 {
-  addItem(new KateUndo(selection));
+  if (!m_selection.isValid())
+    m_selection = selection;
 }
 
+void KateUndoGroup::setCursorPosition(const KTextEditor::Cursor &cursor)
+{
+  if (!m_cursor.isValid())
+    m_cursor = cursor;
+}
+
 void KateUndoGroup::addItem(KateUndo* u)
 {
   if (!u->isValid())
@@ -379,16 +365,4 @@
   return true;
 }
 
-bool KateUndoGroup::contains(KateUndoGroup::UndoType type) const
-{
-  if (type == editInvalid) return false;
-
-  Q_FOREACH(const KateUndo *item, m_items)
-    if (item->type() == type)
-      return true;
-
-  return false;
-}
-
-
 // kate: space-indent on; indent-width 2; replace-tabs on;
--- trunk/KDE/kdelibs/kate/document/kateundo.h #802509:802510
@@ -70,8 +70,6 @@
       editInsertLine,
       editRemoveLine,
       editMarkLineAutoWrapped,
-      editCursorMove,
-      selectionRange,
       editInvalid
     };
 
@@ -86,12 +84,18 @@
     void addItem (KateUndoGroup::UndoType type, uint line, uint col, uint len, const QString &text);
 
     /**
-     * add an item to the group, the type is selectionRange 
+     * sets the text selection range for the edit group.
      * @param selection selection to remember
      */
-    void addItem (const KTextEditor::Range &selection);
+    void setSelection (const KTextEditor::Range &selection);
 
     /**
+     * sets the cursor position for the edit group.
+     * @param selection selection to remember
+     */
+    void setCursorPosition (const KTextEditor::Cursor &cursor);
+
+    /**
      * merge this group with an other
      * @param newGroup group to merge into this one
      * @param complex set if a complex undo
@@ -109,13 +113,6 @@
      */
     bool isEmpty () const { return m_items.isEmpty(); }
 
-    /**
-     * do we already have an item of this type?
-     * @param type type to query
-     * @return we contain only the given type
-     */
-    bool contains(KateUndoGroup::UndoType type) const;
-
   private:
     /**
      * singleType
@@ -151,6 +148,16 @@
      * prohibit merging with the next group
      */
     bool m_safePoint;
+
+    /**
+     * the text selection of the active view before the edit step
+     */
+    KTextEditor::Range m_selection;
+
+    /**
+     * the cursor position of the active view before the edit step
+     */
+    KTextEditor::Cursor m_cursor;
 };
 
 #endif
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic