]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
move some selection related stuff over to textcursor.C
[lyx.git] / src / text3.C
index d838a18b3892d70ad6d948e9425e58523b00193f..33284bc3e9248f8cf65d1ab26c871b9e5e4c7faf 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"
@@ -95,20 +96,20 @@ namespace {
                LyXCursor const & cur, int & x, int & y)
        {
                lyx::pos_type const pos = cur.pos();
-               Paragraph /*const*/ & par = *cur.par();
+               ParagraphList::iterator par = cur.par();
 
-               if (pos >= par.size() || !par.isInset(pos))
+               if (pos >= par->size() || !par->isInset(pos))
                        return 0;
 
-               Inset /*const*/ * inset = par.getInset(pos);
+               Inset /*const*/ * inset = par->getInset(pos);
 
                if (!isEditableInset(inset))
                        return 0;
 
                // get inset dimensions
-               lyx::Assert(par.getInset(pos));
+               lyx::Assert(par->getInset(pos));
 
-               LyXFont const & font = text.getFont(bv->buffer(), &par, pos);
+               LyXFont const & font = text.getFont(bv->buffer(), par, pos);
 
                int const width = inset->width(bv, font);
                int const inset_x = font.isVisibleRightToLeft()
@@ -128,7 +129,7 @@ namespace {
                        return 0;
                }
 
-               text.setCursor(&par, pos, true);
+               text.setCursor(par, pos, true);
 
                x -= b.x1;
                // The origin of an inset is on the baseline
@@ -242,7 +243,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 +252,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 +272,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 +298,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 +317,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 +337,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);
                }
@@ -381,7 +383,7 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
        if (inset) {
                bool gotsel = false;
                if (lt->selection.set()) {
-                       lt->cutSelection(true, false);
+                       bv->owner()->dispatch(FuncRequest(LFUN_CUT));
                        gotsel = true;
                }
                if (bv->insertInset(inset)) {
@@ -390,7 +392,7 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
                                inset->localDispatch(cmd);
                        }
                        if (gotsel && pastesel)
-                               bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
+                               bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
                }
                else
                        delete inset;
@@ -418,7 +420,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                for (; tmp != end; ++tmp) {
                        if (tmp->params().startOfAppendix()) {
-                               setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
+                               setUndo(bv, Undo::EDIT, tmp);
                                tmp->params().startOfAppendix(false);
                                int tmpy;
                                setHeightOfRow(getRow(tmp, 0, tmpy));
@@ -426,7 +428,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                }
 
-               setUndo(bv, Undo::EDIT, pit, boost::next(pit));
+               setUndo(bv, Undo::EDIT, pit);
                pit->params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
@@ -608,7 +610,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                    && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
                        Inset * tmpinset = cursor.par()->getInset(cursor.pos());
                        cmd.message(tmpinset->editMessage());
-                       FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
+                       FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
                        tmpinset->localDispatch(cmd1);
                        break;
                }
@@ -634,7 +636,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                    isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
                        Inset * tmpinset = cursor.par()->getInset(cursor.pos());
                        cmd.message(tmpinset->editMessage());
-                       FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
+                       FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
                        tmpinset->localDispatch(cmd1);
                        break;
                }
@@ -736,7 +738,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 +779,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                }
                update();
                break;
@@ -794,7 +796,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                        update();
                }
                bv->owner()->view_state_changed();
@@ -823,7 +825,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                } else {
                        update();
-                       cutSelection(bv, true);
+                       cutSelection(true, false);
                }
                update();
                break;
@@ -930,12 +932,12 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bv->switchKeyMap();
                break;
 
-       case LFUN_PROTECTEDSPACE:
+       case LFUN_SPACE_INSERT:
                if (cursor.par()->layout()->free_spacing) {
                        insertChar(' ');
                        update();
                } else {
-                       specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
+                       doInsertInset(this, cmd, false, false);
                }
                moveCursorUpdate(bv, false);
                break;
@@ -1020,21 +1022,29 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                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;
@@ -1124,6 +1134,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                bool change_layout = (current_layout != layout);
+
                if (!change_layout && selection.set() &&
                        selection.start.par() != selection.end.par())
                {
@@ -1137,6 +1148,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                ++spit;
                        }
                }
+
                if (change_layout) {
                        current_layout = layout;
                        update();
@@ -1299,7 +1311,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
@@ -1311,7 +1323,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)
@@ -1381,7 +1393,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();
 
@@ -1596,7 +1608,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_INDEX_PRINT:
-       case LFUN_PARENTINSERT:
        case LFUN_TOC_INSERT:
        case LFUN_HFILL:
                // do nothing fancy