- && row.back().endpos == row.endpos())
- boundary = row.right_boundary();
-
-#if !defined(KEEP_OLD_METRICS_CODE)
- return pos - row.pos();
-#else
- Buffer const & buffer = bv_->buffer();
-
- /// For the main Text, it is possible that this pit is not
- /// yet in the CoordCache when moving cursor up.
- /// x Paragraph coordinate is always 0 for main text anyway.
- int const xo = origin_.x_;
- int x2 = x - xo;
- Paragraph const & par = text_->getPar(pit);
- Bidi bidi;
- bidi.computeTables(par, buffer, row);
-
- pos_type vc = row.pos();
- pos_type const end = row.endpos();
- pos_type c = 0;
- Layout const & layout = par.layout();
-
- bool left_side = false;
-
- pos_type body_pos = par.beginOfBody();
-
- double tmpx = row.x;
- double last_tmpx = tmpx;
-
- if (body_pos > 0 &&
- (body_pos > end || !par.isLineSeparator(body_pos - 1)))
- body_pos = 0;
-
- // check for empty row
- if (vc == end) {
- x2 = int(tmpx) + xo;
- return 0;
- }
-
- // This (rtl_support test) is not needed, but gives
- // some speedup if rtl_support == false
- bool const lastrow = lyxrc.rtl_support && row.endpos() == par.size();
-
- // If lastrow is false, we don't need to compute
- // the value of rtl.
- bool const rtl_on_lastrow = lastrow ? text_->isRTL(par) : false;
-
- while (vc < end && tmpx <= x2) {
- c = bidi.vis2log(vc);
- last_tmpx = tmpx;
- if (body_pos > 0 && c == body_pos - 1) {
- FontMetrics const & fm = theFontMetrics(
- text_->labelFont(par));
- tmpx += row.label_hfill + fm.width(layout.labelsep);
- if (par.isLineSeparator(body_pos - 1))
- tmpx -= singleWidth(pit, body_pos - 1);
- }
-
- tmpx += singleWidth(pit, c);
- if (par.isSeparator(c) && c >= body_pos)
- tmpx += row.separator;
- ++vc;
- }
-
- if ((tmpx + last_tmpx) / 2 > x2) {
- tmpx = last_tmpx;
- left_side = true;
- }
-
- // This shouldn't happen. But we can reset and try to continue.
- LASSERT(vc <= end, vc = end);
-
- bool boundary2 = false;
-
- if (lastrow &&
- ((rtl_on_lastrow && left_side && vc == row.pos() && x2 < tmpx - 5) ||
- (!rtl_on_lastrow && !left_side && vc == end && x2 > tmpx + 5))) {
- if (!par.isNewline(end - 1))
- c = end;
- } else if (vc == row.pos()) {
- c = bidi.vis2log(vc);
- if (bidi.level(c) % 2 == 1)
- ++c;
- } else {
- c = bidi.vis2log(vc - 1);
- bool const rtl = (bidi.level(c) % 2 == 1);
- if (left_side == rtl) {
- ++c;
- boundary2 = isRTLBoundary(pit, c);
- }
- }
-
-// I believe this code is not needed anymore (Jug 20050717)
-#if 0
- // The following code is necessary because the cursor position past
- // the last char in a row is logically equivalent to that before
- // the first char in the next row. That's why insets causing row
- // divisions -- Newline and display-style insets -- must be treated
- // specially, so cursor up/down doesn't get stuck in an air gap -- MV
- // Newline inset, air gap below:
- if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
- if (bidi.level(end -1) % 2 == 0)
- tmpx -= singleWidth(pit, end - 1);