Bug 141253 - Ctrl+8/Ctrl+9 completion should offer "nil" completion, also
Summary: Ctrl+8/Ctrl+9 completion should offer "nil" completion, also
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: kwrite (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-06 02:20 UTC by Wolfram R. Sieber
Modified: 2007-02-17 17:18 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfram R. Sieber 2007-02-06 02:20:48 UTC
Version:           4.5.5 (using KDE 3.5.5, Debian Package 4:3.5.5a.dfsg.1-5 (4.0))
Compiler:          Target: i486-linux-gnu
OS:                Linux (i586) release 2.6.18-3-486

Anders,

Thanks for your Ctrl+8/+9 hint. :) But now... maybe you shouldn't have tell me about them. ;-) See below..


I tried them out amidst a word and got stuck with no chance to recover the original word without additional Backspace/Delete keystrokes.

I'm not yet sure whether or not this is a real issue -- i.e. whether people indeed might move the cursor into the middle of a word and use Ctrl+8/+9 there --, but if so, I'd opt for an additional "nil" completion (=""), so that the original word becomes recovered.
Comment 1 Anders Lund 2007-02-06 09:21:19 UTC
That is a good idea i believe. I will add it "at cursor position" in the flow.
Comment 2 Anders Lund 2007-02-06 11:19:09 UTC
SVN commit 630772 by alund:

FEATURE:141253

When using directional completion, reset if the user moves back to the original position in the flow (comlete forward/backward an equal amount of times, and the text is reset)



 M  +22 -2     docwordcompletion.cpp  


--- trunk/KDE/kdelibs/kate/plugins/wordcompletion/docwordcompletion.cpp #630771:630772
@@ -93,7 +93,6 @@
       return QVariant::Invalid;
     case InheritanceDepth:
       return 0;
-
   }
 
   return QVariant();
@@ -267,6 +266,7 @@
   QRegExp re;           // hrm
   KToggleAction *autopopup; // for accessing state
   uint treshold;        // the required length of a word before popping up the completion list automatically
