]> git.lyx.org Git - features.git/commitdiff
Fix for the 'spurious selection with RMB' and improved 'cursor up/down'
authorAndré Pönitz <poenitz@gmx.net>
Tue, 15 Oct 2002 16:17:40 +0000 (16:17 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 15 Oct 2002 16:17:40 +0000 (16:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5416 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_iterator.C
src/mathed/math_pos.C
src/mathed/math_pos.h

index 7da6d42cb7e034186117c03affcbf64a198901b4..f4aa659db5f9916453f2846a5f33dcd8967615df 100644 (file)
@@ -297,7 +297,8 @@ Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
        BufferView * bv = cmd.view();
        hideInsetCursor(bv);
        showInsetCursor(bv);
-       bv->updateInset(this, false);
+       bv->updateInset(this, true);
+       //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << "\n";
 
        if (cmd.button() == mouse_button::button3) {
                // try to dispatch to enclosed insets first
@@ -336,6 +337,12 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
        BufferView * bv = cmd.view();
        releaseMathCursor(bv);
        mathcursor = new MathCursor(this, cmd.x == 0);
+       //lyxerr << "lfunMousePress: buttons: " << cmd.button() << "\n";
+
+       if (cmd.button() == mouse_button::button3) {
+               mathcursor->dispatch(cmd);
+               return DISPATCHED;
+       }
 
        if (cmd.button() == mouse_button::button1) {
                // just set the cursor here
@@ -349,12 +356,6 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
                return DISPATCHED;
        }
 
-       if (cmd.button() == mouse_button::button3) {
-               mathcursor->dispatch(cmd);
-               //delete mathcursor;
-               return DISPATCHED;
-       }
-
        bv->updateInset(this, false);
        return DISPATCHED;
 }
@@ -368,10 +369,13 @@ Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
        if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED)
                return DISPATCHED;
 
-       if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2) {
-               //lyxerr << "insetMotionNotify: ignored\n";
+       // only select with button 1
+       if (cmd.button() != mouse_button::button1) 
                return DISPATCHED;
-       }
+
+       if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
+               return DISPATCHED;
+       
        first_x = cmd.x;
        first_y = cmd.y;
 
index d7f2b8d57472e73c5b26e49db8996d5b183536f0..0fea05418e74693858700314273c8cff65935c62 100644 (file)
@@ -262,7 +262,8 @@ void MathCursor::last()
 }
 
 
-bool positionable(MathIterator const & cursor, MathIterator const & anchor)
+bool positionable
+       (MathIterator const & cursor, MathIterator const & anchor)
 {
        // avoid deeper nested insets when selecting
        if (cursor.size() > anchor.size())
@@ -1003,8 +1004,12 @@ bool MathCursor::goUpDown(bool up)
        while (1) {
                ///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
                // ask inset first
-               if (par()->idxUpDown(idx(), pos(), up, targetx_))
+               if (par()->idxUpDown(idx(), pos(), up, targetx_)) {
+                       // try to find best position within this inset
+                       if (!selection())
+                               bruteFind2(xo, yo);
                        return true;
+               }
 
                // no such inset found, just take something "above"
                ///lyxerr << "updown: handled by strange case\n";
@@ -1061,6 +1066,31 @@ bool MathCursor::bruteFind
 }
 
 
+void MathCursor::bruteFind2(int x, int y)
+{
+       double best_dist = 1e10;
+
+       MathIterator it = Cursor_;
+       it.back().setPos(0);
+       MathIterator et = Cursor_;
+       et.back().setPos(it.cell().size());
+       while (1) {
+               int xo, yo;
+               it.back().getPos(xo, yo);
+               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'
+               if (d <= best_dist) {
+                       best_dist = d;
+                       Cursor_   = it;
+               }
+               if (it == et)
+                       break;
+               ++it;
+       }
+}
+
+
 bool MathCursor::idxLineLast()
 {
        idx() -= idx() % par()->ncols();
index 9eaf8d99a6d5a7736726a56a5952443144606beb..0ef9dd555e9652626eb346c9a14d8a625c41a711 100644 (file)
@@ -260,12 +260,13 @@ private:
        bool posRight();
        /// moves position somehow up or down
        bool goUpDown(bool up);
-       /// moves position into box
-       bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
+       /// moves position closest to (x, y) in given box
+       bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
+       /// moves position closest to (x, y) in current cell
+       void bruteFind2(int x, int y);
        /// are we in a nucleus of a script inset?
        bool inNucleus() const;
 
-
        /// grab grid marked by anchor and current cursor 
        MathGridInset grabSelection() const;
        /// erase the selected part and re-sets the cursor
@@ -273,9 +274,9 @@ private:
        /// guess what
        MathGridInset grabAndEraseSelection();
 
-       ///
+       /// the name of the macro we are currently inputting
        string macroName() const;
-       ///
+       /// where in the curent cell does the macro name start?
        MathInset::difference_type macroNamePos() const;
        /// can we enter the inset?
        bool openable(MathAtom const &, bool selection) const;
index 8f508907e8bbed52a78ce3fe1d2307141bb078f0..ddfbc620aa4fc6eca595a9b30dde715289d28b0b 100644 (file)
@@ -77,8 +77,8 @@ void MathIterator::goEnd()
 
 void MathIterator::operator++()
 {
-       MathCursorPos   & top = back();
-       MathArray & ar  = top.par_->cell(top.idx_);
+       MathCursorPos & top = back();
+       MathArray     & ar  = top.par_->cell(top.idx_);
 
        // move into the current inset if possible
        // it is impossible for pos() == size()!
index 2dfa32839bf15579d95ac930014e290bcb85da9b..497892f7da86c1ee0e244df4518618160efcf5be 100644 (file)
@@ -44,6 +44,12 @@ void MathCursorPos::getPos(int & x, int & y) const
 }
 
 
+void MathCursorPos::setPos(MathArray::pos_type pos)
+{
+       pos_ = pos;
+}
+
+
 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
 {
        os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
index 806827bcfdf58ccaa9975bb359f4724aa21c145e..a885294adbd8fda22c18bbc78002f3c6eb3b3f0d 100644 (file)
@@ -23,6 +23,8 @@ public:
        MathArray & cell(MathArray::idx_type idx) const;
        /// gets screen position of the thing
        void getPos(int & x, int & y) const;
+       /// set position
+       void setPos(MathArray::pos_type pos);
 
 public:
        /// pointer to an inset