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

List:       kde-core-devel
Subject:    Re: [PATCH] selections in konsole
From:       Waldo Bastian <bastian () kde ! org>
Date:       2001-07-26 0:54:21
[Download RAW message or body]

On Wednesday 25 July 2001 10:33 am, Waldo Bastian wrote:
> On Wednesday 25 July 2001 07:08 am, Carsten Pfeiffer wrote:
> > On Mittwoch, 25. Juli 2001 07:50 Waldo Bastian wrote:
> > > Selections in konsole don't scroll along with the rest of the text when
> > > the konsole buffer has reached its maximum size. This patch attemtps to
> > > fix that.
> >
> > Neither do they scroll with the text when you're working in a pager, e.g.
> > less, btw.
>
> Hm, I was afraid of that. Luckily I thought out The Right Way (tm) to
> handle this all this night, stay tuned for a new patch.

Ok.. take #2. New and improved.

Cheers,
Waldo
-- 
Andrei Sakharov, Exiled 1980-1986, USSR, http://www.aip.org/history/sakharov/
Dmitry Sklyarov, Detained 2001-????, USA, http://www.elcomsoft.com/

["konsole_selection2.diff" (text/x-diff)]

Index: TEScreen.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/TEScreen.C,v
retrieving revision 1.51
diff -u -3 -d -p -r1.51 TEScreen.C
--- TEScreen.C	2001/07/23 20:20:19	1.51
+++ TEScreen.C	2001/07/26 00:48:44
@@ -843,6 +843,38 @@ void TEScreen::moveImage(int dst, int lo
   }
   //kdDebug(1211) << "Using memmove to scroll up" << endl;
   memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca));
+  if (sel_begin != -1)
+  {
+     // Adjust selection to follow scroll.
+     bool beginIsTL = (sel_begin == sel_TL);     
+     int diff = dst - loca; // Scroll by this amount
+     int scr_TL=loc(0,hist->getLines());
+     loca += scr_TL; // Translate index from screen to global
+     loce += scr_TL; // Translate index from screen to global
+
+//qWarning("loca = %d loce = %d sel_TL = %d sel_BR = %d diff = %d", loca, loce, sel_TL, sel_BR, diff);
+
+     if ((sel_TL >= loca) && (sel_TL <= loce))
+        sel_TL += diff;
+
+     if ((sel_BR >= loca) && (sel_BR <= loce))
+        sel_BR += diff;
+
+     if (sel_BR < 0)
+     {
+        clearSelection();
+     }
+     else 
+     {
+        if (sel_TL < 0)
+           sel_TL = 0;
+     }
+
+     if (beginIsTL)
+        sel_begin = sel_TL;
+     else
+        sel_begin = sel_BR;
+  }
 }
 
 /*! clear from (including) current cursor position to end of screen.
@@ -1199,8 +1231,49 @@ void TEScreen::addHistLine()
     hist->addCells(image,end+1);
     hist->addLine();
 
+    bool beginIsTL = (sel_begin == sel_TL);
+
     // adjust history cursor
-    histCursor += (hist->getLines()-1 == histCursor);
+    if (hist->getLines()-1 == histCursor)
+    {
+       histCursor++;
+       // Adjust selection for the new 
+       if (sel_begin != -1)
+       {
+//qWarning("sel_TL = %d sel_BR = %d  += columns", sel_TL, sel_BR);
+          sel_TL += columns;
+          sel_BR += columns;
+       }
+    }
+
+    if (sel_begin != -1)
+    {
+       // Scroll selection in history up
+       int top_BR = loc(0, 1+hist->getLines());
+
+//qWarning("top_BR = %d sel_TL = %d sel_BR = %d  -= columns", top_BR, sel_TL, sel_BR);
+
+       if (sel_TL < top_BR)
+          sel_TL -= columns;
+
+       if (sel_BR < top_BR)
+          sel_BR -= columns;
+
+       if (sel_BR < 0)
+       {
+          clearSelection();
+       }
+       else 
+       {
+          if (sel_TL < 0)
+             sel_TL = 0;
+       }
+
+       if (beginIsTL)
+          sel_begin = sel_TL;
+       else
+          sel_begin = sel_BR;
+    }
   }
 
   if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround
@@ -1223,6 +1296,7 @@ int TEScreen::getHistLines()
 
 void TEScreen::setScroll(const HistoryType& t)
 {
+  clearSelection();
   hist = t.getScroll(hist);
   histCursor = hist->getLines();
 }


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

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