]> git.lyx.org Git - features.git/commitdiff
Fix the cursor position to be on the end of the row before an inset which
authorJürgen Vigna <jug@sad.it>
Thu, 11 Apr 2002 09:53:23 +0000 (09:53 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 11 Apr 2002 09:53:23 +0000 (09:53 +0000)
needs a full row (#44).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3966 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView2.C
src/BufferView_pimpl.C
src/ChangeLog
src/lyxcursor.C
src/lyxcursor.h
src/text.C
src/text2.C

index fa9456ea50788a105b496d7242557021762e5155..90f7e3e9fb4830a6960c99e99d628ad090ef2509 100644 (file)
@@ -572,7 +572,7 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
                        shape = (txt->real_current_font.isVisibleRightToLeft())
                                ? LyXScreen::REVERSED_L_SHAPE
                                : LyXScreen::L_SHAPE;
-               y += cursor.y() + theLockingInset()->insetInInsetY();
+               y += cursor.iy() + theLockingInset()->insetInInsetY();
                pimpl_->screen_->showManualCursor(text, x, y, asc, desc,
                                                  shape);
        }
@@ -590,7 +590,7 @@ void BufferView::hideLockedInsetCursor()
 bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 {
        if (theLockingInset() && available()) {
-               y += text->cursor.y() + theLockingInset()->insetInInsetY();
+               y += text->cursor.iy() + theLockingInset()->insetInInsetY();
                if (pimpl_->screen_->fitManualCursor(text, this, x, y, asc, desc)) {
                        updateScrollbar();
                        return true;
index cad89d3fdfa8eb378a486ab21bfb3e2765d858b1..1549d3338a442383a5c5999e7569b03284cf370c 100644 (file)
@@ -951,7 +951,7 @@ Inset * BufferView::Pimpl::checkInset(LyXText const & text,
 
        x -= b.x1;
        // The origin of an inset is on the baseline
-       y -= (text.cursor.y());
+       y -= text.cursor.iy();
 
        return inset;
 }
index 1a242e948a6596b7b2f842397470e036e3f29991..564ac4e52cc2a43d2b94e16104e8f9c4b0e27603 100644 (file)
@@ -1,3 +1,22 @@
+2002-04-11  Juergen Vigna  <jug@sad.it>
+
+       * BufferView2.C (showLockedInsetCursor): use iy
+       (fitLockedInsetCursor): ditto
+
+       * BufferView_pimpl.C (checkInset): use LyXCursor::iy for baseline of
+       locked insets as there we have the right value now.
+
+       * lyxcursor.C: added iy_ variable and iy functions to set to the
+       baseline of cursor-y of the locked inset.
+
+       * text2.C (setCursorFromCoordinates): set LyXCursor::iy.
+       (setCursor): fixed for insets which need a full row.
+
+       * text.C (rowLastPrintable): don't ignore the last space when before
+       an inset which needs a full row.
+       (numberOfSeparators): use rowLastPrintable and <= last to honor a space
+       as last character of a row when before a inset which needs a full row.
+
 2002-04-06  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * version.C.in: update date
index 76e43f76bad945de84b5c6b8206afbddcc638f63..4e02327fbc0b982a41bfb466522085f4ff7d39cd 100644 (file)
@@ -19,7 +19,7 @@
 
 LyXCursor::LyXCursor()
        : par_(0), pos_(0), boundary_(false),
-         x_(0), x_fix_(0), y_(0), row_(0)
+         x_(0), x_fix_(0), y_(0), iy_(0), row_(0)
 {}
 
 
@@ -94,6 +94,18 @@ int LyXCursor::y() const
 }
 
 
+void LyXCursor::iy(int i)
+{
+       iy_ = i;
+}
+
+
+int LyXCursor::iy() const
+{
+       return iy_;
+}
+
+
 void LyXCursor::row(Row * r)
 {
        row_ = r;
index c36812befd3ac70d82f49f08ab19a6df233d88ab..9c37d0dff992c13ddd47cadc725814327b615475 100644 (file)
@@ -52,6 +52,10 @@ public:
        ///
        int y() const;
        ///
+       void iy(int i);
+       ///
+       int iy() const;
+       ///
        void row(Row * r);
        ///
        Row * row() const;
@@ -68,6 +72,9 @@ private:
        int x_fix_;
        ///
        int y_;
+       /// the y position of the position before the inset when we put
+       /// the cursor on the end of the row before, otherwise equal to y.
+       int iy_;
        ///
        Row * row_;
 };
index 6898b18145d487bf9a5ae7c438508a9fc0fdc451..7bbca3dfeec05b024f4961df1bb939389768b95f 100644 (file)
@@ -254,10 +254,21 @@ pos_type LyXText::rowLast(Row const * row) const
 pos_type LyXText::rowLastPrintable(Row const * row) const
 {
        pos_type const last = rowLast(row);
+       bool ignore_the_space_on_the_last_position = true;
+       Inset * ins;
+       // we have to consider a space on the last position in this case!
+       if (row->next() && row->par() == row->next()->par() &&
+           row->next()->par()->getChar(last+1) == Paragraph::META_INSET &&
+           (ins=row->next()->par()->getInset(last+1)) &&
+           (ins->needFullRow() || ins->display()))
+       {
+               ignore_the_space_on_the_last_position = false;
+       }
        if (last >= row->pos()
            && row->next()
            && row->next()->par() == row->par()
-           && row->par()->isSeparator(last))
+           && row->par()->isSeparator(last)
+               && ignore_the_space_on_the_last_position)
                return last - 1;
        else
                return last;
@@ -1134,10 +1145,11 @@ int LyXText::labelFill(BufferView * bview, Row const * row) const
 // on the very last column doesnt count
 int LyXText::numberOfSeparators(Buffer const * buf, Row const * row) const
 {
-       pos_type const last = rowLast(row);
+       pos_type last = rowLastPrintable(row);
        pos_type p = max(row->pos(), beginningOfMainBody(buf, row->par()));
+               
        int n = 0;
-       for (; p < last; ++p) {
+       for (; p <= last; ++p) {
                if (row->par()->isSeparator(p)) {
                        ++n;
                }
index 6479cf7c15ff350f6be8b77e076a0dd9120c9d3a..5b6f639769b9522b6830c4c3c52399631c2884ce 100644 (file)
@@ -2061,20 +2061,23 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        cur.pos(pos);
        cur.boundary(boundary);
 
-#if 0
-       if (pos && par->getChar(pos) == Paragraph::META_INSET &&
-               par->getInset(pos)) {
-               Inset * ins = par->getInset(pos);
-               if (ins->needFullRow() || ins->display()) {
-                       --pos;
-                       boundary = true;
-               }
-       }
-#endif
-
        // get the cursor y position in text
        int y = 0;
        Row * row = getRow(par, pos, y);
+       Row * old_row = row;
+       // if we are before the first char of this row and are still in the
+       // same paragraph and there is a previous row then put the cursor on
+       // the end of the previous row
+       cur.iy(y + row->baseline());
+       Inset * ins;
+       if (pos && par->getChar(pos) == Paragraph::META_INSET &&
+               (ins=par->getInset(pos)) && (ins->needFullRow() || ins->display()))
+       {
+               row = row->previous();
+               y -= row->height();
+       }
+
+       cur.row(row);
        // y is now the beginning of the cursor row
        y += row->baseline();
        // y is now the cursor baseline
@@ -2088,7 +2091,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        prepareToPrint(bview, row, x, fill_separator, fill_hfill,
                       fill_label_hfill);
        pos_type cursor_vpos = 0;
-       pos_type last = rowLastPrintable(row);
+       pos_type last = rowLastPrintable(old_row);
 
        if (pos > last + 1) {
                // This shouldn't happen.
@@ -2149,7 +2152,6 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
 
        cur.x(int(x));
        cur.x_fix(cur.x());
-       cur.row(row);
 }
 
 
@@ -2247,6 +2249,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
        cur.pos(row->pos() + column);
        cur.x(x);
        cur.y(y + row->baseline());
+       cur.iy(cur.y());
        cur.row(row);
        cur.boundary(bound);
 }