// returns the column near the specified x-coordinate of the row
// x is set to the real beginning of this column
pos_type TextMetrics::getPosNearX(Row const & row, int & x,
- bool & boundary) const
+ bool & boundary, bool const select) const
{
//LYXERR0("getPosNearX(" << x << ") row=" << row);
/// For the main Text, it is possible that this pit is not
for ( ; cit != cend; ++cit) {
if (w <= x && w + cit->full_width() > x) {
int x_offset = int(x - w);
- pos = cit->x2pos(x_offset);
+ pos = cit->x2pos(x_offset, select);
x = int(x_offset + w);
break;
}
}
-void TextMetrics::setCursorFromCoordinates(Cursor & cur, int const x, int const y)
+void TextMetrics::setCursorFromCoordinates(Cursor & cur, int const x,
+ int const y, bool const select)
{
LASSERT(text_ == cur.text(), return);
pit_type const pit = getPitNearY(y);
bool bound = false;
int xx = x;
- pos_type const pos = getPosNearX(row, xx, bound);
+ pos_type const pos = getPosNearX(row, xx, bound, select);
LYXERR(Debug::DEBUG, "setting cursor pit: " << pit << " pos: " << pos);
LYXERR(Debug::DEBUG, "x: " << x << " y: " << y << " pit: " << pit);
- InsetList::const_iterator iit = par.insetList().begin();
- InsetList::const_iterator iend = par.insetList().end();
- for (; iit != iend; ++iit) {
- Inset * inset = iit->inset;
-
- LYXERR(Debug::DEBUG, "examining inset " << inset);
-
- if (!insetCache.has(inset)) {
- LYXERR(Debug::DEBUG, "inset has no cached position");
- return 0;
- }
-
- Dimension const & dim = insetCache.dim(inset);
- Point p = insetCache.xy(inset);
-
- LYXERR(Debug::DEBUG, "xo: " << p.x_ << "..." << p.x_ + dim.wid
- << " yo: " << p.y_ - dim.asc << "..." << p.y_ + dim.des);
+ for (auto const & it : par.insetList()) {
+ LYXERR(Debug::DEBUG, "examining inset " << it.inset);
- if (x >= p.x_ && x <= p.x_ + dim.wid
- && y >= p.y_ - dim.asc && y <= p.y_ + dim.des) {
- LYXERR(Debug::DEBUG, "Hit inset: " << inset);
- return const_cast<InsetList::InsetTable *>(&(*iit));
+ if (insetCache.covers(it.inset, x, y)) {
+ LYXERR(Debug::DEBUG, "Hit inset: " << it.inset);
+ return const_cast<InsetList::InsetTable *>(&it);
}
}