]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
last Friday's text*.C -> text_func shuffle
[lyx.git] / src / text3.C
index 50f3498dc49e5a73592b536660366df5c47d4b26..e4cf6deba6a67e1d2589d245a2137706ec1c43a5 100644 (file)
@@ -27,6 +27,7 @@
 #include "box.h"
 #include "language.h"
 #include "support/tostr.h"
+#include "support/lstrings.h"
 #include "frontends/LyXView.h"
 #include "frontends/screen.h"
 #include "frontends/Dialogs.h"
@@ -42,6 +43,8 @@
 #include <ctime>
 #include <clocale>
 
+using namespace lyx::support;
+
 using std::endl;
 using std::find;
 using std::vector;
@@ -106,7 +109,7 @@ namespace {
                        return 0;
 
                // get inset dimensions
-               lyx::Assert(par->getInset(pos));
+               Assert(par->getInset(pos));
 
                LyXFont const & font = text.getFont(bv->buffer(), par, pos);
 
@@ -242,7 +245,7 @@ void LyXText::cursorPrevious()
 {
        int y = top_y();
 
-       if (cursor.row() == rows().begin()) {
+       if (cursorRow() == rows().begin()) {
                if (y > 0) {
                        int new_y = bv()->text->top_y() - bv()->workHeight();
                        bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
@@ -251,13 +254,13 @@ void LyXText::cursorPrevious()
                return;
        }
 
-       RowList::iterator cursorrow = cursor.row();
+       RowList::iterator cursorrow = cursorRow();
 
        setCursorFromCoordinates(cursor.x_fix(), y);
        finishUndo();
 
        int new_y;
-       if (cursorrow == bv()->text->cursor.row()) {
+       if (cursorrow == bv()->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
                cursorUp(true);
@@ -271,20 +274,20 @@ void LyXText::cursorPrevious()
                if (inset_owner) {
                        new_y = bv()->text->cursor.iy()
                                + bv()->theLockingInset()->insetInInsetY() + y
-                               + cursor.row()->height()
+                               + cursorRow()->height()
                                - bv()->workHeight() + 1;
                } else {
                        new_y = cursor.y()
-                               - cursor.row()->baseline()
-                               + cursor.row()->height()
+                               - cursorRow()->baseline()
+                               + cursorRow()->height()
                                - bv()->workHeight() + 1;
                }
        }
        bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
-       if (cursor.row() != rows().begin()) {
+       if (cursorRow() != rows().begin()) {
                LyXCursor cur;
-               setCursor(cur, boost::prior(cursor.row())->par(),
-                         boost::prior(cursor.row())->pos(), false);
+               setCursor(cur, boost::prior(cursorRow())->par(),
+                         boost::prior(cursorRow())->pos(), false);
                if (cur.y() > top_y()) {
                        cursorUp(true);
                }
@@ -297,9 +300,9 @@ void LyXText::cursorNext()
 {
        int topy = top_y();
 
-       if (boost::next(cursor.row()) == rows().end()) {
-               int y = cursor.y() - cursor.row()->baseline() +
-                       cursor.row()->height();
+       if (boost::next(cursorRow()) == rows().end()) {
+               int y = cursor.y() - cursorRow()->baseline() +
+                       cursorRow()->height();
                if (y > topy + bv()->workHeight()) {
                        bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
                        bv()->updateScrollbar();
@@ -316,13 +319,13 @@ void LyXText::cursorNext()
 
        getRowNearY(y);
 
-       RowList::iterator cursorrow = cursor.row();
+       RowList::iterator cursorrow = cursorRow();
        setCursorFromCoordinates(cursor.x_fix(), y);
        // + bv->workHeight());
        finishUndo();
 
        int new_y;
-       if (cursorrow == bv()->text->cursor.row()) {
+       if (cursorrow == bv()->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
                cursorDown(true);
@@ -336,16 +339,17 @@ void LyXText::cursorNext()
                if (inset_owner) {
                        new_y = bv()->text->cursor.iy()
                                + bv()->theLockingInset()->insetInInsetY()
-                               + y - cursor.row()->baseline();
+                               + y - cursorRow()->baseline();
                } else {
-                       new_y =  cursor.y() - cursor.row()->baseline();
+                       new_y =  cursor.y() - cursorRow()->baseline();
                }
        }
        bv()->screen().draw(bv()->text, bv(), new_y);
-       if (boost::next(cursor.row()) != rows().end()) {
+
+       RowList::iterator next_row = boost::next(cursorRow());
+       if (next_row != rows().end()) {
                LyXCursor cur;
-               setCursor(cur, boost::next(cursor.row())->par(),
-                         boost::next(cursor.row())->pos(), false);
+               setCursor(cur, next_row->par(), next_row->pos(), false);
                if (cur.y() < top_y() + bv()->workHeight()) {
                        cursorDown(true);
                }
@@ -586,9 +590,9 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_WORDSEL: {
                update();
-               LyXCursor cur1;
+               LyXCursor cur1 = cursor;
                LyXCursor cur2;
-               getWord(cur1, cur2, WHOLE_WORD);
+               ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
                setCursor(cur1.par(), cur1.pos());
                bv->beforeChange(this);
                setCursor(cur2.par(), cur2.pos());
@@ -736,7 +740,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // just comment out the line below...
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                        update();
                }
                moveCursorUpdate(bv, false);
@@ -777,7 +781,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                }
                update();
                break;
@@ -794,7 +798,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                        update();
                }
                bv->owner()->view_state_changed();
@@ -823,7 +827,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                }
                update();
                break;
@@ -918,7 +922,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_INSET_SETTINGS:
-               lyx::Assert(bv->theLockingInset());
+               Assert(bv->theLockingInset());
                bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
                break;
 
@@ -1014,27 +1018,37 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_TRANSPOSE_CHARS:
                update();
-               transposeChars(*this, cursor);
+               setUndo(bv, Undo::FINISH, cursor.par());
+               if (transposeChars(cursor))
+                       checkParagraph(cursor.par(), cursor.pos());
                if (inset_owner)
                        bv->updateInset(inset_owner);
                update();
                break;
 
-       case LFUN_PASTE:
+       case LFUN_PASTE: {
                cmd.message(_("Paste"));
                // clear the selection
                bv->toggleSelection();
                clearSelection();
                update();
-               pasteSelection();
+               size_t sel_index = 0;
+               string const & arg = cmd.argument;
+               if (isStrUnsignedInt(arg)) {
+                       size_t const paste_arg = strToUnsignedInt(arg);
+#warning FIXME Check if the arg is in the domain of available selections.
+                       sel_index = paste_arg;
+               }
+               pasteSelection(sel_index);
                clearSelection(); // bug 393
                update();
                bv->switchKeyMap();
                break;
+       }
 
        case LFUN_CUT:
                update();
-               cutSelection(bv, true);
+               cutSelection(true, true);
                update();
                cmd.message(_("Cut"));
                break;
@@ -1256,10 +1270,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
                                bv->screen().toggleSelection(this, bv);
-                               selectWord(LyXText::WHOLE_WORD_STRICT);
+                               selectWord(lyx::WHOLE_WORD_STRICT);
                                bv->screen().toggleSelection(this, bv, false);
                        } else {
-                               selectWord(LyXText::WHOLE_WORD_STRICT);
+                               selectWord(lyx::WHOLE_WORD_STRICT);
                        }
                        update();
                        bv->haveSelection(selection.set());
@@ -1301,7 +1315,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               RowList::iterator cursorrow = bv->text->cursor.row();
+               RowList::iterator cursorrow = bv->text->cursorRow();
                bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
        #if 0
                // sorry for this but I have a strange error that the y value jumps at
@@ -1313,7 +1327,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                               << bv->text->cursor.y() << endl;
        #endif
                // This is to allow jumping over large insets
-               if (cursorrow == bv->text->cursor.row()) {
+               if (cursorrow == bv->text->cursorRow()) {
                        if (cmd.y >= bv->workHeight())
                                bv->text->cursorDown(false);
                        else if (cmd.y < 0)
@@ -1383,7 +1397,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                // Clear the selection
                bv->screen().toggleSelection(bv->text, bv);
                bv->text->clearSelection();
-               bv->text->fullRebreak();
+               bv->text->partialRebreak();
                bv->update();
                bv->updateScrollbar();