From 0060227f27d9981ed17526ec9d4fedc7ecc6ed38 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 2 Feb 2017 16:14:23 +0100 Subject: [PATCH] Simplify TextMetrics::checkInsetHit The main point is to use CoordCacheBase::covers to see whether a point is inside a given isnet. --- src/TextMetrics.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 94594ede2c..a93f9ba4cd 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1427,28 +1427,12 @@ InsetList::InsetTable * TextMetrics::checkInsetHit(pit_type pit, int x, int y) 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(&(*iit)); + if (insetCache.covers(it.inset, x, y)) { + LYXERR(Debug::DEBUG, "Hit inset: " << it.inset); + return const_cast(&it); } } -- 2.39.2