]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
GuiTabular: disabling is now done on textChanged()
[lyx.git] / src / lyxfind.cpp
index a19724b8cea126e8da86b3b9a4c6a5d4ac6daf47..d6df0ef78009aef22a93fb10631d08415fc74da7 100644 (file)
@@ -154,7 +154,9 @@ bool findOne(BufferView * bv, docstring const & searchstr,
        if (!searchAllowed(searchstr))
                return false;
 
-       DocIterator cur = bv->cursor();
+       DocIterator cur = forward 
+               ? bv->cursor().selectionEnd() 
+               : bv->cursor().selectionBegin();
 
        MatchString const match(searchstr, case_sens, whole);
 
@@ -495,54 +497,62 @@ typedef vector<pair<string, string> > Escapes;
 /// @note Beware of order
 Escapes const & get_regexp_escapes()
 {
+       typedef std::pair<std::string, std::string> P;
+
        static Escapes escape_map;
        if (escape_map.empty()) {
-               escape_map.push_back(pair<string, string>("$", "_x_$"));
-               escape_map.push_back(pair<string, string>("{", "_x_{"));
-               escape_map.push_back(pair<string, string>("}", "_x_}"));
-               escape_map.push_back(pair<string, string>("[", "_x_["));
-               escape_map.push_back(pair<string, string>("]", "_x_]"));
-               escape_map.push_back(pair<string, string>("(", "_x_("));
-               escape_map.push_back(pair<string, string>(")", "_x_)"));
-               escape_map.push_back(pair<string, string>("+", "_x_+"));
-               escape_map.push_back(pair<string, string>("*", "_x_*"));
-               escape_map.push_back(pair<string, string>(".", "_x_."));
-               escape_map.push_back(pair<string, string>("\\", "(?:\\\\|\\\\backslash)"));
-               escape_map.push_back(pair<string, string>("~", "(?:\\\\textasciitilde|\\\\sim)"));
-               escape_map.push_back(pair<string, string>("^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
-               escape_map.push_back(pair<string, string>("_x_", "\\"));
+               escape_map.push_back(P("$", "_x_$"));
+               escape_map.push_back(P("{", "_x_{"));
+               escape_map.push_back(P("}", "_x_}"));
+               escape_map.push_back(P("[", "_x_["));
+               escape_map.push_back(P("]", "_x_]"));
+               escape_map.push_back(P("(", "_x_("));
+               escape_map.push_back(P(")", "_x_)"));
+               escape_map.push_back(P("+", "_x_+"));
+               escape_map.push_back(P("*", "_x_*"));
+               escape_map.push_back(P(".", "_x_."));
+               escape_map.push_back(P("\\", "(?:\\\\|\\\\backslash)"));
+               escape_map.push_back(P("~", "(?:\\\\textasciitilde|\\\\sim)"));
+               escape_map.push_back(P("^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
+               escape_map.push_back(P("_x_", "\\"));
        }
        return escape_map;
 }
 
 /// A map of lyx escaped strings and their unescaped equivalent.
-Escapes const & get_lyx_unescapes() {
+Escapes const & get_lyx_unescapes()
+{
+       typedef std::pair<std::string, std::string> P;
+
        static Escapes escape_map;
        if (escape_map.empty()) {
-               escape_map.push_back(pair<string, string>("\\%", "%"));
-               escape_map.push_back(pair<string, string>("\\mathcircumflex ", "^"));
-               escape_map.push_back(pair<string, string>("\\mathcircumflex", "^"));
-               escape_map.push_back(pair<string, string>("\\backslash ", "\\"));
-               escape_map.push_back(pair<string, string>("\\backslash", "\\"));
-               escape_map.push_back(pair<string, string>("\\\\{", "_x_<"));
-               escape_map.push_back(pair<string, string>("\\\\}", "_x_>"));
-               escape_map.push_back(pair<string, string>("\\sim ", "~"));
-               escape_map.push_back(pair<string, string>("\\sim", "~"));
+               escape_map.push_back(P("\\%", "%"));
+               escape_map.push_back(P("\\mathcircumflex ", "^"));
+               escape_map.push_back(P("\\mathcircumflex", "^"));
+               escape_map.push_back(P("\\backslash ", "\\"));
+               escape_map.push_back(P("\\backslash", "\\"));
+               escape_map.push_back(P("\\\\{", "_x_<"));
+               escape_map.push_back(P("\\\\}", "_x_>"));
+               escape_map.push_back(P("\\sim ", "~"));
+               escape_map.push_back(P("\\sim", "~"));
        }
        return escape_map;
 }
 
 /// A map of escapes turning a regexp matching text to one matching latex.
-Escapes const & get_regexp_latex_escapes() {
+Escapes const & get_regexp_latex_escapes()
+{
+       typedef std::pair<std::string, std::string> P;
+
        static Escapes escape_map;
        if (escape_map.empty()) {
-               escape_map.push_back(pair<string, string>("\\\\", "(?:\\\\\\\\|\\\\backslash|\\\\textbackslash\\{\\})"));
-               escape_map.push_back(pair<string, string>("(<?!\\\\\\\\textbackslash)\\{", "\\\\\\{"));
-               escape_map.push_back(pair<string, string>("(<?!\\\\\\\\textbackslash\\\\\\{)\\}", "\\\\\\}"));
-               escape_map.push_back(pair<string, string>("\\[", "\\{\\[\\}"));
-               escape_map.push_back(pair<string, string>("\\]", "\\{\\]\\}"));
-               escape_map.push_back(pair<string, string>("\\^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
-               escape_map.push_back(pair<string, string>("%", "\\\\\\%"));
+               escape_map.push_back(P("\\\\", "(?:\\\\\\\\|\\\\backslash|\\\\textbackslash\\{\\})"));
+               escape_map.push_back(P("(<?!\\\\\\\\textbackslash)\\{", "\\\\\\{"));
+               escape_map.push_back(P("(<?!\\\\\\\\textbackslash\\\\\\{)\\}", "\\\\\\}"));
+               escape_map.push_back(P("\\[", "\\{\\[\\}"));
+               escape_map.push_back(P("\\]", "\\{\\]\\}"));
+               escape_map.push_back(P("\\^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
+               escape_map.push_back(P("%", "\\\\\\%"));
        }
        return escape_map;
 }
@@ -615,6 +625,7 @@ string escape_for_regex(string s, bool match_latex)
        return s;
 }
 
+
 /// Wrapper for lyx::regex_replace with simpler interface
 bool regex_replace(string const & s, string & t, string const & searchstr,
                   string const & replacestr)
@@ -629,6 +640,7 @@ bool regex_replace(string const & s, string & t, string const & searchstr,
        return rv;
 }
 
+
 /** Checks if supplied string segment is well-formed from the standpoint of matching open-closed braces.
  **
  ** Verify that closed braces exactly match open braces. This avoids that, for example,
@@ -670,6 +682,7 @@ bool braces_match(string::const_iterator const & beg,
        return true;
 }
 
+
 /** The class performing a match between a position in the document and the FindAdvOptions.
  **/
 class MatchStringAdv {
@@ -754,7 +767,8 @@ static docstring buffer_to_latex(Buffer & buffer)
 }
 
 
-static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions const & opt) {
+static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions const & opt)
+{
        docstring str;
        if (!opt.ignoreformat) {
                str = buffer_to_latex(buffer);
@@ -779,7 +793,8 @@ static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions co
 
 
 /// Return separation pos between the leading material and the rest
-static size_t identifyLeading(string const & s)  {
+static size_t identifyLeading(string const & s)
+{
        string t = s;
        // @TODO Support \item[text]
        while (regex_replace(t, t, "^\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\*?\\{", "")
@@ -793,7 +808,8 @@ static size_t identifyLeading(string const & s)  {
 
 
 // Remove trailing closure of math, macros and environments, so to catch parts of them.
-static int identifyClosing(string & t) {
+static int identifyClosing(string & t)
+{
        int open_braces = 0;
        do {
                LYXERR(Debug::FIND, "identifyClosing(): t now is '" << t << "'");
@@ -960,10 +976,10 @@ string MatchStringAdv::normalize(docstring const & s, bool hack_braces) const
        else
                t = lyx::to_utf8(s);
        // Remove \n at begin
-       while (t.size() > 0 && t[0] == '\n')
+       while (!t.empty() && t[0] == '\n')
                t = t.substr(1);
        // Remove \n at end
-       while (t.size() > 0 && t[t.size() - 1] == '\n')
+       while (!t.empty() && t[t.size() - 1] == '\n')
                t = t.substr(0, t.size() - 1);
        size_t pos;
        // Replace all other \n with spaces
@@ -1203,7 +1219,8 @@ int findMostBackwards(DocIterator & cur, MatchStringAdv const & match)
 
 
 /// Finds backwards
-int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) {
+int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match)
+{
        if (! cur)
                return 0;
        // Backup of original position
@@ -1282,7 +1299,8 @@ namespace {
 
 
 /** Check if 'len' letters following cursor are all non-lowercase */
-static bool allNonLowercase(DocIterator const & cur, int len) {
+static bool allNonLowercase(DocIterator const & cur, int len)
+{
        pos_type end_pos = cur.pos() + len;
        for (pos_type pos = cur.pos(); pos != end_pos; ++pos)
                if (isLowerCase(cur.paragraph().getChar(pos)))
@@ -1292,7 +1310,8 @@ static bool allNonLowercase(DocIterator const & cur, int len) {
 
 
 /** Check if first letter is upper case and second one is lower case */
-static bool firstUppercase(DocIterator const & cur) {
+static bool firstUppercase(DocIterator const & cur)
+{
        char_type ch1, ch2;
        if (cur.pos() >= cur.lastpos() - 1) {
                LYXERR(Debug::FIND, "No upper-case at cur: " << cur);
@@ -1313,13 +1332,15 @@ static bool firstUppercase(DocIterator const & cur) {
  **
  ** \fixme What to do with possible further paragraphs in replace buffer ?
  **/
-static void changeFirstCase(Buffer & buffer, TextCase first_case, TextCase others_case) {
+static void changeFirstCase(Buffer & buffer, TextCase first_case, TextCase others_case)
+{
        ParagraphList::iterator pit = buffer.paragraphs().begin();
        pos_type right = pos_type(1);
        pit->changeCase(buffer.params(), pos_type(0), right, first_case);
        right = pit->size() + 1;
        pit->changeCase(buffer.params(), right, right, others_case);
 }
+
 } // anon namespace
 
 ///