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

List:       kde-commits
Subject:    kdenetwork/ksirc
From:       Andrew Stanley-Jones <asj () cban ! com>
Date:       2003-01-20 5:27:07
[Download RAW message or body]

CVS commit by asj: 

This fixes a really bad memory corruption bug in ksirc tha caused tons of crashes.

Why:

1. When the mouse was pressed the selectionStart and End were both set to
   the right item.  Don't move the mouse.
2. The Item was set to NoSelection.
3. If a relayout caused the item to be deleted the relayout then
   updates the selection state writting to the item just deleted item.
   Since the item was set to NoSelection when it's deleted it does
   not fix the dangling pointers.
4. Turns out all wrapped lines are deleted on screen updates so
   this happends a lot.

Fix:

1. Don't store the Start and End pointers on initial click.
2. Store a tentative selectionPoint and wait the mouse to move.
3. if it moves make a true selection, it doesn't erase it on release.

Only store start and end pointers when the selection mode in not NoSelection!


  M +11 -4     kstextview.cpp   1.80
  M +3 -0      kstextview.h   1.47


--- kdenetwork/ksirc/kstextview.h  #1.46:1.47
@@ -179,4 +179,6 @@ public:
                          const ItemProperties &props = ItemProperties() );
 
+    TextParag *getParag() { return m_parag; }
+
 protected:
     mutable bool m_extendsDirty;
@@ -504,4 +506,5 @@ private:
     QPixmap m_paintBuffer;
 
+    SelectionPoint m_selectionMaybeStart;
     SelectionPoint m_selectionStart;
     SelectionPoint m_selectionEnd;

--- kdenetwork/ksirc/kstextview.cpp  #1.79:1.80
@@ -352,5 +352,5 @@ Item *TextChunk::hardBreak( const String
 {
     TextChunk *chunk = new TextChunk( m_parag, rightHandSide, m_props );
-    chunk->m_originalTextLength = 0; // ### hack...
+    chunk->m_originalTextLength = 0; // ### hack... You make the last line dynamic \
so if it's 1 word it doesn't chop itself up  
     m_text.len = rightHandSide.ptr - m_text.ptr;
@@ -1605,6 +1605,5 @@ void TextView::contentsMousePressEvent( 
         Item *itemUnderMouse = itemAt( ev->pos(), &p, Item::SelectFuzzy );
         if ( p.item ) {
-            m_selectionStart = p;
-            m_selectionEnd = p;
+            m_selectionMaybeStart = p;
             p.item->setSelectionStatus( Item::NoSelection );
         }
@@ -1643,7 +1642,13 @@ void TextView::contentsMouseMoveEvent( Q
         return;
 
-    if ( ev->state() & LeftButton && m_selectionStart.item && p.item )
+    if ( (ev->state() & LeftButton && m_selectionStart.item && p.item) ||
+         (ev->state() & LeftButton && m_selectionMaybeStart.item && p.item))
     {
 
+        if(m_selectionMaybeStart.item != 0){
+            m_selectionStart = m_selectionMaybeStart;
+            m_selectionMaybeStart = SelectionPoint();
+        }
+
         m_selectionEnd = p;
 
@@ -1702,4 +1707,6 @@ void TextView::contentsMouseReleaseEvent
     m_dragStartPos = QPoint();
     m_dragURL = QString::null;
+
+    m_selectionMaybeStart = SelectionPoint();
 
     if ((ev->button() & Qt::LeftButton) && !m_selectedText.isEmpty() )


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

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