]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
BufferParams.cpp: make Lithuanian documents compilable, fixes http://bugzilla.lyx...
[lyx.git] / src / Cursor.cpp
index 98d18fa125938792818e34e4aa3bd93196acf7f6..a51c98b8b4c6c2d8c945cb5b7507790ac0e7b97a 100644 (file)
@@ -249,13 +249,13 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up)
 
 docstring parbreak(Paragraph const & par)
 {
-       odocstringstream ods;
-       ods << '\n';
+       odocstringstream os;
+       os << '\n';
        // only add blank line if we're not in an ERT or Listings inset
        if (par.ownerCode() != ERT_CODE
                        && par.ownerCode() != LISTINGS_CODE)
-               ods << '\n';
-       return ods.str();
+               os << '\n';
+       return os.str();
 }
 
 } // namespace anon
@@ -468,7 +468,7 @@ bool Cursor::posVisRight(bool skip_inset)
        new_cur.pos() = right_pos;
        new_cur.boundary(false);
        if (!skip_inset &&
-               text()->checkAndActivateInsetVisual(new_cur, right_pos>=pos(), false)) {
+               text()->checkAndActivateInsetVisual(new_cur, right_pos >= pos(), false)) {
                // we actually move the cursor at the end of this function, for now
                // we just keep track of the new position in new_cur...
                LYXERR(Debug::RTL, "entering inset at: " << new_cur.pos());
@@ -944,7 +944,14 @@ DocIterator Cursor::selectionBegin() const
 {
        if (!selection())
                return *this;
-       DocIterator di = (anchor() < top() ? anchor_ : *this);
+
+       DocIterator di;
+       // FIXME: This is a work-around for the problem that
+       // CursorSlice doesn't keep track of the boundary.
+       if (anchor() == top())
+               di = anchor_.boundary() > boundary() ? anchor_ : *this;
+       else
+               di = anchor() < top() ? anchor_ : *this;
        di.resize(depth());
        return di;
 }
@@ -954,7 +961,15 @@ DocIterator Cursor::selectionEnd() const
 {
        if (!selection())
                return *this;
-       DocIterator di = (anchor() > top() ? anchor_ : *this);
+
+       DocIterator di;
+       // FIXME: This is a work-around for the problem that
+       // CursorSlice doesn't keep track of the boundary.
+       if (anchor() == top())
+               di = anchor_.boundary() < boundary() ? anchor_ : *this;
+       else
+               di = anchor() > top() ? anchor_ : *this;
+
        if (di.depth() > depth()) {
                di.resize(depth());
                ++di.pos();
@@ -965,18 +980,20 @@ DocIterator Cursor::selectionEnd() const
 
 void Cursor::setSelection()
 {
-       selection() = true;
+       setSelection(true);
        // A selection with no contents is not a selection
        // FIXME: doesnt look ok
-       if (pit() == anchor().pit() && pos() == anchor().pos())
-               selection() = false;
+       if (idx() == anchor().idx() && 
+           pit() == anchor().pit() && 
+           pos() == anchor().pos())
+               setSelection(false);
 }
 
 
 void Cursor::setSelection(DocIterator const & where, int n)
 {
        setCursor(where);
-       selection() = true;
+       setSelection(true);
        anchor_ = where;
        pos() += n;
 }
@@ -984,8 +1001,8 @@ void Cursor::setSelection(DocIterator const & where, int n)
 
 void Cursor::clearSelection()
 {
-       selection() = false;
-       mark() = false;
+       setSelection(false);
+       setMark(false);
        resetAnchor();
 }
 
@@ -1048,7 +1065,7 @@ bool Cursor::selHandle(bool sel)
                cap::saveSelection(*this);
 
        resetAnchor();
-       selection() = sel;
+       setSelection(sel);
        return true;
 }
 
@@ -1307,7 +1324,7 @@ bool Cursor::backspace()
                // let's require two backspaces for 'big stuff' and
                // highlight on the first
                resetAnchor();
-               selection() = true;
+               setSelection(true);
                --pos();
        } else {
                --pos();
@@ -1355,7 +1372,7 @@ bool Cursor::erase()
        // 'clever' UI hack: only erase large items if previously slected
        if (pos() != lastpos() && nextAtom()->nargs() > 0) {
                resetAnchor();
-               selection() = true;
+               setSelection(true);
                ++pos();
        } else {
                plainErase();
@@ -1812,6 +1829,8 @@ void Cursor::handleFont(string const & font)
                safe = cap::grabAndEraseSelection(*this);
        }
 
+       recordUndoInset();
+
        if (lastpos() != 0) {
                // something left in the cell
                if (pos() == 0) {
@@ -1831,8 +1850,9 @@ void Cursor::handleFont(string const & font)
                }
        } else {
                // nothing left in the cell
-               pullArg();
+               popBackward();
                plainErase();
+               resetAnchor();
        }
        insert(safe);
 }
@@ -1998,7 +2018,6 @@ bool Cursor::fixIfBroken()
 {
        if (DocIterator::fixIfBroken()) {
                        clearSelection();
-                       resetAnchor();
                        return true;
        }
        return false;
@@ -2090,8 +2109,7 @@ bool Cursor::textUndo()
                return false;
        // Set cursor
        setCursor(dit);
-       selection() = false;
-       resetAnchor();
+       clearSelection();
        fixIfBroken();
        return true;
 }
@@ -2105,8 +2123,7 @@ bool Cursor::textRedo()
                return false;
        // Set cursor
        setCursor(dit);
-       selection() = false;
-       resetAnchor();
+       clearSelection();
        fixIfBroken();
        return true;
 }
@@ -2118,6 +2135,18 @@ void Cursor::finishUndo() const
 }
 
 
+void Cursor::beginUndoGroup() const
+{
+       bv_->buffer().undo().beginUndoGroup();
+}
+
+
+void Cursor::endUndoGroup() const
+{
+       bv_->buffer().undo().endUndoGroup();
+}
+
+
 void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to) const
 {
        bv_->buffer().undo().recordUndo(*this, kind, from, to);
@@ -2163,11 +2192,8 @@ void Cursor::recordUndoSelection() const
 
 void Cursor::checkBufferStructure()
 {
-       if (paragraph().layout().toclevel == Layout::NOT_IN_TOC)
-               return;
        Buffer const * master = buffer().masterBuffer();
-       master->tocBackend().updateItem(ParConstIterator(*this));
-       master->structureChanged();
+       master->tocBackend().updateItem(*this);
 }