]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
* Only enter inset which return true on isActive(). This is the behavior in the curso...
[lyx.git] / src / Text3.cpp
index 4085b75a89116948b541cae7345c57dcd8b3b639..d3a4d376e69bc3b22f63a56b7c65c83fa749916f 100644 (file)
@@ -99,7 +99,6 @@ namespace {
        Font freefont(Font::ALL_IGNORE);
        bool toggleall = false;
 
-
        void toggleAndShow(Cursor & cur, Text * text,
                Font const & font, bool toggleall = true)
        {
@@ -108,13 +107,10 @@ namespace {
                if (font.language() != ignore_language ||
                                font.number() != Font::IGNORE) {
                        Paragraph & par = cur.paragraph();
-                       text->bidi.computeTables(par, cur.buffer(), cur.textRow());
-                       if (cur.boundary() !=
-                                       text->bidi.isBoundary(cur.buffer(), par,
-                                                       cur.pos(),
-                                                       text->real_current_font))
+                       if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
+                                               cur.pos(), text->real_current_font))
                                text->setCursor(cur, cur.pit(), cur.pos(),
-                                               false, !cur.boundary());
+                                               false, !cur.boundary());
                }
        }
 
@@ -299,6 +295,56 @@ bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
 }
 
 
+bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
+{
+       if (!lyxrc.rtl_support && !sl.text())
+               return false;
+
+       int correction = 0;
+       if (boundary && sl.pos() > 0)
+               correction = -1;
+               
+       Paragraph const & par = getPar(sl.pit());
+       return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
+}
+
+
+bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
+                         pos_type pos) const
+{
+       if (!lyxrc.rtl_support)
+               return false;
+
+       // no RTL boundary at line start
+       if (pos == 0)
+               return false;
+
+       bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
+       bool right;
+       if (pos == par.size())
+               right = par.isRightToLeftPar(buffer.params());
+       else
+               right = getFont(buffer, par, pos).isVisibleRightToLeft();
+       return left != right;
+}
+
+
+bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
+                         pos_type pos, Font const & font) const
+{
+       if (!lyxrc.rtl_support)
+               return false;
+
+       bool left = font.isVisibleRightToLeft();
+       bool right;
+       if (pos == par.size())
+               right = par.isRightToLeftPar(buffer.params());
+       else
+               right = getFont(buffer, par, pos).isVisibleRightToLeft();
+       return left != right;
+}
+
+
 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 {
        LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
@@ -334,7 +380,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                std::swap(pars_[pit], pars_[pit + 1]);
 
                ParIterator begin(cur);
-               // begin.pos() (== cur.pos()) may point beyond the end of the 
+               // begin.pos() (== cur.pos()) may point beyond the end of the
                // paragraph referenced by begin. This would cause a crash
                // in updateLabels()
                begin.pos() = 0;
@@ -353,7 +399,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                std::swap(pars_[pit], pars_[pit - 1]);
 
                ParIterator end = ParIterator(cur);
-               // end.pos() (== cur.pos()) may point beyond the end of the 
+               // end.pos() (== cur.pos()) may point beyond the end of the
                // paragraph referenced by end. This would cause a crash
                // in boost::next()
                end.pos() = 0;
@@ -443,8 +489,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
-               }
-               if (cur.selection())
+               } else if (cur.selection())
                        saveSelection(cur);
                break;
 
@@ -467,36 +512,28 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_UP:
-       case LFUN_UP_SELECT:
+       case LFUN_UP_SELECT: {
                //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
                needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
-
-               needsUpdate |= cursorUp(cur);
-
-               if (!needsUpdate && oldTopSlice == cur.top()
-                         && cur.boundary() == oldBoundary) {
+               bool const successful = cur.upDownInText(true, needsUpdate);
+               if (!successful)
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
-               }
                if (cur.selection())
                        saveSelection(cur);
                break;
+       }
 
        case LFUN_DOWN:
-       case LFUN_DOWN_SELECT:
+       case LFUN_DOWN_SELECT: {
                //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
                needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
-               needsUpdate |= cursorDown(cur);
-
-               if (!needsUpdate && oldTopSlice == cur.top() &&
-                   cur.boundary() == oldBoundary)
-               {
+               bool const successful = cur.upDownInText(false, needsUpdate);
+               if (!successful)
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
-               }
                if (cur.selection())
                        saveSelection(cur);
                break;
+       }
 
        case LFUN_PARAGRAPH_UP:
        case LFUN_PARAGRAPH_UP_SELECT:
