]> 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 8521110de97637f0fe882d5b5ba03982532104d6..33284bc3e9248f8cf65d1ab26c871b9e5e4c7faf 100644 (file)
@@ -16,6 +16,7 @@
 #include "BufferView.h"
 #include "funcrequest.h"
 #include "lyxrc.h"
+#include "Lsstream.h"
 #include "debug.h"
 #include "bufferparams.h"
 #include "buffer.h"
@@ -25,6 +26,7 @@
 #include "intl.h"
 #include "box.h"
 #include "language.h"
+#include "support/tostr.h"
 #include "support/lstrings.h"
 #include "frontends/LyXView.h"
 #include "frontends/screen.h"
@@ -35,6 +37,8 @@
 #include "insets/insetcommand.h"
 #include "insets/insetnewline.h"
 #include "undo_funcs.h"
+#include "text_funcs.h"
+#include "Lsstream.h"
 
 #include <ctime>
 #include <clocale>
@@ -42,6 +46,7 @@
 using std::endl;
 using std::find;
 using std::vector;
+using lyx::pos_type;
 
 extern string current_layout;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
@@ -60,20 +65,14 @@ namespace {
                if (selecting || lt->selection.mark()) {
                        lt->setSelection();
                        if (lt->isInInset())
-                               bv->updateInset(lt->inset_owner, false);
+                               bv->updateInset(lt->inset_owner);
                        else
                                bv->toggleToggle();
                }
                if (!lt->isInInset()) {
-                       //if (fitcur)
-                       //      bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
-                       //else
-                       bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
-                       bv->showCursor();
-               } else if (bv->text->status() != LyXText::UNCHANGED) {
-                       bv->theLockingInset()->hideInsetCursor(bv);
-                       bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
-                       bv->showCursor();
+                       bv->update(lt, BufferView::SELECT);
+               } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
+                       bv->update(BufferView::SELECT);
                }
 
                if (!lt->selection.set())
