mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 21:24:14 +00:00
editXY: make cursor positionning correct over non editable inset
Instead of using complicated (and wrong) code, it is better to use
getPosNearX here.
Also simplify the code by removing temporary variables.
Fixes part of #10569.
(cherry picked from commit 6a0c1c6573
)
This commit is contained in:
parent
db9f41c039
commit
bafc40b857
@ -1369,23 +1369,19 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
|
|||||||
}
|
}
|
||||||
pit_type pit = getPitNearY(y);
|
pit_type pit = getPitNearY(y);
|
||||||
LASSERT(pit != -1, return 0);
|
LASSERT(pit != -1, return 0);
|
||||||
|
Row const & row = getPitAndRowNearY(y, pit, assert_in_view, up);
|
||||||
int yy = y; // is modified by getPitAndRowNearY
|
|
||||||
Row const & row = getPitAndRowNearY(yy, pit, assert_in_view, up);
|
|
||||||
|
|
||||||
cur.pit() = pit;
|
cur.pit() = pit;
|
||||||
|
|
||||||
// Do we cover an inset?
|
// Do we cover an inset?
|
||||||
InsetList::InsetTable * it = checkInsetHit(pit, x, yy);
|
InsetList::InsetTable * it = checkInsetHit(pit, x, y);
|
||||||
|
|
||||||
if (!it) {
|
if (!it) {
|
||||||
// No inset, set position in the text
|
// No inset, set position in the text
|
||||||
bool bound = false; // is modified by getPosNearX
|
bool bound = false; // is modified by getPosNearX
|
||||||
int xx = x; // is modified by getPosNearX
|
cur.pos() = getPosNearX(row, x, bound);
|
||||||
cur.pos() = getPosNearX(row, xx, bound);
|
|
||||||
cur.boundary(bound);
|
cur.boundary(bound);
|
||||||
cur.setCurrentFont();
|
cur.setCurrentFont();
|
||||||
cur.setTargetX(xx);
|
cur.setTargetX(x);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1398,23 +1394,15 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
|
|||||||
cur.setTargetX(x);
|
cur.setTargetX(x);
|
||||||
|
|
||||||
// Try to descend recursively inside the inset.
|
// Try to descend recursively inside the inset.
|
||||||
Inset * edited = inset->editXY(cur, x, yy);
|
Inset * edited = inset->editXY(cur, x, y);
|
||||||
if (edited == inset && cur.pos() == it->pos) {
|
if (edited == inset && cur.pos() == it->pos) {
|
||||||
// non-editable inset, set cursor after the inset if x is
|
// non-editable inset, set cursor after the inset if x is
|
||||||
// nearer to that position (bug 9628)
|
// nearer to that position (bug 9628)
|
||||||
CoordCache::Insets const & insetCache = bv_->coordCache().getInsets();
|
bool bound = false; // is modified by getPosNearX
|
||||||
Dimension const & dim = insetCache.dim(inset);
|
cur.pos() = getPosNearX(row, x, bound);
|
||||||
Point p = insetCache.xy(inset);
|
cur.boundary(bound);
|
||||||
bool const is_rtl = text_->isRTL(text_->getPar(pit));
|
cur.setCurrentFont();
|
||||||
if (is_rtl) {
|
cur.setTargetX(x);
|
||||||
// "in front of" == "right of"
|
|
||||||
if (abs(p.x_ - x) < abs(p.x_ + dim.wid - x))
|
|
||||||
cur.posForward();
|
|
||||||
} else {
|
|
||||||
// "in front of" == "left of"
|
|
||||||
if (abs(p.x_ + dim.wid - x) < abs(p.x_ - x))
|
|
||||||
cur.posForward();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur.top().text() == text_)
|
if (cur.top().text() == text_)
|
||||||
|
Loading…
Reference in New Issue
Block a user