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
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
return DISPATCHED;
}
- if (cmd.button() == mouse_button::button3) {
- mathcursor->dispatch(cmd);
- //delete mathcursor;
- return DISPATCHED;
- }
-
bv->updateInset(this, false);
return DISPATCHED;
}
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;
}
-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())
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";
}
+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();
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
/// 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;
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()!
}
+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_ << ")";
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