]> git.lyx.org Git - lyx.git/blobdiff - src/cursor.C
explain why ownsClipbiard() does not work on Windows and OS X
[lyx.git] / src / cursor.C
index 3146935b4795dd1b3fd22f80a82fe08e438e068f..68a5e8ba4b711b71a8318c30d88dcec008ff4c9e 100644 (file)
@@ -13,6 +13,7 @@
 #include <config.h>
 
 #include "BufferView.h"
+#include "bufferview_funcs.h"
 #include "buffer.h"
 #include "cursor.h"
 #include "coordcache.h"
@@ -55,9 +56,6 @@ namespace lyx {
 using std::string;
 using std::vector;
 using std::endl;
-#ifndef CXX_GLOBAL_CSTD
-using std::isalpha;
-#endif
 using std::min;
 using std::for_each;
 
@@ -92,7 +90,7 @@ namespace {
                it.top().pos() = 0;
                DocIterator et = c;
                et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
-               for (size_t i = 0; ; ++i) {
+               for (size_t i = 0;; ++i) {
                        int xo;
                        int yo;
                        InsetBase const * inset = &it.inset();
@@ -117,7 +115,7 @@ namespace {
                        double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
                        // '<=' in order to take the last possible position
                        // this is important for clicking behind \sum in e.g. '\sum_i a'
-                       lyxerr[Debug::DEBUG] << "i: " << i << " d: " << d
+                       LYXERR(Debug::DEBUG) << "i: " << i << " d: " << d
                                << " best: " << best_dist << endl;
                        if (d <= best_dist) {
                                best_dist = d;
@@ -278,7 +276,7 @@ void LCursor::setCursor(DocIterator const & cur)
 
 void LCursor::dispatch(FuncRequest const & cmd0)
 {
-       lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
+       LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION
                             << " cmd: " << cmd0 << '\n'
                             << *this << endl;
        if (empty())
@@ -289,7 +287,7 @@ void LCursor::dispatch(FuncRequest const & cmd0)
        LCursor safe = *this;
 
        for (; depth(); pop()) {
-               lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
+               LYXERR(Debug::DEBUG) << "LCursor::dispatch: cmd: "
                        << cmd0 << endl << *this << endl;
                BOOST_ASSERT(pos() <= lastpos());
                BOOST_ASSERT(idx() <= lastidx());
@@ -307,7 +305,7 @@ void LCursor::dispatch(FuncRequest const & cmd0)
        // it completely to get a 'bomb early' behaviour in case this
        // object will be used again.
        if (!disp_.dispatched()) {
-               lyxerr[Debug::DEBUG] << "RESTORING OLD CURSOR!" << endl;
+               LYXERR(Debug::DEBUG) << "RESTORING OLD CURSOR!" << endl;
                operator=(safe);
                disp_.update(Update::None);
                disp_.dispatched(false);
@@ -404,17 +402,11 @@ void LCursor::getPos(int & x, int & y) const
 }
 
 
-Row & LCursor::textRow()
-{
-       BOOST_ASSERT(!paragraph().rows().empty());
-       return paragraph().getRow(pos(), boundary());
-}
-
-
 Row const & LCursor::textRow() const
 {
-       BOOST_ASSERT(!paragraph().rows().empty());
-       return paragraph().getRow(pos(), boundary());
+       ParagraphMetrics const & pm = bv().parMetrics(text(), pit());
+       BOOST_ASSERT(!pm.rows().empty());
+       return pm.getRow(pos(), boundary());
 }
 
 
@@ -548,8 +540,12 @@ void LCursor::info(odocstream & os) const
                operator[](i).inset().infoize(os);
                os << "  ";
        }
-       if (pos() != 0)
-               prevInset()->infoize2(os);
+       if (pos() != 0) {
+               InsetBase const * inset = prevInset();
+               // prevInset() can return 0 in certain case.
+               if (inset)
+                       prevInset()->infoize2(os);
+       }
        // overwite old message
        os << "                    ";
 }
@@ -563,6 +559,7 @@ bool LCursor::selHandle(bool sel)
 
        resetAnchor();
        selection() = sel;
+       cap::saveSelection(*this);
        return true;
 }
 
@@ -602,7 +599,6 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 #include "mathed/InsetMathScript.h"
 #include "mathed/InsetMathUnknown.h"
 #include "mathed/MathFactory.h"
-#include "mathed/MathMacroArgument.h"
 #include "mathed/MathStream.h"
 #include "mathed/MathSupport.h"
 
@@ -770,7 +766,7 @@ bool LCursor::backspace()
        autocorrect() = false;
 
        if (selection()) {
-               cap::selDel(*this);
+               cap::eraseSelection(*this);
                return true;
        }
 
@@ -787,8 +783,10 @@ bool LCursor::backspace()
                        // [|], can not delete from inside
                        return false;
                } else {
-                       // move to left
-                       popLeft();
+                       if (inMathed())
+                               pullArg();
+                       else
+                               popLeft();
                        return true;
                }
        }
@@ -822,7 +820,7 @@ bool LCursor::erase()
                return true;
 
        if (selection()) {
-               cap::selDel(*this);
+               cap::eraseSelection(*this);
                return true;
        }
 
@@ -1118,7 +1116,7 @@ bool LCursor::goUpDown(bool up)
 
 void LCursor::handleFont(string const & font)
 {
-       lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl;
+       LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION << ": " << font << endl;
        docstring safe;
        if (selection()) {
                macroModeClose();
@@ -1300,6 +1298,7 @@ void LCursor::fixIfBroken()
                               << ", max is " << copy.lastidx()
                               << " at level " << copy.depth()
                               << ". Trying to correct this."  << endl;
+                       lyxerr << "old: " << *this << endl;
                        newdepth = copy.depth() - 1;
                }
                else if (copy.pit() > copy.lastpit()) {
@@ -1307,6 +1306,7 @@ void LCursor::fixIfBroken()
                               << ", max is " << copy.lastpit()
                               << " at level " << copy.depth()
                               << ". Trying to correct this."  << endl;
+                       lyxerr << "old: " << *this << endl;
                        newdepth = copy.depth() - 1;
                }
                else if (copy.pos() > copy.lastpos()) {
@@ -1314,6 +1314,7 @@ void LCursor::fixIfBroken()
                               << ", max is " << copy.lastpos()
                               << " at level " << copy.depth()
                               << ". Trying to correct this."  << endl;
+                       lyxerr << "old: " << *this << endl;
                        newdepth = copy.depth() - 1;
                }
                copy.pop();
@@ -1323,6 +1324,8 @@ void LCursor::fixIfBroken()
        while (depth() > newdepth) {
                pop();
                lyxerr << "correcting cursor to level " << depth() << endl;
+               lyxerr << "new: " << *this << endl;
+               clearSelection();
        }
 }