@@ -97,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()
@@ -130,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
@@ -172,28 +171,29 @@ Inset * LyXText::checkInsetHit(int & x, int & y)
 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
                            string const & contents)
 {
-       LyXCursor res = cursor;
+       ParagraphList::iterator end = ownerParagraphs().end();
+       ParagraphList::iterator pit = cursor.par();
+       pos_type pos = cursor.pos();
+
        Inset * inset;
        do {
-               if (res.pos() < res.par()->size() - 1) {
-                       res.pos(res.pos() + 1);
+               if (pos + 1 < pit->size()) {
+                       ++pos;
                } else  {
-                       res.par(res.par()->next());
-                       res.pos(0);
+                       ++pit;
+                       pos = 0;
                }
 
-       } while (res.par() &&
-                !(res.par()->isInset(res.pos())
-                  && (inset = res.par()->getInset(res.pos())) != 0
-                  && find(codes.begin(), codes.end(), inset->lyxCode())
-                  != codes.end()
-                  && (contents.empty() ||
-                      static_cast<InsetCommand *>(
-                                                       res.par()->getInset(res.pos()))->getContents()
-                      == contents)));
-
-       if (res.par()) {
-               setCursor(res.par(), res.pos(), false);
+       } while (pit != end &&
+                !(pit->isInset(pos) &&
+                  (inset = pit->getInset(pos)) != 0 &&
+                  find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
+                  (contents.empty() ||
+                   static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
+                   == contents)));
+
+       if (pit != end) {
+               setCursor(pit, pos, false);
                return true;
        }
        return false;
@@ -201,14 +201,14 @@ bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
 
 
 void LyXText::gotoInset(vector<Inset::Code> const & codes,
-                                 bool same_content)
+                       bool same_content)
 {
-       bv()->hideCursor();
        bv()->beforeChange(this);
-       update(false);
+       update();
 
        string contents;
-       if (same_content && cursor.par()->isInset(cursor.pos())) {
+       if (same_content && cursor.pos() < cursor.par()->size()
+           && cursor.par()->isInset(cursor.pos())) {
                Inset const * inset = cursor.par()->getInset(cursor.pos());
                if (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
@@ -216,9 +216,9 @@ void LyXText::gotoInset(vector<Inset::Code> const & codes,
        }
 
        if (!gotoNextInset(codes, contents)) {
-               if (cursor.pos() || cursor.par() != ownerParagraph()) {
+               if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
                        LyXCursor tmp = cursor;
-                       cursor.par(ownerParagraph());
+                       cursor.par(ownerParagraphs().begin());
                        cursor.pos(0);
                        if (!gotoNextInset(codes, contents)) {
                                cursor = tmp;
@@ -228,7 +228,7 @@ void LyXText::gotoInset(vector<Inset::Code> const & codes,
                        bv()->owner()->message(_("No more insets"));
                }
        }
-       update(false);
+       update();
        selection.cursor = cursor;
 }
 
@@ -241,8 +241,10 @@ void LyXText::gotoInset(Inset::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-       if (!cursor.row()->previous()) {
-               if (top_y() > 0) {
+       int y = top_y();
+
+       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);
                        bv()->updateScrollbar();
@@ -250,14 +252,13 @@ void LyXText::cursorPrevious()
                return;
        }
 
-       int y = top_y();
-       Row * 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()->previous()) {
+       if (cursorRow() != rows().begin()) {
                LyXCursor cur;
-               setCursor(cur, cursor.row()->previous()->par(),
-                         cursor.row()->previous()->pos(), false);
+               setCursor(cur, boost::prior(cursorRow())->par(),
+                         boost::prior(cursorRow())->pos(), false);
                if (cur.y() > top_y()) {
                        cursorUp(true);
                }
@@ -295,18 +296,20 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       if (!cursor.row()->next()) {
-               int y = cursor.y() - cursor.row()->baseline() +
-                       cursor.row()->height();
-               if (y > top_y() + bv()->workHeight()) {
+       int topy = top_y();
+
+       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();
                }
                return;
        }
 
-       int y = top_y() + bv()->workHeight();
-       if (inset_owner && !top_y()) {
+       int y = topy + bv()->workHeight();
+       if (inset_owner && !topy) {
                y -= (bv()->text->cursor.iy()
                          - bv()->text->top_y()
                          + bv()->theLockingInset()->insetInInsetY());
@@ -314,13 +317,13 @@ void LyXText::cursorNext()
 
        getRowNearY(y);
 
-       Row * 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);
@@ -334,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 (cursor.row()->next()) {
+
+       RowList::iterator next_row = boost::next(cursorRow());
+       if (next_row != rows().end()) {
                LyXCursor cur;
-               setCursor(cur, cursor.row()->next()->par(),
-                                               cursor.row()->next()->pos(), false);
+               setCursor(cur, next_row->par(), next_row->pos(), false);
                if (cur.y() < top_y() + bv()->workHeight()) {
                        cursorDown(true);
                }
@@ -352,26 +356,21 @@ void LyXText::cursorNext()
 }
 
 
-void LyXText::update(bool changed)
+void LyXText::update()
 {
-       BufferView::UpdateCodes c = BufferView::SELECT | BufferView::FITCUR;
-       if (changed)
-               bv()->update(this, c | BufferView::CHANGE);
-       else
-               bv()->update(this, c);
+       bv()->update(this, BufferView::SELECT);
 }
 
 namespace {
 
 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 {
-       bv->hideCursor();
-       lt->update(bv);
+       lt->update();
        InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
        if (!bv->insertInset(new_inset))
                delete new_inset;
        else
-               bv->updateInset(new_inset, true);
+               bv->updateInset(new_inset);
 }
 
 
@@ -384,14 +383,16 @@ 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)) {
-                       if (edit)
-                               inset->edit(bv);
+                       if (edit) {
+                               FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
+                               inset->localDispatch(cmd);
+                       }
                        if (gotsel && pastesel)
-                               bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
+                               bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
                }
                else
                        delete inset;
@@ -410,14 +411,16 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        switch (cmd.action) {
 
        case LFUN_APPENDIX: {
-               Paragraph * par = cursor.par();
-               bool start = !par->params().startOfAppendix();
+               ParagraphList::iterator pit = cursor.par();
+               bool start = !pit->params().startOfAppendix();
 
                // ensure that we have only one start_of_appendix in this document
-               Paragraph * tmp = ownerParagraph();
-               for (; tmp; tmp = tmp->next()) {
+               ParagraphList::iterator tmp = ownerParagraphs().begin();
+               ParagraphList::iterator end = ownerParagraphs().end();
+
+               for (; tmp != end; ++tmp) {
                        if (tmp->params().startOfAppendix()) {
-                               setUndo(bv, Undo::EDIT, tmp, tmp->next());
+                               setUndo(bv, Undo::EDIT, tmp);
                                tmp->params().startOfAppendix(false);
                                int tmpy;
                                setHeightOfRow(getRow(tmp, 0, tmpy));
@@ -425,55 +428,46 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                }
 
-               setUndo(bv, Undo::EDIT, par, par->next());
-               par->params().startOfAppendix(start);
+               setUndo(bv, Undo::EDIT, pit);
+               pit->params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
                updateCounters();
                redoHeightOfParagraph();
                postPaint(0);
                setCursor(cursor.par(), cursor.pos());
-               update(bv);
+               update();
                break;
        }
 
        case LFUN_DELETE_WORD_FORWARD:
                bv->beforeChange(this);
-               update(false);
+               update();
                deleteWordForward();
-               update(bv);
+               update();
                finishChange(bv);
                break;
 
        case LFUN_DELETE_WORD_BACKWARD:
                bv->beforeChange(this);
-               update(false);
+               update();
                deleteWordBackward();
-               update(true);
+               update();
                finishChange(bv);
                break;
 
        case LFUN_DELETE_LINE_FORWARD:
                bv->beforeChange(this);
-               update(false);
+               update();
                deleteLineForward();
                update();
                finishChange(bv);
                break;
 
-       case LFUN_SHIFT_TAB:
-       case LFUN_TAB:
-               if (!selection.mark())
-                       bv->beforeChange(this);
-               update(false);
-               cursorTab();
-               finishChange(bv);
-               break;
-
        case LFUN_WORDRIGHT:
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(false);
+               update();
                if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
                        cursorLeftOneWord();
                else
@@ -484,7 +478,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDLEFT:
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(false);
+               update();
                if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
                        cursorRightOneWord();
                else
@@ -495,7 +489,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_BEGINNINGBUF:
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(false);
+               update();
                cursorTop();
                finishChange(bv);
                break;
@@ -503,13 +497,13 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_ENDBUF:
                if (selection.mark())
                        bv->beforeChange(this);
-               update(false);
+               update();
                cursorBottom();
                finishChange(bv);
                break;
 
        case LFUN_RIGHTSEL:
-               update(false);
+               update();
                if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
                        cursorLeft(bv);
                else
@@ -518,7 +512,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_LEFTSEL:
-               update(false);
+               update();
                if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
                        cursorRight(bv);
                else
@@ -527,55 +521,55 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_UPSEL:
-               update(false);
+               update();
                cursorUp(true);
                finishChange(bv, true);
                break;
 
        case LFUN_DOWNSEL:
-               update(false);
+               update();
                cursorDown(true);
                finishChange(bv, true);
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
-               update(false);
+               update();
                cursorUpParagraph();
                finishChange(bv, true);
                break;
 
        case LFUN_DOWN_PARAGRAPHSEL:
-               update(false);
+               update();
                cursorDownParagraph();
                finishChange(bv, true);
                break;
 
        case LFUN_PRIORSEL:
-               update(false);
+               update();
                cursorPrevious();
                finishChange(bv, true);
                break;
 
        case LFUN_NEXTSEL:
-               update(false);
+               update();
                cursorNext();
                finishChange(bv, true);
                break;
 
        case LFUN_HOMESEL:
-               update(false);
+               update();
                cursorHome();
                finishChange(bv, true);
                break;
 
        case LFUN_ENDSEL:
-               update(false);
+               update();
                cursorEnd();
                finishChange(bv, true);
                break;
 
        case LFUN_WORDRIGHTSEL:
-               update(false);
+               update();
                if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
                        cursorLeftOneWord();
                else
@@ -584,7 +578,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_WORDLEFTSEL:
-               update(false);
+               update();
                if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
                        cursorRightOneWord();
                else
@@ -593,7 +587,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_WORDSEL: {
-               update(false);
+               update();
                LyXCursor cur1;
                LyXCursor cur2;
                getWord(cur1, cur2, WHOLE_WORD);
@@ -608,7 +602,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(false);
+               update();
                if (is_rtl)
                        cursorLeft(false);
                if (cursor.pos() < cursor.par()->size()
@@ -616,7 +610,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                    && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
                        Inset * tmpinset = cursor.par()->getInset(cursor.pos());
                        cmd.message(tmpinset->editMessage());
-                       tmpinset->edit(bv, !is_rtl);
+                       FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
+                       tmpinset->localDispatch(cmd1);
                        break;
                }
                if (!is_rtl)
@@ -631,7 +626,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(false);
+               update();
                LyXCursor const cur = cursor;
                if (!is_rtl)
                        cursorLeft(false);
@@ -641,7 +636,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                    isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
                        Inset * tmpinset = cursor.par()->getInset(cursor.pos());
                        cmd.message(tmpinset->editMessage());
-                       tmpinset->edit(bv, is_rtl);
+                       FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
+                       tmpinset->localDispatch(cmd1);
                        break;
                }
                if (is_rtl)
@@ -705,7 +701,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_HOME:
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(bv);
+               update();
                cursorHome();
                finishChange(bv, false);
                break;
@@ -713,7 +709,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_END:
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(bv);
+               update();
                cursorEnd();
                finishChange(bv, false);
                break;
@@ -727,7 +723,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                bv->beforeChange(this);
                insertInset(new InsetNewline);
-               update(true);
+               update();
                setCursor(cursor.par(), cursor.pos());
                moveCursorUpdate(bv, false);
                break;
@@ -737,14 +733,13 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!selection.set()) {
                        Delete();
                        selection.cursor = cursor;
-                       update(bv);
+                       update();
                        // It is possible to make it a lot faster still
                        // just comment out the line below...
-                       bv->showCursor();
                } else {
-                       update(false);
-                       cutSelection(bv, true);
-                       update(bv);
+                       update();
+                       cutSelection(true, false);
+                       update();
                }
                moveCursorUpdate(bv, false);
                bv->owner()->view_state_changed();
@@ -772,7 +767,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                                 cur.par()->params().align(),
                                                 cur.par()->params().labelWidthString(), 0);
                                        cursorLeft(bv);
-                                       update(bv);
+                                       update();
                                } else {
                                        cursorLeft(bv);
                                        Delete();
@@ -783,10 +778,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                selection.cursor = cursor;
                        }
                } else {
-                       update(false);
-                       cutSelection(bv, true);
+                       update();
+                       cutSelection(true, false);
                }
-               update(bv);
+               update();
                break;
 
 
@@ -795,15 +790,14 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        if (bv->owner()->getIntl().getTransManager().backspace()) {
                                backspace();
                                selection.cursor = cursor;
-                               update(bv);
+                               update();
                                // It is possible to make it a lot faster still
                                // just comment out the line below...
-                               bv->showCursor();
                        }
                } else {
-                       update(false);
-                       cutSelection(bv, true);
-                       update(bv);
+                       update();
+                       cutSelection(true, false);
+                       update();
                }
                bv->owner()->view_state_changed();
                bv->switchKeyMap();
@@ -830,16 +824,16 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                selection.cursor = cur;
                        }
                } else {
-                       update(false);
-                       cutSelection(bv, true);
+                       update();
+                       cutSelection(true, false);
                }
-               update(bv);
+               update();
                break;
 
        case LFUN_BREAKPARAGRAPH:
                bv->beforeChange(this);
                breakParagraph(bv->buffer()->paragraphs, 0);
-               update(bv);
+               update();
                selection.cursor = cursor;
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
@@ -848,7 +842,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
                bv->beforeChange(this);
                breakParagraph(bv->buffer()->paragraphs, 1);
-               update(bv);
+               update();
                selection.cursor = cursor;
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
@@ -871,14 +865,12 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                         cur.par()->params().spacing(),
                                         cur.par()->params().align(),
                                         cur.par()->params().labelWidthString(), 1);
-                               //update(bv);
                        }
                }
                else {
                        breakParagraph(bv->buffer()->paragraphs, 0);
-                       //update(bv);
                }
-               update(bv);
+               update();
                selection.cursor = cur;
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
@@ -886,13 +878,13 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_PARAGRAPH_SPACING: {
-               Paragraph * par = cursor.par();
-               Spacing::Space cur_spacing = par->params().spacing().getSpace();
+               ParagraphList::iterator pit = cursor.par();
+               Spacing::Space cur_spacing = pit->params().spacing().getSpace();
                float cur_value = 1.0;
                if (cur_spacing == Spacing::Other)
-                       cur_value = par->params().spacing().getValue();
+                       cur_value = pit->params().spacing().getValue();
 
-               istringstream is(cmd.argument.c_str());
+               istringstream is(STRCONV(cmd.argument));
                string tmp;
                is >> tmp;
                Spacing::Space new_spacing = cur_spacing;
@@ -920,28 +912,32 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                               << cmd.argument << endl;
                }
                if (cur_spacing != new_spacing || cur_value != new_value) {
-                       par->params().spacing(Spacing(new_spacing, new_value));
+                       pit->params().spacing(Spacing(new_spacing, new_value));
                        redoParagraph();
-                       update(bv);
+                       update();
                }
                break;
        }
 
+       case LFUN_INSET_SETTINGS:
+               lyx::Assert(bv->theLockingInset());
+               bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
+               break;
+
        case LFUN_INSET_TOGGLE:
-               bv->hideCursor();
                bv->beforeChange(this);
-               update(false);
+               update();
                toggleInset();
-               update(false);
+               update();
                bv->switchKeyMap();
                break;
 
-       case LFUN_PROTECTEDSPACE:
+       case LFUN_SPACE_INSERT:
                if (cursor.par()->layout()->free_spacing) {
                        insertChar(' ');
-                       update(bv);
+                       update();
                } else {
-                       specialChar(this, bv, InsetSpecialChar::PROTECTED_SEPARATOR);
+                       doInsertInset(this, cmd, false, false);
                }
                moveCursorUpdate(bv, false);
                break;
@@ -968,7 +964,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_MARK_OFF:
                bv->beforeChange(this);
-               update(false);
+               update();
                selection.cursor = cursor;
                cmd.message(N_("Mark off"));
                break;
@@ -976,7 +972,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_MARK_ON:
                bv->beforeChange(this);
                selection.mark(true);
-               update(false);
+               update();
                selection.cursor = cursor;
                cmd.message(N_("Mark on"));
                break;
@@ -984,67 +980,72 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_SETMARK:
                bv->beforeChange(this);
                if (selection.mark()) {
-                       update(bv);
+                       update();
                        cmd.message(N_("Mark removed"));
                } else {
                        selection.mark(true);
-                       update(bv);
+                       update();
                        cmd.message(N_("Mark set"));
                }
                selection.cursor = cursor;
                break;
 
        case LFUN_UPCASE_WORD:
-               update(false);
+               update();
                changeCase(LyXText::text_uppercase);
                if (inset_owner)
-                       bv->updateInset(inset_owner, true);
-               update(bv);
+                       bv->updateInset(inset_owner);
+               update();
                break;
 
        case LFUN_LOWCASE_WORD:
-               update(false);
+               update();
                changeCase(LyXText::text_lowercase);
                if (inset_owner)
-                       bv->updateInset(inset_owner, true);
+                       bv->updateInset(inset_owner);
                update();
                break;
 
        case LFUN_CAPITALIZE_WORD:
-               update(false);
+               update();
                changeCase(LyXText::text_capitalization);
                if (inset_owner)
-                       bv->updateInset(inset_owner, true);
-               update(bv);
+                       bv->updateInset(inset_owner);
+               update();
                break;
 
        case LFUN_TRANSPOSE_CHARS:
-               update(false);
-               transposeChars();
+               update();
+               transposeChars(*this, cursor);
                if (inset_owner)
-                       bv->updateInset(inset_owner, true);
-               update(bv);
+                       bv->updateInset(inset_owner);
+               update();
                break;
 
-       case LFUN_PASTE:
+       case LFUN_PASTE: {
                cmd.message(_("Paste"));
-               bv->hideCursor();
                // clear the selection
                bv->toggleSelection();
                clearSelection();
-               update(false);
-               pasteSelection();
+               update();
+               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(false);
-               update(bv);
+               update();
                bv->switchKeyMap();
                break;
+       }
 
        case LFUN_CUT:
-               bv->hideCursor();
-               update(false);
-               cutSelection(bv, true);
-               update(bv);
+               update();
+               cutSelection(true, true);
+               update();
                cmd.message(_("Cut"));
                break;
 
@@ -1056,7 +1057,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_BEGINNINGBUFSEL:
                if (inset_owner)
                        return UNDISPATCHED;
-               update(false);
+               update();
                cursorTop();
                finishChange(bv, true);
                break;
@@ -1064,7 +1065,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_ENDBUFSEL:
                if (inset_owner)
                        return UNDISPATCHED;
-               update(false);
+               update();
                cursorBottom();
                finishChange(bv, true);
                break;
@@ -1076,7 +1077,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_SETXY: {
                int x = 0;
                int y = 0;
-               istringstream is(cmd.argument.c_str());
+               istringstream is(STRCONV(cmd.argument));
                is >> x >> y;
                if (!is)
                        lyxerr << "SETXY: Could not parse coordinates in '"
@@ -1133,26 +1134,27 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                bool change_layout = (current_layout != layout);
+
                if (!change_layout && selection.set() &&
                        selection.start.par() != selection.end.par())
                {
-                       Paragraph * spar = selection.start.par();
-                       Paragraph * epar = selection.end.par()->next();
-                       while (spar != epar) {
-                               if (spar->layout()->name() != current_layout) {
+                       ParagraphList::iterator spit = selection.start.par();
+                       ParagraphList::iterator epit = boost::next(selection.end.par());
+                       while (spit != epit) {
+                               if (spit->layout()->name() != current_layout) {
                                        change_layout = true;
                                        break;
                                }
-                               spar = spar->next();
+                               ++spit;
                        }
                }
+
                if (change_layout) {
-                       bv->hideCursor();
                        current_layout = layout;
-                       update(false);
+                       update();
                        setLayout(layout);
                        bv->owner()->setLayout(layout);
-                       update(bv);
+                       update();
                        bv->switchKeyMap();
                }
                break;
@@ -1161,7 +1163,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_PASTESELECTION: {
                if (!bv->buffer())
                        break;
-               bv->hideCursor();
                // this was originally a beforeChange(bv->text), i.e
                // the outermost LyXText!
                bv->beforeChange(this);
@@ -1172,7 +1173,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        else
                                insertStringAsLines(clip);
                        clearSelection();
-                       update(bv);
+                       update();
                }
                break;
        }
@@ -1195,21 +1196,20 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_QUOTE: {
-               Paragraph const * par = cursor.par();
+               ParagraphList::iterator pit = cursor.par();
                lyx::pos_type pos = cursor.pos();
                char c;
                if (!pos)
                        c = ' ';
-               else if (par->isInset(pos - 1) && par->getInset(pos - 1)->isSpace())
+               else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
                        c = ' ';
                else
-                       c = par->getChar(pos - 1);
+                       c = pit->getChar(pos - 1);
 
-               bv->hideCursor();
-               LyXLayout_ptr const & style = par->layout();
+               LyXLayout_ptr const & style = pit->layout();
 
                if (style->pass_thru ||
-                               par->getFontSettings(bv->buffer()->params,
+                               pit->getFontSettings(bv->buffer()->params,
                                         pos).language()->lang() == "hebrew" ||
                        (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
                        bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
@@ -1231,7 +1231,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                for (int i = 0; i < datetmp_len; i++) {
                        insertChar(datetmp[i]);
-                       update(true);
+                       update();
                }
                selection.cursor = cursor;
                moveCursorUpdate(bv, false);
@@ -1245,7 +1245,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
-                               bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                        }
                        cursorHome();
@@ -1254,7 +1253,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        setSelection();
                        if (!isInInset())
                                bv->screen().toggleSelection(this, bv, false);
-                       update(false);
+                       update();
                        bv->haveSelection(selection.set());
                }
                break;
@@ -1266,14 +1265,13 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
-                               bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                                selectWord(LyXText::WHOLE_WORD_STRICT);
                                bv->screen().toggleSelection(this, bv, false);
                        } else {
                                selectWord(LyXText::WHOLE_WORD_STRICT);
                        }
-                       update(false);
+                       update();
                        bv->haveSelection(selection.set());
                }
                break;
@@ -1292,7 +1290,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        Inset * tli = bv->theLockingInset();
                        LyXCursor cursor = bv->text->cursor;
                        LyXFont font = bv->text->getFont(bv->buffer(),
-                                                               cursor.par(), cursor.pos());
+                                                        cursor.par(), cursor.pos());
                        int width = tli->width(bv, font);
                        int inset_x = font.isVisibleRightToLeft()
                                ? cursor.ix() - width : cursor.ix();
@@ -1313,9 +1311,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               bv->screen().hideCursor();
-
-               Row * 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
@@ -1327,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)
@@ -1336,11 +1332,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                // Maybe an empty line was deleted
                if (!bv->text->selection.set())
-                       bv->update(bv->text, BufferView::UPDATE);
+                       bv->update(BufferView::UPDATE);
                bv->text->setSelection();
                bv->screen().toggleToggle(bv->text, bv);
                bv->fitCursor();
-               bv->showCursor();
                break;
        }
 
