]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Hotfix to move cursor to the right when pressing M-m g x in text mode.
[lyx.git] / src / text2.C
index 5b6f639769b9522b6830c4c3c52399631c2884ce..089965c9973152fe4fa658a803281bbb3c92baee 100644 (file)
@@ -1647,13 +1647,12 @@ void LyXText::insertInset(BufferView * bview, Inset * inset)
 {
        if (!cursor.par()->insetAllowed(inset->lyxCode()))
                return;
-       // I don't know if this is necessary here (Jug 20020102)
-       setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
+       setUndo(bview, Undo::FINISH, cursor.par(), cursor.par()->next());
+       freezeUndo();
        cursor.par()->insertInset(cursor.pos(), inset);
        // Just to rebreak and refresh correctly.
        // The character will not be inserted a second time
        insertChar(bview, Paragraph::META_INSET);
-#if 1
        // If we enter a highly editable inset the cursor should be to before
        // the inset. This couldn't happen before as Undo was not handled inside
        // inset now after the Undo LyX tries to call inset->Edit(...) again
@@ -1662,7 +1661,7 @@ void LyXText::insertInset(BufferView * bview, Inset * inset)
        if (isHighlyEditableInset(inset)) {
                cursorLeft(bview, true);
        }
-#endif
+       unFreezeUndo();
 }
 
 
@@ -2070,7 +2069,8 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        // the end of the previous row
        cur.iy(y + row->baseline());
        Inset * ins;
-       if (pos && par->getChar(pos) == Paragraph::META_INSET &&
+       if (row->previous() && pos &&
+               par->getChar(pos) == Paragraph::META_INSET &&
                (ins=par->getInset(pos)) && (ins->needFullRow() || ins->display()))
        {
                row = row->previous();
@@ -2083,14 +2083,6 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        // y is now the cursor baseline
        cur.y(y);
 
-       // now get the cursors x position
-       float x;
-       float fill_separator;
-       float fill_hfill;
-       float fill_label_hfill;
-       prepareToPrint(bview, row, x, fill_separator, fill_hfill,
-                      fill_label_hfill);
-       pos_type cursor_vpos = 0;
        pos_type last = rowLastPrintable(old_row);
 
        if (pos > last + 1) {
@@ -2102,6 +2094,30 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                cur.pos(pos);
        }
 
+       // now get the cursors x position
+       float x = getCursorX(bview, row, pos, last, boundary);
+       cur.x(int(x));
+       cur.x_fix(cur.x());
+       if (old_row != row) {
+               x = getCursorX(bview, old_row, pos, last, boundary);
+               cur.ix(int(x));
+       } else
+               cur.ix(cur.x());
+}
+
+
+float LyXText::getCursorX(BufferView * bview, Row * row,
+                                                 pos_type pos, pos_type last, bool boundary) const
+{
+       pos_type cursor_vpos = 0;
+       float x;
+       float fill_separator;
+       float fill_hfill;
+       float fill_label_hfill;
+       // This call HAS to be here because of the BidiTables!!!
+       prepareToPrint(bview, row, x, fill_separator, fill_hfill,
+                      fill_label_hfill);
+
        if (last < row->pos())
                cursor_vpos = row->pos();
        else if (pos > last && !boundary)
@@ -2125,7 +2141,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                main_body = 0;
 
        for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
-               pos = vis2log(vpos);
+               pos_type pos = vis2log(vpos);
                if (main_body > 0 && pos == main_body - 1) {
                        x += fill_label_hfill +
                                lyxfont::width(textclasslist[
@@ -2149,9 +2165,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                } else
                        x += singleWidth(bview, row->par(), pos);
        }
-
-       cur.x(int(x));
-       cur.x_fix(cur.x());
+       return x;
 }
 
 
@@ -2248,8 +2262,18 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
        cur.par(row->par());
        cur.pos(row->pos() + column);
        cur.x(x);
+       cur.ix(x);
        cur.y(y + row->baseline());
-       cur.iy(cur.y());
+       Inset * ins;
+       if (row->next() && cur.pos() &&
+               cur.par()->getChar(cur.pos()) == Paragraph::META_INSET &&
+               (ins=cur.par()->getInset(cur.pos())) &&
+               (ins->needFullRow() || ins->display()))
+       {
+               cur.iy(y + row->height() + row->next()->baseline());
+       } else {
+               cur.iy(cur.y());
+       }
        cur.row(row);
        cur.boundary(bound);
 }