@@ -517,10 +554,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_UP_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
-               if (cur.pit() == 0 && cur.textRow().pos() == 0) {
+               if (cur.pit() == 0 && cur.textRow().pos() == 0)
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
-               } else {
+               else {
                        cursorPrevious(cur);
                }
                if (cur.selection())
@@ -531,10 +567,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_SCREEN_DOWN_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
                if (cur.pit() == cur.lastpit()
-                         && cur.textRow().endpos() == cur.lastpos()) {
+                         && cur.textRow().endpos() == cur.lastpos())
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
-               } else {
+               else {
                        cursorNext(cur);
                }
                if (cur.selection())
@@ -734,7 +769,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        // FIXME (Abdel 01/02/2006):
                        // What follows would be a partial fix for bug 2154:
                        //   http://bugzilla.lyx.org/show_bug.cgi?id=2154
-                       // This automatically put the label inset _after_ a 
+                       // This automatically put the label inset _after_ a
                        // numbered section. It should be possible to extend the mechanism
                        // to any kind of LateX environement.
                        // The correct way to fix that bug would be at LateX generation.
@@ -810,7 +845,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_CHARS_TRANSPOSE:
-               charsTranspose(cur);
+               charsTranspose(cur);
                break;
 
        case LFUN_PASTE:
@@ -926,13 +961,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CLIPBOARD_PASTE:
                cur.clearSelection();
                pasteClipboard(cur, bv->buffer()->errorList("Paste"),
-                              cmd.argument() == "paragraph");
+                              cmd.argument() == "paragraph");
                bv->buffer()->errors("Paste");
                break;
 
        case LFUN_PRIMARY_SELECTION_PASTE:
                pasteString(cur, theSelection().get(),
-                           cmd.argument() == "paragraph");
+                           cmd.argument() == "paragraph");
                break;
 
        case LFUN_UNICODE_INSERT: {
@@ -949,7 +984,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                }
                break;
        }
-               
+
        case LFUN_QUOTE_INSERT: {
                Paragraph & par = cur.paragraph();
                pos_type pos = cur.pos();
@@ -1032,9 +1067,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        paste_internally = true;
                }
 
-               // we have to update after dePM triggered
-               bool update = bv->mouseSetCursor(cur);
-
                // Insert primary selection with middle mouse
                // if there is a local selection in the current buffer,
                // insert this
@@ -1044,11 +1076,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                bv->buffer()->errors("Paste");
                                cur.clearSelection(); // bug 393
                                bv->switchKeyMap();
+                               bv->buffer()->markDirty();
                                finishUndo();
-                       } else
+                       } else {
+                               bv->mouseSetCursor(cur);
                                lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
+                       }
                }
 
+               // we have to update after dePM triggered
+               bool update = bv->mouseSetCursor(cur);
+
                if (!update && cmd.button() == mouse_button::button1) {
                        needsUpdate = false;
                        cur.noUpdate();
@@ -1071,7 +1109,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        int const y = std::max(0, std::min(wh - 1, cmd.y));
 
                        setCursorFromCoordinates(cur, cmd.x, y);
-                       cur.x_target() = cmd.x;
+                       cur.setTargetX(cmd.x);
                        if (cmd.y >= wh)
                                lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
                        else if (cmd.y < 0)
@@ -1244,7 +1282,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        pars.push_back(Paragraph());
                        pars.back().setInsetOwner(pars[0].inInset());
                        pars.back().layout(tclass.defaultLayout());
-                       
+
                }
 
                // reposition the cursor to the caption
@@ -1336,7 +1374,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_DELIM:
        case LFUN_MATH_BIGDELIM: {
                cur.insert(new InsetMathHull(hullSimple));
-               cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
+               checkAndActivateInset(cur, true);
                BOOST_ASSERT(cur.inMathed());
                cur.dispatch(cmd);
                break;
@@ -1446,16 +1484,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        ++cur.pos();
                break;
 
-       case LFUN_FINISHED_UP:
-               LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_UP:\n" << cur << endl;
-               cursorUp(cur);
-               break;
-
-       case LFUN_FINISHED_DOWN:
-               LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
-               cursorDown(cur);
-               break;
-
        case LFUN_LAYOUT_PARAGRAPH: {
                string data;
                params2string(cur.paragraph(), data);
@@ -1602,7 +1630,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        // update flag treatment.
        if (singleParUpdate) {
                // Inserting characters does not change par height
-               ParagraphMetrics const & pms 
+               ParagraphMetrics const & pms
                        = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
                if (pms.dim().height()
                    == olddim.height()) {
@@ -1624,7 +1652,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                //
                //if (cur.result().update() != Update::FitCursor)
                //      cur.noUpdate();
-               // 
+               //
                // But some LFUNs do not set Update::FitCursor when needed, so we
                // do it for all. This is not very harmfull as FitCursor will provoke
                // a full redraw only if needed but still, a proper review of all LFUN