Bug 101895 - Kate refuses to replace a pattern with an empty string
Summary: Kate refuses to replace a pattern with an empty string
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Unclassified
Component: general (show other bugs)
Version: 2.4
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Anders Lund
URL:
Keywords:
: 102678 105540 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-19 14:54 UTC by Maxilys
Modified: 2005-05-12 17:32 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxilys 2005-03-19 14:54:48 UTC
Version:           2.4 (using KDE 3.4.0 Level "a" , SUSE 9.2 UNSUPPORTED)
Compiler:          gcc version 3.3.4 (pre 3.3.5 20040809)
OS:                Linux (i686) release 2.6.8-24.11-default

It is impossible to use search&replace to erase a pattern. If you delete the replace field, Kate remembers what was in it for the previous search&replace and uses it instead of an empty string.

It only works as expected when Kate just started because she has no replace text to remember.
Comment 1 Anders Lund 2005-03-19 15:10:26 UTC
I'll fix it for 3.4.1. In the meantime, you can use the commandline replace as a work around (press F7 and enter 'replace PATTERN' will replace with nothing)
Comment 2 Anders Lund 2005-03-19 15:17:44 UTC
CVS commit by alund: 

allow to replace with nothing.
BUG: 101895
Could someone please backport?


  M +18 -11    katesearch.cpp   1.87


--- kdelibs/kate/part/katesearch.cpp  #1.86:1.87
@@ -38,4 +38,5 @@
 #include <kfinddialog.h>
 #include <kreplacedialog.h>
+#include <knotifyclient.h>
 
 #include <qlayout.h>
@@ -111,5 +112,5 @@ void KateSearch::find()
 }
 
-void KateSearch::find( const QString &pattern, long flags, bool add, bool shownotfound )
+bool KateSearch::find( const QString &pattern, long flags, bool add, bool shownotfound )
 {
   KateViewConfig::global()->setSearchFlags( flags );
@@ -145,5 +146,5 @@ void KateSearch::find( const QString &pa
   s.showNotFound = shownotfound;
 
-  search( searchFlags );
+  return search( searchFlags );
 }
 
@@ -166,7 +167,7 @@ void KateSearch::replace()
     m_replacement = replaceDialog->replacement();
     s_searchList = replaceDialog->findHistory () ;
-    s_replaceList = replaceDialog->replacementHistory () ;
+    s_replaceList = replaceDialog->replacementHistory ();
 
-    replace( s_searchList.first(), s_replaceList.first(), opts );
+    replace( s_searchList.first(), m_replacement, opts );
   }
 
@@ -234,5 +235,5 @@ void KateSearch::findAgain( bool back )
 }
 
-void KateSearch::search( SearchFlags flags )
+bool KateSearch::search( SearchFlags flags )
 {
   s.flags = flags;
@@ -262,6 +263,7 @@ void KateSearch::search( SearchFlags fla
     else
       replaceAll();
+    return false; // FIXME
   } else {
-    findAgain();
+    return findAgain();
   }
 }
@@ -291,19 +293,21 @@ void KateSearch::wrapSearch()
 }
 
-void KateSearch::findAgain()
+bool KateSearch::findAgain()
 {
   if(  s_pattern.isEmpty() ) {
     find();
-    return;
+    return false; // ### make find() return a bool too just to be consequent
   }
 
   if ( doSearch(  s_pattern ) ) {
     exposeFound( s.cursor, s.matchedLength );
+    return true;
   } else if( !s.flags.finished ) {
     if( askContinue() ) {
       wrapSearch();
-      findAgain();
+      return findAgain();
     } else {
       if (arbitraryHLExample) m_arbitraryHLList->clear();
+      return false;
     }
   } else {
@@ -315,4 +319,5 @@ void KateSearch::findAgain()
         i18n("Find"));
   }
+  return false;
 }
 
@@ -806,5 +811,6 @@ while ( (p = pattern.find( '\\' + delim,
   if ( cmd.startsWith( "find" ) )
   {
-    ((KateView*)view)->find( pattern, f );
+    if ( ! ((KateView*)view)->find( pattern, f ) )
+      msg = i18n("'%1' not found.").arg( pattern );
     return true;
   }
@@ -899,5 +905,6 @@ void SearchCommand::processText( Kate::V
         v->setCursorPositionInternal( v->selStartLine(), v->selStartCol() );
 
-      v->find( pattern, m_ifindFlags, false );
+      if ( ! v->find( pattern, m_ifindFlags, false ) )
+        KNotifyClient::beep();
     }
   }
Comment 3 Anders Lund 2005-03-19 15:39:56 UTC
Sorry for the lengthy commit, but I *did* fix it. Just needs a backport, but that will be done too...
Comment 4 Dominik Haumann 2005-03-21 00:31:18 UTC
CVS commit by dhaumann: 

Backport Anders' fix for bug: allow to replace with nothing.
CCBUG: 101895


  M +1 -1      katesearch.cpp   1.84.2.1


--- kdelibs/kate/part/katesearch.cpp  #1.84:1.84.2.1
@@ -167,5 +167,5 @@ void KateSearch::replace()
     s_replaceList = replaceDialog->replacementHistory () ;
 
-    replace( s_searchList.first(), s_replaceList.first(), opts );
+    replace( s_searchList.first(), m_replacement, opts );
   }
 
Comment 5 Anders Lund 2005-03-28 15:56:56 UTC
*** Bug 102678 has been marked as a duplicate of this bug. ***
Comment 6 Anders Lund 2005-05-12 17:32:52 UTC
*** Bug 105540 has been marked as a duplicate of this bug. ***