]> git.lyx.org Git - lyx.git/blobdiff - src/Text2.cpp
This patch revert part of the code changed in revision 18825. This is needed because...
[lyx.git] / src / Text2.cpp
index d0b715f609ebf597f2adeb6ea0c551346098d12a..24365e99f30f99f96bb41a088e19bcadb96b5598 100644 (file)
@@ -11,6 +11,7 @@
  * \author John Levon
  * \author André Pönitz
  * \author Allan Rae
+ * \author Stefan Schimanski
  * \author Dekel Tsur
  * \author Jürgen Vigna
  *
@@ -648,16 +649,12 @@ void Text::setParagraph(Cursor & cur,
                params.spacing(spacing);
 
                // does the layout allow the new alignment?
-               Layout_ptr const & layout = par.layout();
-
-               if (align == LYX_ALIGN_LAYOUT)
-                       align = layout->align;
-               if (align & layout->alignpossible) {
-                       if (align == layout->align)
-                               params.align(LYX_ALIGN_LAYOUT);
-                       else
-                               params.align(align);
-               }
+               //FIXME The reason we need the first check is because
+               //LYX_ALIGN_LAYOUT isn't required to be possible. It
+               //should be...and will be.
+               if ((align == LYX_ALIGN_LAYOUT) ||
+                   (align & par.layout()->alignpossible))
+                       params.align(align);
                par.setLabelWidthString(labelwidthstring);
                params.noindent(noindent);
        }
@@ -669,7 +666,7 @@ void Text::insertInset(Cursor & cur, Inset * inset)
 {
        BOOST_ASSERT(this == cur.text());
        BOOST_ASSERT(inset);
-       cur.paragraph().insertInset(cur.pos(), inset,
+       cur.paragraph().insertInset(cur.pos(), inset, current_font,
                                    Change(cur.buffer().params().trackChanges ?
                                           Change::INSERTED : Change::UNCHANGED));
 }
@@ -760,42 +757,33 @@ void Text::setCurrentFont(Cursor & cur)
        pos_type pos = cur.pos();
        Paragraph & par = cur.paragraph();
 
-       // ignore empty paragraph
-       if (par.empty())
-               return;
-       
-       // if on boundary or at paragraph end, set font of previous char
-       if ((pos > 0 && cur.boundary()) || pos == cur.lastpos())
+       // are we behind previous char in fact? -> go to that char
+       if (pos > 0 && cur.boundary())
                --pos;
-       
-       // we changed the line and the bidi tables are outdated?
-       if (!bidi.inRange(pos))
-               bidi.computeTables(par, cur.buffer(), cur.textRow());
 
-       // now in range?
-       if (!bidi.inRange(pos))
-               return;
-
-       if (pos > 0) {
+       // find position to take the font from
+       if (pos != 0) {
+               // paragraph end? -> font of last char
                if (pos == cur.lastpos())
                        --pos;
-               else // potentional bug... BUG (Lgb)
-                       if (par.isSeparator(pos)) {
-                               if (pos > cur.textRow().pos() &&
-                                   bidi.level(pos) % 2 ==
-                                   bidi.level(pos - 1) % 2)
-                                       --pos;
-                               else if (pos + 1 < cur.lastpos())
-                                       ++pos;
-                       }
+               // on space? -> look at the words in front of space
+               else if (pos > 0 && par.isSeparator(pos))       {
+                       // abc| def -> font of c
+                       // abc |[WERBEH], i.e. boundary==true -> font of c
+                       // abc [WERBEH]| def, font of the space
+                       if (!isRTLBoundary(cur.buffer(), par, pos))
+                               --pos;
+               }
        }
 
+       // get font
        BufferParams const & bufparams = cur.buffer().params();
        current_font = par.getFontSettings(bufparams, pos);
        real_current_font = getFont(cur.buffer(), par, pos);
 
+       // special case for paragraph end
        if (cur.pos() == cur.lastpos()
-           && bidi.isBoundary(cur.buffer(), par, cur.pos())
+           && isRTLBoundary(cur.buffer(), par, cur.pos())
            && !cur.boundary()) {
                Language const * lang = par.getParLanguage(bufparams);
                current_font.setLanguage(lang);
@@ -992,6 +980,7 @@ bool Text::cursorLeft(Cursor & cur)
                // -> skip it, i.e. set boundary to true, i.e. go only logically left
                // there are some exceptions to ignore this: lineseps, newlines, spaces
 #if 0
+               // some effectless debug code to see the values in the debugger
                bool bound = cur.boundary();
                int rowpos = cur.textRow().pos();
                int pos = cur.pos();
@@ -1029,17 +1018,20 @@ bool Text::cursorRight(Cursor & cur)
 
        // not at paragraph end?
        if (cur.pos() != cur.lastpos()) {
-               // if left of boundary -> just jump to right side 
-               if (cur.boundary())
-                       return setCursor(cur, cur.pit(), cur.pos(), true, false);
-
                // in front of editable inset, i.e. jump into it?
                if (checkAndActivateInset(cur, true))
                        return false;
-               
+
+               // if left of boundary -> just jump to right side
+         // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
+         if (cur.boundary() && 
+                               !isRTLBoundary(cur.buffer(), cur.paragraph(), cur.pos()))
+                       return setCursor(cur, cur.pit(), cur.pos(), true, false);
+
                // next position is left of boundary, 
                // but go to next line for special cases like space, newline, linesep
 #if 0
+               // some effectless debug code to see the values in the debugger
                int endpos = cur.textRow().endpos();
                int lastpos = cur.lastpos();
                int pos = cur.pos();
@@ -1060,6 +1052,11 @@ bool Text::cursorRight(Cursor & cur)
                        return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
                }
                
+               // in front of RTL boundary? Stay on this side of the boundary because:
+               //   ab|cDDEEFFghi -> abc|DDEEFFghi
+               if (isRTLBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1))
+                       return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
+               
                // move right
                return setCursor(cur, cur.pit(), cur.pos() + 1, true, false);
        }