+  int directionalPos;   // be able to insert "" at the correct time
 };
 
 DocWordCompletionPluginView::DocWordCompletionPluginView( uint treshold,
@@ -434,6 +434,8 @@
   if ( wrd.isEmpty() )
     return;
 
+  int inc = fw ? 1 : -1;
+
   /* IF the current line is equal to the previous line
      AND the position - the length of the last inserted string
           is equal to the old position
@@ -447,6 +449,24 @@
     // this is a repeted activation
     ccol = d->ccol;
     wrd = d->last;
+
+    // if we are back to where we started, reset.
+    if ( ( fw && d->directionalPos == -1 ) ||
+         ( !fw && d->directionalPos == 1 ) )
+    {
+      if ( d->lilen )
+        m_view->document()->removeText( KTextEditor::Range(d->cline, d->ccol, d->cline, d->ccol + d->lilen) );
+
+      d->lastIns = "";
+      d->lilen = 0;
+      d->line = d->cline;
+      d->col = d->ccol;
+      d->directionalPos = 0;
+
+      return;
+    }
+
+    d->directionalPos += inc;
   }
   else
   {
@@ -457,10 +477,10 @@
     d->line = cline;
     d->col = ccol - wrd.length();
     d->lilen = 0;
+    d->directionalPos = inc;
   }
 
   d->re.setPattern( "\\b" + wrd + "(\\w+)" );
-  int inc = fw ? 1 : -1;
   int pos ( 0 );
   QString ln = m_view->document()->line( d->line );
 
Comment 3 Anders Lund 2007-02-17 17:18:20 UTC
SVN commit 634566 by alund:

Backport fixes to directional completion in trunk
backport new feature: revert to to original in the correct position in series of directional completions
CCBUG: 141253


 M  +62 -31    docwordcompletion.cpp  


--- branches/KDE/3.5/kdelibs/kate/plugins/wordcompletion/docwordcompletion.cpp #634565:634566
@@ -131,7 +131,8 @@
   QString lastIns;      // latest applied completion
   QRegExp re;           // hrm
   KToggleAction *autopopup; // for accessing state
-  uint treshold;         // the required length of a word before popping up the completion list automatically
+  uint treshold;        // the required length of a word before popping up the completion list automatically
+  int directionalPos;   // be able to insert "" at the correct time
 };
 
 DocWordCompletionPluginView::DocWordCompletionPluginView( uint treshold, bool autopopup, KTextEditor::View *view, const char *name )
@@ -264,8 +265,11 @@
   uint cline, ccol;
   viewCursorInterface( m_view )->cursorPositionReal( &cline, &ccol );
   QString wrd = word();
-  if ( wrd.isEmpty() ) return;
+  if ( wrd.isEmpty() )
+    return;
 
+  int inc = fw ? 1 : -1;
+
   /* IF the current line is equal to the previous line
      AND the position - the length of the last inserted string
           is equal to the old position
@@ -277,28 +281,47 @@
           wrd.endsWith( d->lastIns ) )
   {
     // this is a repeted activation
+
+    // if we are back to where we started, reset.
+    if ( ( fw && d->directionalPos == -1 ) ||
+         ( !fw && d->directionalPos == 1 ) )
+    {
+      if ( d->lilen )
+        ei->removeText( d->cline, d->ccol, d->cline, d->ccol + d->lilen );
+
+      d->lastIns.clear();
+      d->lilen = 0;
+      d->line = d->cline;
+      d->col = d->ccol;
+      d->directionalPos = 0;
+
+      return;
+    }
+
+    if ( fw )
+      d->col += d->lilen;
+
     ccol = d->ccol;
     wrd = d->last;
+
+    d->directionalPos += inc;
   }
   else
   {
     d->cline = cline;
     d->ccol = ccol;
     d->last = wrd;
-    d->lastIns = QString::null;
-    d->line = d->cline;
-    d->col = d->ccol - wrd.length();
+    d->lastIns.clear();
+    d->line = cline;
+    d->col = ccol - wrd.length();
     d->lilen = 0;
+    d->directionalPos = inc;
   }
 
   d->re.setPattern( "\\b" + wrd + "(\\w+)" );
-  int inc = fw ? 1 : -1;
   int pos ( 0 );
   QString ln = ei->textLine( d->line );
 
-  if ( ! fw )
-    ln = ln.mid( 0, d->col );
-
   while ( true )
   {
     pos = fw ?
@@ -310,50 +333,58 @@
       QString m = d->re.cap( 1 );
       if ( m != d->lastIns )
       {
-        d->col = pos; // for next try
-
-        if ( fw )
-          d->col += m.length();
-
-        // if this is a constructed word at cursor pos, retry.
-        if ( pos + wrd.length() == ccol )
-        {
-          d->col = pos + inc;
-          continue;
-        }
-
         // we got good a match! replace text and return.
         if ( d->lilen )
           ei->removeText( d->cline, d->ccol, d->cline, d->ccol + d->lilen );
         ei->insertText( d->cline, d->ccol, m );
 
+        d->lastIns = m;
         d->lilen = m.length();
-        d->lastIns = m;
+        d->col = pos; // for next try
 
         return;
       }
 
       // equal to last one, continue
       else
-        d->col = pos + inc; // for next try
+      {
+        d->col = pos; // for next try
+
+        if ( fw )
+          d->col += d->re.matchedLength();
+
+        else
+        {
+          if ( pos == 0 )
+          {
+            if ( d->line > 0 )
+            {
+              d->line += inc;
+              ln = ei->textLine( d->line );
+              d->col = ln.length();
+            }
+            else
+            {
+              KNotifyClient::beep();
+              return;
+            }
+          }
+
+          else
+            d->col--;
+        }
+      }
     }
 
     else  // no match
     {
-      if ( ! fw && d->line == 0)
+      if ( (! fw && d->line == 0 ) || ( fw && d->line >= (uint)ei->numLines() ) )
       {
         KNotifyClient::beep();
         return;
       }
-      else if ( fw && d->line >= ei->numLines() )
-      {
-        KNotifyClient::beep();
-        return;
-      }
 
       d->line += inc;
-      if ( fw )
-        d->col++;
 
       ln = ei->textLine( d->line );
       d->col = fw ? 0 : ln.length();