]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
another fix
[lyx.git] / src / lyxfind.C
index 039d34985d035b3b5681906f84b4cb6380a7db59..597df35b6a3622b2c8e0695f04b86106ebc66b39 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "lyxtext.h"
 #include "lyxfind.h"
+#include "paragraph.h"
 #include "frontends/LyXView.h"
 #include "frontends/Alert.h"
 #include "support/textutils.h"
@@ -14,6 +15,7 @@
 #include "buffer.h"
 #include "debug.h"
 #include "gettext.h"
+#include "insets/insettext.h"
 
 using lyx::pos_type;
 
@@ -85,23 +87,28 @@ int LyXReplace(BufferView * bv,
        int replace_count = 0;
        do {
                text = bv->getLyXText();
-               bv->hideCursor();
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
-               bv->toggleSelection(false);
-               text->replaceSelectionWithString(bv, replacestr);
-               text->setSelectionOverString(bv, replacestr);
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               ++replace_count;
+               // We have to do this check only because mathed insets don't
+               // return their own LyXText but the LyXText of it's parent!
+               if (!bv->theLockingInset() ||
+                       ((text != bv->text) &&
+                        (text->inset_owner == text->inset_owner->getLockingInset())))
+               {
+                       bv->hideCursor();
+                       bv->update(text, BufferView::SELECT|BufferView::FITCUR);
+                       bv->toggleSelection(false);
+                       text->replaceSelectionWithString(bv, replacestr);
+                       text->setSelectionOverString(bv, replacestr);
+                       bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+                       ++replace_count;
+               }
                if (!once)
                        found = LyXFind(bv, searchstr, fw, casesens, matchwrd);
        } while (!once && replaceall && found);
 
-       if (bv->focus())
-               bv->showCursor();
-
        return replace_count;
 }
 
+
 bool LyXFind(BufferView * bv,
             string const & searchstr, bool forward,
             bool casesens, bool matchwrd)
@@ -137,7 +144,7 @@ bool LyXFind(BufferView * bv,
 
        bv->toggleSelection();
        text->clearSelection();
-       
+
        SearchResult result = forward ?
                SearchForward(bv, text, searchstr, casesens, matchwrd) :
                SearchBackward(bv, text, searchstr, casesens, matchwrd);
@@ -157,12 +164,11 @@ bool LyXFind(BufferView * bv,
                bv->update(text, BufferView::SELECT|BufferView::FITCUR);
                found = false;
        }
-       if (result != SR_FOUND_NOUPDATE && bv->focus())
-               bv->showCursor();
 
        return found;
 }
 
+
 SearchResult LyXFind(BufferView * bv, LyXText * text,
                     string const & searchstr, bool forward,
                     bool casesens, bool matchwrd)