diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index d497313e49..1c52d6e331 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -476,7 +476,7 @@ void BufferView::Pimpl::scrollDocView(int value) cur.clearSelection(); break; case bv_funcs::CUR_INSIDE: - int const y = bv_funcs::getPos(cur).y_; + int const y = bv_funcs::getPos(cur, cur.boundary()).y_; int const newy = min(last, max(y, first)); if (y != newy) { cur.reset(buffer_->inset()); @@ -596,7 +596,7 @@ bool BufferView::Pimpl::fitCursor() LyXFont const font = cursor_.getFont(); int const asc = font_metrics::maxAscent(font); int const des = font_metrics::maxDescent(font); - Point const p = bv_funcs::getPos(cursor_); + Point const p = bv_funcs::getPos(cursor_, cursor_.boundary()); if (p.y_ - asc >= 0 && p.y_ + des < workarea().workHeight()) return false; } @@ -766,8 +766,8 @@ void BufferView::Pimpl::center() bot.text()->redoParagraph(pit); Paragraph const & par = bot.text()->paragraphs()[pit]; anchor_ref_ = pit; - offset_ref_ = bv_funcs::coordOffset(cursor_).y_ + par.ascent() - - workarea().workHeight() / 2; + offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_ + + par.ascent() - workarea().workHeight() / 2; } diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index d550b73184..fe13bf6160 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -152,7 +152,7 @@ bool string2font(string const & data, LyXFont & font, bool & toggle) // the next two should probably go elsewhere // this give the position relative to (0, baseline) of outermost // paragraph -Point coordOffset(DocIterator const & dit) +Point coordOffset(DocIterator const & dit, bool boundary) { int x = 0; int y = 0; @@ -162,37 +162,41 @@ Point coordOffset(DocIterator const & dit) CursorSlice const & sl = dit[i]; int xx = 0; int yy = 0; - sl.inset().getCursorPos(sl, xx, yy); + sl.inset().cursorPos(sl, boundary, xx, yy); x += xx; y += yy; - //lyxerr << "LCursor::getPos, i: " << i << " x: " << xx << " y: " << y << endl; + //lyxerr << "LCursor::getPos, i: " + // << i << " x: " << xx << " y: " << y << endl; } // Add contribution of initial rows of outermost paragraph CursorSlice const & sl = dit[0]; Paragraph const & par = sl.text()->getPar(sl.pit()); y -= par.rows()[0].ascent(); - for (size_t rit = 0, rend = par.pos2row(sl.pos()); rit != rend; ++rit) + //size_t rend = par.pos2row(sl.pos() - boundary ? 1 : 0); + size_t rend = par.pos2row(sl.pos()); + for (size_t rit = 0; rit != rend; ++rit) y += par.rows()[rit].height(); - y += par.rows()[par.pos2row(sl.pos())].ascent(); - x += dit.bottom().text()->cursorX(dit.bottom()); + y += par.rows()[rend].ascent(); + x += dit.bottom().text()->cursorX(dit.bottom(), boundary); // The following correction should not be there at all. - // The cusor looks much better with the -1, though. + // The cursor looks much better with the -1, though. --x; return Point(x, y); } -Point getPos(DocIterator const & dit) +Point getPos(DocIterator const & dit, bool boundary) { CursorSlice const & bot = dit.bottom(); - CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(bot.text())->second; + CoordCache::InnerParPosCache const & cache = + theCoords.getParPos().find(bot.text())->second; CoordCache::InnerParPosCache::const_iterator it = cache.find(bot.pit()); if (it == cache.end()) { //lyxerr << "cursor out of view" << std::endl; return Point(-1, -1); } - Point p = coordOffset(dit); // offset from outer paragraph + Point p = coordOffset(dit, boundary); // offset from outer paragraph p.y_ += it->second.y_; return p; } diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 291119a1ea..7cd3f17be4 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -17,11 +17,11 @@ #include #include +class BufferView; +class DocIterator; +class InsetBase_code; class LyXFont; class Point; -class DocIterator; -class BufferView; -class InsetBase_code; namespace bv_funcs { @@ -37,7 +37,7 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle); */ std::string const freefont2string(); -Point getPos(DocIterator const & dit); +Point getPos(DocIterator const & dit, bool boundary); enum CurStatus { CUR_INSIDE, @@ -49,7 +49,7 @@ enum CurStatus { CurStatus status(BufferView const * bv, DocIterator const & dit); -Point coordOffset(DocIterator const & dit); +Point coordOffset(DocIterator const & dit, bool boundary); /// Moves cursor to the next inset with one of the given codes. void gotoInset(BufferView * bv, std::vector const & codes, diff --git a/src/cursor.C b/src/cursor.C index 8e2a117d01..e72426f647 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -97,9 +97,7 @@ namespace { for (int i = 0; ; ++i) { int xo; int yo; - LCursor cur = c; - cur.setCursor(it); - cur.inset().getCursorPos(cur.top(), xo, yo); + it.inset().cursorPos(it.top(), c.boundary(), xo, yo); double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); // '<=' in order to take the last possible position // this is important for clicking behind \sum in e.g. '\sum_i a' @@ -134,7 +132,7 @@ namespace { // avoid invalid nesting when selecting if (bv_funcs::status(&cursor.bv(), it) == bv_funcs::CUR_INSIDE && (!cursor.selection() || positionable(it, cursor.anchor_))) { - Point p = bv_funcs::getPos(it); + Point p = bv_funcs::getPos(it, false); int xo = p.x_; int yo = p.y_; if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { @@ -167,7 +165,7 @@ namespace { // bv functions are not yet available! LCursor::LCursor(BufferView & bv) : DocIterator(), bv_(&bv), anchor_(), x_target_(-1), - selection_(false), mark_(false) + selection_(false), mark_(false), logicalpos_(false) {} @@ -309,7 +307,7 @@ int LCursor::currentMode() void LCursor::getPos(int & x, int & y) const { - Point p = bv_funcs::getPos(*this); + Point p = bv_funcs::getPos(*this, boundary()); x = p.x_; y = p.y_; } diff --git a/src/cursor.h b/src/cursor.h index 773513a161..817cdd4817 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -206,6 +206,11 @@ private: bool selection_; /// are we on the way to get one? bool mark_; + /// If true, we are behind the previous char, otherwise we are in front + // of the next char. This only make a difference when we are in front + // of a big inset spanning a whole row and computing coordinates for + // displaying the cursor. + bool logicalpos_; private: diff --git a/src/cursor_slice.C b/src/cursor_slice.C index b98aed8f25..f4a59dfb80 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -30,12 +30,12 @@ using std::endl; CursorSlice::CursorSlice() - : inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false) + : inset_(0), idx_(0), pit_(0), pos_(0) {} CursorSlice::CursorSlice(InsetBase & p) - : inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false) + : inset_(&p), idx_(0), pit_(0), pos_(0) { BOOST_ASSERT(inset_); } diff --git a/src/cursor_slice.h b/src/cursor_slice.h index 6d3508ef34..304dceb901 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -104,10 +104,6 @@ public: /// /// texted specific stuff /// - /// \sa boundary_ - bool boundary() const { return boundary_; } - /// \sa boundary_ - bool & boundary() { return boundary_; } /// returns text corresponding to this position LyXText * text(); /// returns text corresponding to this position @@ -156,22 +152,6 @@ private: bool pit_valid_; /// position in this cell pos_type pos_; - /** - * When the cursor position is i, is the cursor after the i-th char - * or before the i+1-th char ? Normally, these two interpretations are - * equivalent, except when the fonts of the i-th and i+1-th char - * differ. - * We use boundary_ to distinguish between the two options: - * If boundary_=true, then the cursor is after the i-th char - * and if boundary_=false, then the cursor is before the i+1-th char. - * - * We currently use the boundary only when the language direction of - * the i-th char is different than the one of the i+1-th char. - * In this case it is important to distinguish between the two - * cursor interpretations, in order to give a reasonable behavior to - * the user. - */ - bool boundary_; }; /// test for equality diff --git a/src/dociterator.h b/src/dociterator.h index 393af2791e..5b410ae9a7 100644 --- a/src/dociterator.h +++ b/src/dociterator.h @@ -55,16 +55,10 @@ public: explicit DocIterator(InsetBase & inset); /// access slice at position \p i - CursorSlice const & operator[](size_t i) const { - return slices_[i]; - } - + CursorSlice const & operator[](size_t i) const { return slices_[i]; } /// access slice at position \p i - CursorSlice & operator[](size_t i) { - return slices_[i]; - } - - // What is the point of this function? + CursorSlice & operator[](size_t i) { return slices_[i]; } + /// chop a few slices from the iterator void resize(size_t i) { slices_.resize(i); } /// is the iterator valid? @@ -129,6 +123,10 @@ public: InsetBase * prevInset(); /// the inset just in front of the cursor InsetBase const * prevInset() const; + /// + bool boundary() const { return boundary_; } + /// + void boundary(bool b) { boundary_ = b; } /// are we in mathed? bool inMathed() const; @@ -154,10 +152,6 @@ public: // // text-specific part // - /// \sa boundary_ - bool boundary() const { return top().boundary(); } - /// \sa boundary_ - bool & boundary() { return top().boundary(); } /// the paragraph we're in Paragraph & paragraph(); /// the paragraph we're in @@ -209,21 +203,41 @@ public: /// output friend std::ostream & operator<<(std::ostream & os, DocIterator const & cur); + /// friend bool operator==(DocIterator const &, DocIterator const &); + /// friend class StableDocIterator; protected: + /// void clear() { slices_.clear(); } - void push_back(CursorSlice const & sl) { - slices_.push_back(sl); - } - void pop_back() { - slices_.pop_back(); - } + /// + void push_back(CursorSlice const & sl) { slices_.push_back(sl); } + /// + void pop_back() { slices_.pop_back(); } private: + /** + * When the cursor position is i, is the cursor after the i-th char + * or before the i+1-th char ? Normally, these two interpretations are + * equivalent, except when the fonts of the i-th and i+1-th char + * differ. + * We use boundary_ to distinguish between the two options: + * If boundary_=true, then the cursor is after the i-th char + * and if boundary_=false, then the cursor is before the i+1-th char. + * + * We currently use the boundary only when the language direction of + * the i-th char is different than the one of the i+1-th char. + * In this case it is important to distinguish between the two + * cursor interpretations, in order to give a reasonable behavior to + * the user. + */ + bool boundary_; + /// std::vector const & internalData() const { return slices_; } + /// std::vector slices_; + /// InsetBase * inset_; }; diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index c97ec15af5..d775917a5e 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -261,9 +261,9 @@ void InsetBase::markErased() {} -void InsetBase::getCursorPos(CursorSlice const &, int & x, int & y) const +void InsetBase::cursorPos(CursorSlice const &, bool, int & x, int & y) const { - lyxerr << "InsetBase::getCursorPos called directly" << std::endl; + lyxerr << "InsetBase::cursorPos called directly" << std::endl; x = 100; y = 100; } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 8ea7690410..b14fbd60d0 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -133,7 +133,8 @@ public: /// do we cover screen position x/y? virtual bool covers(int x, int y) const; /// get the screen positions of the cursor (see note in cursor.C) - virtual void getCursorPos(CursorSlice const & sl, int & x, int & y) const; + virtual void cursorPos(CursorSlice const & sl, bool boundary, + int & x, int & y) const; /// is this an inset that can be moved into? virtual bool isActive() const { return nargs() > 0; } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index acfb6d28f8..7967caec2a 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -192,24 +192,23 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const } -void InsetCollapsable::getCursorPos - (CursorSlice const & sl, int & x, int & y) const +void InsetCollapsable::cursorPos + (CursorSlice const & sl, bool boundary, int & x, int & y) const { if (status_ == Collapsed) { x = xo(); y = yo(); - return; + } else { + InsetText::cursorPos(sl, boundary, x, y); + if (status_ == Open) { + if (openinlined_) + x += dimensionCollapsed().wid; + else + y += dimensionCollapsed().height() - ascent() + + TEXT_TO_INSET_OFFSET + textdim_.asc; + } + x += TEXT_TO_INSET_OFFSET; } - - InsetText::getCursorPos(sl, x, y); - if (status_ == Open) { - if (openinlined_) - x += dimensionCollapsed().wid; - else - y += dimensionCollapsed().height() - ascent() + TEXT_TO_INSET_OFFSET + textdim_.asc; - } - - x += TEXT_TO_INSET_OFFSET; } @@ -239,7 +238,7 @@ string const InsetCollapsable::getNewLabel(string const & l) const pos_type const n = min(max_length, p_siz); pos_type i = 0; pos_type j = 0; - for( ; i < n && j < p_siz; ++j) { + for (; i < n && j < p_siz; ++j) { if (paragraphs().begin()->isInset(j)) continue; label += paragraphs().begin()->getChar(j); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 3024c486f9..ee90a458c2 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -47,7 +47,7 @@ public: /// void drawSelection(PainterInfo & pi, int x, int y) const; /// return x,y of given position relative to the inset's baseline - void getCursorPos(CursorSlice const & sl, int & x, int & y) const; + void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; /// bool hitButton(FuncRequest const &) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 36ea3c0ccc..a33a336fb3 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1084,9 +1084,10 @@ shared_ptr InsetTabular::cell(idx_type idx) } -void InsetTabular::getCursorPos(CursorSlice const & sl, int & x, int & y) const +void InsetTabular::cursorPos + (CursorSlice const & sl, bool boundary, int & x, int & y) const { - cell(sl.idx())->getCursorPos(sl, x, y); + cell(sl.idx())->cursorPos(sl, boundary, x, y); // y offset correction int const row = tabular.row_of_cell(sl.idx()); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 206f573f5d..53f974eec9 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -91,7 +91,7 @@ public: /// Code lyxCode() const { return InsetBase::TABULAR_CODE; } /// get offset of this cursor slice relative to our upper left corner - void getCursorPos(CursorSlice const & sl, int & x, int & y) const; + void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; /// bool tabularFeatures(LCursor & cur, std::string const & what); /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 0c17b80920..c01fc8cad1 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -364,10 +364,11 @@ void InsetText::validate(LaTeXFeatures & features) const } -void InsetText::getCursorPos(CursorSlice const & sl, int & x, int & y) const +void InsetText::cursorPos + (CursorSlice const & sl, bool boundary, int & x, int & y) const { - x = text_.cursorX(sl) + border_; - y = text_.cursorY(sl); + x = text_.cursorX(sl, boundary) + border_; + y = text_.cursorY(sl, boundary); } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index ed387ff0f2..c243b34809 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -74,7 +74,7 @@ public: void validate(LaTeXFeatures & features) const; /// return x,y of given position relative to the inset's baseline - void getCursorPos(CursorSlice const & sl, int & x, int & y) const; + void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; /// Code lyxCode() const { return TEXT_CODE; } /// diff --git a/src/lyxtext.h b/src/lyxtext.h index 882f340571..504366885d 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -322,9 +322,9 @@ public: /// int descent() const; /// - int cursorX(CursorSlice const & cursor) const; + int cursorX(CursorSlice const & cursor, bool boundary) const; /// - int cursorY(CursorSlice const & cursor) const; + int cursorY(CursorSlice const & cursor, bool boundary) const; /// friend class LyXScreen; diff --git a/src/mathed/math_mboxinset.C b/src/mathed/math_mboxinset.C index 9fcce755dd..bd3c93b54c 100644 --- a/src/mathed/math_mboxinset.C +++ b/src/mathed/math_mboxinset.C @@ -102,10 +102,11 @@ LyXText * MathMBoxInset::getText(int) const } -void MathMBoxInset::getCursorPos(CursorSlice const & sl, int & x, int & y) const +void MathMBoxInset::cursorPos + (CursorSlice const & sl, bool boundary, int & x, int & y) const { - x = text_.cursorX(sl); - y = text_.cursorY(sl); + x = text_.cursorX(sl, boundary); + y = text_.cursorY(sl, boundary); } diff --git a/src/mathed/math_mboxinset.h b/src/mathed/math_mboxinset.h index cf0a58873d..59f13be506 100644 --- a/src/mathed/math_mboxinset.h +++ b/src/mathed/math_mboxinset.h @@ -41,7 +41,7 @@ public: /// LyXText * getText(int) const; /// - void getCursorPos(CursorSlice const & sl, int & x, int & y) const; + void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; protected: virtual void doDispatch(LCursor & cur, FuncRequest & cmd); diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 5f83787f05..0253af32b0 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -88,7 +88,7 @@ MathArray const & MathNestInset::cell(idx_type i) const } -void MathNestInset::getCursorPos(CursorSlice const & sl, +void MathNestInset::cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const { // FIXME: This is a hack. Ideally, the coord cache should not store diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 46b6abe332..72bdcd4536 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -37,7 +37,7 @@ public: /// identifies NestInsets MathNestInset const * asNestInset() const { return this; } /// get cursor position - void getCursorPos(CursorSlice const & sl, int & x, int & y) const; + void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; /// void edit(LCursor & cur, bool left); /// diff --git a/src/text.C b/src/text.C index 61c3dd8500..d322ec48ba 100644 --- a/src/text.C +++ b/src/text.C @@ -1010,7 +1010,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row) if (bv_owner->text() == this) { if (pit == 0 && row.pos() == 0) maxasc += 20; - if (pit == pars_.size() - 1 && row.endpos() == par.size()) + if (pit + 1 == pars_.size() && row.endpos() == par.size()) maxdesc += 20; } @@ -1193,7 +1193,8 @@ void LyXText::insertChar(LCursor & cur, char c) current_font = rawtmpfont; real_current_font = realtmpfont; - setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary()); + //setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary()); + setCursor(cur, cur.pit(), cur.pos() + 1, false, true); charInserted(); } @@ -1793,7 +1794,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const x2 = 0; } else { y1 = bv_funcs::getPos(beg).y_ - row1.ascent(); - int const startx = cursorX(beg.top()); + int const startx = cursorX(beg.top(), begin.boundary()); x1 = isRTL(par1) ? startx : 0; x2 = isRTL(par1) ? 0 + dim_.wid : startx; } @@ -1805,7 +1806,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const X2 = 0; } else { y2 = bv_funcs::getPos(end).y_ + row2.descent(); - int const endx = cursorX(end.top()); + int const endx = cursorX(end.top(), end.boundary()); X1 = isRTL(par2) ? 0 : endx; X2 = isRTL(par2) ? endx : 0 + dim_.wid; } @@ -1868,9 +1869,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const x2 = dim_.wid; } else { Row const & row1 = par1.getRow(beg.pos()); - y1 = bv_funcs::getPos(beg).y_ - row1.ascent(); + y1 = bv_funcs::getPos(beg, beg.boundary()).y_ - row1.ascent(); y2 = y1 + row1.height(); - int const startx = cursorX(beg.top()); + int const startx = cursorX(beg.top(), beg.boundary()); x1 = !isRTL(par1) ? startx : 0; x2 = !isRTL(par1) ? 0 + dim_.wid : startx; } @@ -1883,9 +1884,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const X2 = dim_.wid; } else { Row const & row2 = par2.getRow(end.pos()); - Y1 = bv_funcs::getPos(end).y_ - row2.ascent(); + Y1 = bv_funcs::getPos(end, end.boundary()).y_ - row2.ascent(); Y2 = Y1 + row2.height(); - int const endx = cursorX(end.top()); + int const endx = cursorX(end.top(), end.boundary()); X1 = !isRTL(par2) ? 0 : endx; X2 = !isRTL(par2) ? endx : 0 + dim_.wid; } @@ -1910,6 +1911,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const Y1 - y2, LColor::selection); } + bool LyXText::isLastRow(pit_type pit, Row const & row) const { return row.endpos() >= pars_[pit].size() @@ -2045,16 +2047,20 @@ int LyXText::descent() const } -int LyXText::cursorX(CursorSlice const & cur) const +int LyXText::cursorX(CursorSlice const & sl, bool boundary) const { - pit_type const pit = cur.pit(); + pit_type const pit = sl.pit(); Paragraph const & par = pars_[pit]; if (par.rows().empty()) return 0; - Row const & row = par.getRow(cur.pos()); + pos_type pos = sl.pos(); + //// Correct position in front of big insets + //if (pos && boundary) + // --pos; + + Row const & row = par.getRow(pos); - pos_type pos = cur.pos(); pos_type cursor_vpos = 0; RowMetrics const m = computeRowMetrics(pit, row); @@ -2104,20 +2110,28 @@ int LyXText::cursorX(CursorSlice const & cur) const } else x += singleWidth(par, pos); } + + // see correction above + //if (pos && boundary) + // x += singleWidth(par, pos + 1); + return int(x); } -int LyXText::cursorY(CursorSlice const & cur) const +int LyXText::cursorY(CursorSlice const & sl, bool boundary) const { - Paragraph const & par = getPar(cur.pit()); + //lyxerr << "LyXText::cursorY: boundary: " << boundary << std::endl; + Paragraph const & par = getPar(sl.pit()); int h = 0; h -= pars_[0].rows()[0].ascent(); - for (pit_type pit = 0; pit < cur.pit(); ++pit) + for (pit_type pit = 0; pit < sl.pit(); ++pit) h += pars_[pit].height(); - for (size_t rit = 0, rend = par.pos2row(cur.pos()); rit != rend; ++rit) + //size_t const rend = par.pos2row(sl.pos() - boundary ? 1 : 0); + size_t const rend = par.pos2row(sl.pos()); + for (size_t rit = 0; rit != rend; ++rit) h += par.rows()[rit].height(); - h += par.rows()[par.pos2row(cur.pos())].ascent(); + h += par.rows()[rend].ascent(); return h; } @@ -2254,7 +2268,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const pos_type LyXText::x2pos(pit_type pit, int row, int x) const { - BOOST_ASSERT(row < pars_[pit].rows().size()); + BOOST_ASSERT(row < int(pars_[pit].rows().size())); bool bound = false; Row const & r = pars_[pit].rows()[row]; return r.pos() + getColumnNearX(pit, r, x, bound); diff --git a/src/text2.C b/src/text2.C index 75d4f4f875..8408af2041 100644 --- a/src/text2.C +++ b/src/text2.C @@ -660,6 +660,7 @@ bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos, { LCursor old = cur; setCursorIntern(cur, par, pos, setfont, boundary); + cur.boundary(boundary); return deleteEmptyParagraphMechanism(cur, old); } @@ -670,7 +671,6 @@ void LyXText::setCursor(CursorSlice & cur, pit_type par, BOOST_ASSERT(par != int(paragraphs().size())); cur.pit() = par; cur.pos() = pos; - cur.boundary() = boundary; // now some strict checking Paragraph & para = getPar(par); @@ -928,7 +928,7 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y) pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); cur.pit() = pit; cur.pos() = pos; - cur.boundary() = bound; + cur.boundary(bound); cur.x_target() = x; // try to descend into nested insets @@ -1022,7 +1022,7 @@ bool LyXText::cursorUp(LCursor & cur) int const x = cur.targetX(); if (!cur.selection()) { - int const y = bv_funcs::getPos(cur).y_; + int const y = bv_funcs::getPos(cur, cur.boundary()).y_; LCursor old = cur; editXY(cur, x, y - par.rows()[row].ascent() - 1); @@ -1061,7 +1061,7 @@ bool LyXText::cursorDown(LCursor & cur) int const x = cur.targetX(); if (!cur.selection()) { - int const y = bv_funcs::getPos(cur).y_; + int const y = bv_funcs::getPos(cur, cur.boundary()).y_; LCursor old = cur; editXY(cur, x, y + par.rows()[row].descent() + 1); diff --git a/src/text3.C b/src/text3.C index 35fc074caf..475712a46b 100644 --- a/src/text3.C +++ b/src/text3.C @@ -406,8 +406,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_RIGHT: case LFUN_RIGHTSEL: - lyxerr << BOOST_CURRENT_FUNCTION - << " LFUN_RIGHT[SEL]:\n" << cur << endl; + //lyxerr << BOOST_CURRENT_FUNCTION + // << " LFUN_RIGHT[SEL]:\n" << cur << endl; cur.selHandle(cmd.action == LFUN_RIGHTSEL); if (isRTL(cur.paragraph())) needsUpdate = cursorLeft(cur); @@ -819,8 +819,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; case LFUN_GETXY: - cur.message(convert(cursorX(cur.top())) + ' ' - + convert(cursorY(cur.top()))); + cur.message(convert(cursorX(cur.top(), cur.boundary())) + ' ' + + convert(cursorY(cur.top(), cur.boundary()))); break; case LFUN_SETXY: {