]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
somewhat clearer logic
[lyx.git] / src / lyxfind.C
index 34499ae36b5d13cf686bbbbfe73929682c108598..b5bd7fb7f4e1892118044fe6440f93bff84b9787 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "frontends/Alert.h"
 
-#include "insets/insettext.h"
-
 #include "support/textutils.h"
 
 using lyx::support::lowercase;
@@ -47,8 +45,10 @@ class MatchString
 {
 public:
        MatchString(string const & str, bool cs, bool mw)
-               : str(str), cs(cs), mw(mw) {};
-// returns true if the specified string is at the specified position
+               : str(str), cs(cs), mw(mw)
+       {}
+
+       // returns true if the specified string is at the specified position
        bool operator()(Paragraph const & par, pos_type pos) const
        {                       
                string::size_type size = str.length();
@@ -60,22 +60,28 @@ public:
                           : (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) {
                        ++i;
                }
-               if (size == string::size_type(i)) {
-                       // if necessary, check whether string matches word
-                       if (!mw)
-                               return true;
-                       if ((pos <= 0 || !IsLetterCharOrDigit(par.getChar(pos - 1)))
-                           && (pos + pos_type(size) >= parsize
-                               || !IsLetterCharOrDigit(par.getChar(pos + size)))) {
-                               return true;
-                       }
+
+               if (size != string::size_type(i))
+                       return false;
+
+               // if necessary, check whether string matches word
+               if (mw) {
+                       if (pos > 0     && IsLetterCharOrDigit(par.getChar(pos - 1)))
+                               return false;
+                       if (pos + pos_type(size) < parsize
+                                       && IsLetterCharOrDigit(par.getChar(pos + size)));
+                               return false;
                }
-               return false;
+
+               return true;
        }
        
 private:
+       // search string
        string str;
+       // case sensitive
        bool cs;
+       // match whole words only
        bool mw;
 };
 
@@ -127,8 +133,7 @@ bool searchAllowed(BufferView * bv, string const & str)
 
 
 
-bool find(BufferView * bv, string const & searchstr,
-         bool cs, bool mw, bool fw)
+bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw)
 {
        if (!searchAllowed(bv, searchstr))
                return false;
@@ -159,8 +164,7 @@ int replaceAll(BufferView * bv,
        if (!searchAllowed(bv, searchstr) || buf.isReadonly())
                return 0;
        
-       recordUndo(Undo::ATOMIC, bv->text, 0,
-                  buf.paragraphs().size() - 1);
+       recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1);
        
        PosIterator cur = buf.pos_iterator_begin();
        PosIterator const end = buf.pos_iterator_end();
@@ -181,7 +185,7 @@ int replaceAll(BufferView * bv,
        }
 
        PosIterator beg = buf.pos_iterator_begin();
-       bv->text->init(bv);
+       bv->text()->init(bv);
        put_selection_at(bv, beg, 0, false);
        if (num)
                buf.markDirty();
@@ -201,8 +205,7 @@ bool stringSelected(BufferView * bv,
        string const & str1 = searchstr;
        string const str2 = text->selectionAsString(*bv->buffer(),
                                                    false);
-       if ((cs && str1 != str2)
-           || lowercase(str1) != lowercase(str2)) {
+       if ((cs && str1 != str2) || lowercase(str1) != lowercase(str2)) {
                find(bv, searchstr, cs, mw, fw);
                return false;
        }
@@ -227,7 +230,7 @@ int replace(BufferView * bv,
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
-       text->cursor = fw ? text->selection.end : text->selection.start;
+       text->cursor = fw ? text->selEnd() : text->selStart();
 
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
@@ -266,7 +269,6 @@ bool findNextChange(BufferView * bv)
                }
        }
        pos_type length = end - pos;
-       bv->text->init(bv);
        put_selection_at(bv, cur, length, true);
        return true;
 }