]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView2.C
Change the latex font names in order to match the names of type1inst.
[lyx.git] / src / BufferView2.C
index 6072b4548345bb74ee85ee1708d6b4a1bb9f27ec..892d36e22e68df11a66c015e61bcf72f1b69eaf6 100644 (file)
@@ -34,9 +34,9 @@
 #include "support/filetools.h"
 #include "support/lyxfunctional.h" //equal_1st_in_pair
 #include "support/types.h"
+#include "support/lyxalgo.h" // lyx_count
 
 #include <fstream>
-#include <algorithm>
 
 extern BufferList bufferlist;
 
@@ -47,7 +47,6 @@ using std::endl;
 using std::ifstream;
 using std::vector;
 using std::find;
-using std::count;
 using std::count_if;
 
 
@@ -108,11 +107,10 @@ bool BufferView::insertLyXFile(string const & filen)
 
 bool BufferView::removeAutoInsets()
 {
-       LyXCursor tmpcursor = text->cursor;
-       Paragraph * cur_par = tmpcursor.par();
+       Paragraph * cur_par = text->cursor.par();
        Paragraph * cur_par_prev = cur_par ? cur_par->previous() : 0;
        Paragraph * cur_par_next = cur_par ? cur_par->next() : 0;
-       pos_type cur_pos = tmpcursor.pos();
+       pos_type cur_pos = text->cursor.pos();
 
        bool found = false;
 
@@ -154,6 +152,11 @@ bool BufferView::removeAutoInsets()
                        // The previous setCursor line was deleted and that
                        // was the cur_par line.  This can only happen if an
                        // error box was the sole item on cur_par.
+                       // It is possible for cur_par_prev to be stray if
+                       // the line it pointed to only had a error box on it
+                       // so we have to set it to a known correct value.
+                       // This is often the same value it already had.
+                       cur_par_prev = par->previous();
                        if (cur_par_prev) {
                                // '|' = par, '.' = cur_par, 'E' = error box
                                // First step below may occur before while{}
@@ -204,6 +207,20 @@ bool BufferView::removeAutoInsets()
                }
        }
 
+       // It is possible that the last line is empty if it was cur_par and/or
+       // only had an error inset on it.
+       if (text->setCursor(this, text->ownerParagraph(), 0)
+           && 0 == cur_par_next) {
+               cur_par = cur_par_prev;
+               cur_pos = cur_par->size();
+       } else if (cur_pos > cur_par->size()) {
+               // Some C-Enter lines were removed by the setCursor call which
+               // then invalidated cur_pos. It could still be "wrong" because
+               // the cursor may appear to have jumped but since we collapsed
+               // some C-Enter lines this should be a reasonable compromise.
+               cur_pos = cur_par->size();
+       }
+
        text->setCursorIntern(this, cur_par, cur_pos);
 
        return found;
@@ -503,7 +520,7 @@ bool BufferView::lockInset(UpdatableInset * inset)
                                }
                                if ((*it)->getInsetFromID(id)) {
                                        text->setCursorIntern(this, par, it.getPos());
-                                       theLockingInset(static_cast<UpdatableInset *>(*it));
+                                       (*it)->edit(this);
                                        return theLockingInset()->lockInsetInInset(this, inset);
                                }
                        }
@@ -650,10 +667,8 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
 {
        // Check if the label 'from' appears more than once
        vector<string> labels = buffer()->getLabelList();
-       // count is broken on some systems, so use the HP version
-       int res;
-       count(labels.begin(), labels.end(), from, res);
-       if (res > 1)
+
+       if (lyx::count(labels.begin(), labels.end(), from) > 1)
                return false;
 
        return ChangeInsets(Inset::REF_CODE, from, to);