]> git.lyx.org Git - lyx.git/blobdiff - src/lyxtextclass.C
Fix deleting of paragraphs after undo (fix #236).
[lyx.git] / src / lyxtextclass.C
index ff19fbc4934c40c6e28ae83dabb78f299f5fd4da..7f6a668ff464adfee5de6161a4246f86ccfaf8d6 100644 (file)
@@ -183,7 +183,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                                string const name = subst(lexrc.getString(),
                                                    '_', ' ');
                                if (hasLayout(name)) {
-                                       LyXLayout & lay = operator[](name);
+                                       LyXLayout & lay =
+                                               const_cast<LyXLayout &>(operator[](name));
                                        error = do_readStyle(lexrc, lay);
                                } else {
                                        LyXLayout lay;
@@ -511,40 +512,20 @@ LyXLayout const & LyXTextClass::operator[](string const & n) const
                lyxerr << "Operator[] called with empty n" << endl;
        
        string const name = (n.empty() ? defaultLayoutName() : n);
-       
-       LayoutList::const_iterator cit =
-               find_if(layoutlist.begin(),
-                       layoutlist.end(),
-                       lyx::compare_memfun(&LyXLayout::name, name));
 
-       if (cit == layoutlist.end()) {
-               lyxerr << "We failed to find the layout '" << name
-                      << "' in the layout list. You MUST investigate!"
-                      << endl;
-               
-               // we require the name to exist
-               lyx::Assert(false);
-       }
+       static string lastLayoutName;
+       static LayoutList::difference_type lastLayoutIndex;
 
-       return *cit;
-}
+       if (name == lastLayoutName)
+               return layoutlist[lastLayoutIndex];
 
-
-LyXLayout & LyXTextClass::operator[](string const & n)
-{
-       lyx::Assert(!n.empty());
-
-       if (n.empty())
-               lyxerr << "Operator[] called with empty n" << endl;
-
-       string const name = (n.empty() ? defaultLayoutName() : n);
        
-       LayoutList::iterator it =
+       LayoutList::const_iterator cit =
                find_if(layoutlist.begin(),
                        layoutlist.end(),
                        lyx::compare_memfun(&LyXLayout::name, name));
 
-       if (it == layoutlist.end()) {
+       if (cit == layoutlist.end()) {
                lyxerr << "We failed to find the layout '" << name
                       << "' in the layout list. You MUST investigate!"
                       << endl;
@@ -552,8 +533,11 @@ LyXLayout & LyXTextClass::operator[](string const & n)
                // we require the name to exist
                lyx::Assert(false);
        }
+
+       lastLayoutName = name;
+       lastLayoutIndex = std::distance(layoutlist.begin(), cit);
        
-       return *it;
+       return *cit;
 }
 
 
@@ -608,12 +592,6 @@ LyXLayout const & LyXTextClass::defaultLayout() const
 }
 
 
-LyXLayout & LyXTextClass::defaultLayout()
-{
-       return operator[](defaultLayoutName());
-}
-
-
 string const & LyXTextClass::name() const
 {
        return name_;