From c2771dd61f9f33280c48dfb964b164447ef893f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 15 Oct 2002 16:17:40 +0000 Subject: [PATCH] Fix for the 'spurious selection with RMB' and improved 'cursor up/down' git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5416 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 24 ++++++++++++++---------- src/mathed/math_cursor.C | 34 ++++++++++++++++++++++++++++++++-- src/mathed/math_cursor.h | 11 ++++++----- src/mathed/math_iterator.C | 4 ++-- src/mathed/math_pos.C | 6 ++++++ src/mathed/math_pos.h | 2 ++ 6 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 7da6d42cb7..f4aa659db5 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index d7f2b8d574..0fea05418e 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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(); diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 9eaf8d99a6..0ef9dd555e 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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; diff --git a/src/mathed/math_iterator.C b/src/mathed/math_iterator.C index 8f508907e8..ddfbc620aa 100644 --- a/src/mathed/math_iterator.C +++ b/src/mathed/math_iterator.C @@ -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()! diff --git a/src/mathed/math_pos.C b/src/mathed/math_pos.C index 2dfa32839b..497892f7da 100644 --- a/src/mathed/math_pos.C +++ b/src/mathed/math_pos.C @@ -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_ << ")"; diff --git a/src/mathed/math_pos.h b/src/mathed/math_pos.h index 806827bcfd..a885294adb 100644 --- a/src/mathed/math_pos.h +++ b/src/mathed/math_pos.h @@ -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 -- 2.39.2