@@ -1394,12 +1389,11 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                if (!inset_hit)
                        selection_possible = true;
-               bv->screen().hideCursor();
 
                // Clear the selection
                bv->screen().toggleSelection(bv->text, bv);
                bv->text->clearSelection();
-               bv->text->fullRebreak();
+               bv->text->partialRebreak();
                bv->update();
                bv->updateScrollbar();
 
@@ -1408,11 +1402,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // Highly editable inset, like math
                        UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
                        selection_possible = false;
-                       bv->owner()->updateLayoutChoice();
                        bv->owner()->message(inset->editMessage());
-                       //inset->edit(bv, x, y, cmd.button());
                        // We just have to lock the inset before calling a PressEvent on it!
-                       // we don't need the edit() call here! (Jug20020329)
                        if (!bv->lockInset(inset))
                                lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
                        FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
@@ -1433,7 +1424,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bv->text->selection.cursor = bv->text->cursor;
                bv->text->cursor.x_fix(bv->text->cursor.x());
 
-               bv->owner()->updateLayoutChoice();
                if (bv->fitCursor())
                        selection_possible = false;
 
@@ -1550,7 +1540,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (lyxrc.auto_region_delete) {
                        if (selection.set()) {
                                cutSelection(false, false);
-                               update(bv);
+                               update();
                        }
                        bv->haveSelection(false);
                }
@@ -1564,7 +1554,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        bv->owner()->getIntl().getTransManager().
                                TranslateAndInsert(*cit, this);
 
-               update(bv);
+               update();
                selection.cursor = cursor;
                moveCursorUpdate(bv, false);
 
@@ -1618,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