mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
More fixes to cursorX
In Row::Element::pos2x, handle the boundaries in a cleaner way.
This commit is contained in:
parent
8649ac7fe6
commit
79014c7551
22
src/Row.cpp
22
src/Row.cpp
@ -36,17 +36,23 @@ using frontend::FontMetrics;
|
|||||||
|
|
||||||
double Row::Element::pos2x(pos_type const i) const
|
double Row::Element::pos2x(pos_type const i) const
|
||||||
{
|
{
|
||||||
|
LASSERT(i >= pos && i <= endpos, return 0);
|
||||||
|
|
||||||
bool const rtl = font.isVisibleRightToLeft();
|
bool const rtl = font.isVisibleRightToLeft();
|
||||||
|
|
||||||
// handle first the two bounds of the element
|
int w = 0;
|
||||||
if ((!rtl && pos >= i) || (rtl && endpos <= i))
|
//handle first the two bounds of the element
|
||||||
return 0;
|
if (i == pos)
|
||||||
if ((!rtl && endpos <= i) || (rtl && pos >= i))
|
w = 0;
|
||||||
return width();
|
else if (i == endpos)
|
||||||
|
w = width();
|
||||||
|
else {
|
||||||
|
LASSERT(type == STRING, return 0);
|
||||||
|
FontMetrics const & fm = theFontMetrics(font);
|
||||||
|
// FIXME Avoid caching of metrics there?
|
||||||
|
w = fm.width(str.substr(0, i - pos));
|
||||||
|
}
|
||||||
|
|
||||||
FontMetrics const & fm = theFontMetrics(font);
|
|
||||||
// FIXME Avoid caching of metrics there?
|
|
||||||
int const w = fm.width(str.substr(0, i - pos));
|
|
||||||
if (rtl)
|
if (rtl)
|
||||||
return width() - w;
|
return width() - w;
|
||||||
else
|
else
|
||||||
|
@ -1613,15 +1613,16 @@ int TextMetrics::cursorX(CursorSlice const & sl,
|
|||||||
double x = row.x;
|
double x = row.x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When boundary is true, position is on the row element (pos, endpos)
|
* When boundary is true, position i is in the row element (pos, endpos)
|
||||||
* if
|
* if
|
||||||
* pos < pos <= endpos
|
* pos < i <= endpos
|
||||||
* whereas, when boundary is false, the test is
|
* whereas, when boundary is false, the test is
|
||||||
* pos <= pos < endpos
|
* pos <= i < endpos
|
||||||
* The correction below allows to handle both cases.
|
* The correction below allows to handle both cases.
|
||||||
*/
|
*/
|
||||||
int const boundary_corr = (boundary && pos) ? -1 : 0;
|
int const boundary_corr = (boundary && pos) ? -1 : 0;
|
||||||
|
|
||||||
|
//?????
|
||||||
if (row.empty()
|
if (row.empty()
|
||||||
|| (row.begin()->font.isVisibleRightToLeft()
|
|| (row.begin()->font.isVisibleRightToLeft()
|
||||||
&& pos == row.begin()->endpos))
|
&& pos == row.begin()->endpos))
|
||||||
|
Loading…
Reference in New Issue
Block a user