]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
Fixed cut&paste bugs and added freespacing for ERT Insets.
[lyx.git] / src / lyxfind.C
index 34d1bfaebe14352a6c6b90958f60285307b42e11..93af1df39085c8890700cecf1235c68c35ab87e0 100644 (file)
@@ -7,13 +7,16 @@
 #include "lyxtext.h"
 #include "lyxfind.h"
 #include "LyXView.h"
-#include "lyx_gui_misc.h"
+#include "frontends/Alert.h"
 #include "support/textutils.h"
 #include "support/lstrings.h"
 #include "BufferView.h"
 #include "buffer.h"
 #include "gettext.h"
 
+using lyx::pos_type;
+
+
 ///
 // locally used enum
 ///
@@ -28,7 +31,7 @@ enum SearchResult {
 
 
 /// returns true if the specified string is at the specified  position
-bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
+bool IsStringInText(Paragraph * par, pos_type pos,
                     string const & str, bool const & = true,
                     bool const & = false);
 
@@ -53,7 +56,7 @@ int LyXReplace(BufferView * bv,
        if (searchstr.length() == 0
                || (searchstr.length() == 1 && searchstr[0] == ' '))
        {
-               WriteAlert(_("Sorry!"), _("You cannot replace a single space, "
+               Alert::alert(_("Sorry!"), _("You cannot replace a single space, "
                                          "nor an empty character."));
                return 0;
        }
@@ -80,10 +83,10 @@ int LyXReplace(BufferView * bv,
        string str2;
        if (casesens) {
                str1 = searchstr;
-               str2 = text->selectionAsString(bv->buffer());
+               str2 = text->selectionAsString(bv->buffer(), false);
        } else {
                str1 = lowercase(searchstr);
-               str2 = lowercase(text->selectionAsString(bv->buffer()));
+               str2 = lowercase(text->selectionAsString(bv->buffer(), false));
        }
        if (str1 != str2) {
                if (!LyXFind(bv, searchstr, fw, false, casesens, matchwrd) ||
@@ -104,7 +107,7 @@ int LyXReplace(BufferView * bv,
                bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                ++replace_count;
                if (!once)
-                 found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
+                       found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
        } while (!once && replaceall && found);
    
        if (bv->focus())
@@ -140,7 +143,7 @@ bool LyXFind(BufferView * bv,
                else {
                        text = bv->getLyXText();
                        Paragraph * par = text->cursor.par();
-                       Paragraph::size_type pos = text->cursor.pos();
+                       pos_type pos = text->cursor.pos();
                        if (forward) {
                                if (pos < par->size() - 1)
                                        ++pos;
@@ -183,7 +186,7 @@ bool LyXFind(BufferView * bv,
 
 
 // returns true if the specified string is at the specified position
-bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
+bool IsStringInText(Paragraph * par, pos_type pos,
                    string const & str, bool const & cs,
                    bool const & mw)
 {
@@ -191,7 +194,7 @@ bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
                return false;
    
        string::size_type size = str.length();
-       Paragraph::size_type i = 0;
+       pos_type i = 0;
        while (((pos + i) < par->size())
               && (string::size_type(i) < size)
               && (cs ? (str[i] == par->getChar(pos + i))
@@ -201,12 +204,11 @@ bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
        }
        if (size == string::size_type(i)) {
                // if necessary, check whether string matches word
-               if (!mw || 
-                   (mw && ((pos <= 0 || !IsLetterCharOrDigit(par->getChar(pos - 1)))
-                            && (pos + Paragraph::size_type(size) >= par->size()
-                                || !IsLetterCharOrDigit(par->getChar(pos + size))))
-                    ))
-               {
+               if (!mw)
+                       return true;
+               if ((pos <= 0 || !IsLetterCharOrDigit(par->getChar(pos - 1)))
+                       && (pos + pos_type(size) >= par->size()
+                       || !IsLetterCharOrDigit(par->getChar(pos + size)))) {
                        return true;
                }
        }
@@ -220,7 +222,7 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
                            bool const & cs, bool const & mw)
 {
        Paragraph * par = text->cursor.par();
-       Paragraph::size_type pos = text->cursor.pos();
+       pos_type pos = text->cursor.pos();
        UpdatableInset * inset;
 
        while (par && !IsStringInText(par, pos, str, cs, mw)) {
@@ -281,7 +283,7 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
                             bool const & cs, bool const & mw)
 {
        Paragraph * par = text->cursor.par();
-       Paragraph::size_type pos = text->cursor.pos();
+       pos_type pos = text->cursor.pos();
 
        do {
                if (pos > 0)
@@ -311,7 +313,9 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
        if (par) {
                text->setCursor(bv, par, pos);
                return SR_FOUND;
-       } else if (text->inset_owner) {
+       }
+#if 0
+       else if (text->inset_owner) {
                // test if we're inside an inset if yes unlock the inset
                // and recall us with the outside LyXText!
                bv->unlockInset((UpdatableInset *)text->inset_owner);
@@ -319,6 +323,7 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
                        return SearchBackward(bv, bv->getLyXText(), str, cs, mw);
                }
        }
+#endif
        return SR_NOT_FOUND;
 }