]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
fix some C++ parsing bugs
[lyx.git] / src / lyxfind.C
index 2526f48a9f4dd78a4ef52b09c6edaddc2bcc8064..77427ae82d2ae4b3b15052dd983806d343a628a3 100644 (file)
@@ -1,9 +1,5 @@
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "lyxtext.h"
 #include "lyxfind.h"
 #include "paragraph.h"
@@ -61,7 +57,7 @@ int LyXReplace(BufferView * bv,
                text->clearSelection();
                bv->unlockInset(bv->theLockingInset());
                text = bv->text;
-               text->cursorTop(bv);
+               text->cursorTop();
                // override search direction because we search top to bottom
                fw = true;
        }
@@ -96,17 +92,21 @@ int LyXReplace(BufferView * bv,
                         (text->inset_owner == text->inset_owner->getLockingInset())))
                {
                        bv->hideCursor();
-                       bv->update(text, BufferView::SELECT|BufferView::FITCUR);
+                       bv->update(text, BufferView::SELECT);
                        bv->toggleSelection(false);
-                       text->replaceSelectionWithString(bv, replacestr);
-                       text->setSelectionRange(bv, replacestr.length());
-                       bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+                       text->replaceSelectionWithString(replacestr);
+                       text->setSelectionRange(replacestr.length());
+                       bv->update(text, BufferView::SELECT);
                        ++replace_count;
                }
                if (!once)
                        found = LyXFind(bv, searchstr, fw, casesens, matchwrd);
        } while (!once && replaceall && found);
 
+       // FIXME: should be called via an LFUN
+       bv->buffer()->markDirty();
+       bv->fitCursor();
+
        return replace_count;
 }
 
@@ -119,7 +119,7 @@ bool LyXFind(BufferView * bv,
                return false;
 
        bv->hideCursor();
-       bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
+       bv->update(bv->getLyXText(), BufferView::SELECT);
 
        if (bv->theLockingInset()) {
                bool found = forward ?
@@ -132,7 +132,7 @@ bool LyXFind(BufferView * bv,
                // We now are in the main text but if we did a forward
                // search we have to put the cursor behind the inset.
                if (forward) {
-                       bv->text->cursorRight(bv, true);
+                       bv->text->cursorRight(true);
                }
        }
        // If we arrive here we are in the main text again so we
@@ -157,16 +157,18 @@ bool LyXFind(BufferView * bv,
        // inset did it already.
        if (result == SR_FOUND) {
                bv->unlockInset(bv->theLockingInset());
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->setSelectionRange(bv, searchstr.length());
+               bv->update(text, BufferView::SELECT);
+               text->setSelectionRange(searchstr.length());
                bv->toggleSelection(false);
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
+               bv->update(text, BufferView::SELECT);
        } else if (result == SR_NOT_FOUND) {
                bv->unlockInset(bv->theLockingInset());
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
+               bv->update(text, BufferView::SELECT);
                found = false;
        }
 
+       bv->fitCursor();
+
        return found;
 }
 
@@ -255,12 +257,12 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
        }
 
        if (par) {
-               text->setCursor(bv, par, pos);
+               text->setCursor(par, pos);
                return SR_FOUND;
        } else {
                // make sure we end up at the end of the text,
                // not the start point of the last search
-               text->setCursor(bv, prev_par, prev_par->size());
+               text->setCursor(prev_par, prev_par->size());
                return SR_NOT_FOUND;
        }
 }
@@ -305,16 +307,16 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
        } while (par && !IsStringInText(par, pos, str, cs, mw));
 
        if (par) {
-               text->setCursor(bv, par, pos);
+               text->setCursor(par, pos);
                return SR_FOUND;
        } else {
                // go to the last part of the unsuccessful search
-               text->setCursor(bv, prev_par, 0);
+               text->setCursor(prev_par, 0);
                return SR_NOT_FOUND;
        }
 }
 
+
 SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length)
 {
        Paragraph * par = text->cursor.par();
@@ -344,7 +346,7 @@ SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length)
        }
 
        if (par) {
-               text->setCursor(bv, par, pos);
+               text->setCursor(par, pos);
                Change orig_change = par->lookupChangeFull(pos);
                pos_type end = pos;
 
@@ -363,12 +365,12 @@ SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length)
        } else {
                // make sure we end up at the end of the text,
                // not the start point of the last search
-               text->setCursor(bv, prev_par, prev_par->size());
+               text->setCursor(prev_par, prev_par->size());
                return SR_NOT_FOUND;
        }
 }
+
+
 SearchResult findNextChange(BufferView * bv, LyXText * text, pos_type & length)
 {
        if (text->selection.set())
@@ -387,21 +389,21 @@ bool findNextChange(BufferView * bv)
                return false;
 
        bv->hideCursor();
-       bv->update(bv->getLyXText(), BufferView::SELECT | BufferView::FITCUR);
+       bv->update(bv->getLyXText(), BufferView::SELECT);
 
        pos_type length;
+
        if (bv->theLockingInset()) {
                bool found = bv->theLockingInset()->nextChange(bv, length);
+
                // We found the stuff inside the inset so we don't have to
                // do anything as the inset did all the update for us!
                if (found)
                        return true;
+
                // We now are in the main text but if we did a forward
                // search we have to put the cursor behind the inset.
-               bv->text->cursorRight(bv, true);
+               bv->text->cursorRight(true);
        }
        // If we arrive here we are in the main text again so we
        // just start searching from the root LyXText at the position
@@ -413,29 +415,31 @@ bool findNextChange(BufferView * bv)
 
        bv->toggleSelection();
        text->clearSelection();
-       
+
        SearchResult result = nextChange(bv, text, length);
 
        lyxerr << "Result is " << result << endl;
+
        bool found = true;
+
        // If we found the cursor inside an inset we will get back
        // SR_FOUND_NOUPDATE and we don't have to do anything as the
        // inset did it already.
        if (result == SR_FOUND) {
                bv->unlockInset(bv->theLockingInset());
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->setSelectionRange(bv, length);
+               bv->update(text, BufferView::SELECT);
+               text->setSelectionRange(length);
                bv->toggleSelection(false);
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
+               bv->update(text, BufferView::SELECT);
        } else if (result == SR_NOT_FOUND) {
                bv->unlockInset(bv->theLockingInset());
-               bv->update(text, BufferView::SELECT|BufferView::FITCUR);
+               bv->update(text, BufferView::SELECT);
                found = false;
        }
 
+       bv->fitCursor();
+
        return found;
 }
+
 } // end lyxfind namespace