]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Disable changebar checkbox if show changes in output is off
[lyx.git] / src / Text.cpp
index 876c5d0cb15689522055cb5416dae5a2fcb470d6..e060a6c9dd6d69e2dbf95f819063ae8f9bf23a6d 100644 (file)
@@ -288,6 +288,35 @@ Font const Text::outerFont(pit_type par_offset) const
 }
 
 
+int Text::getEndLabel(pit_type p) const
+{
+       pit_type pit = p;
+       depth_type par_depth = pars_[p].getDepth();
+       while (pit != pit_type(pars_.size())) {
+               Layout const & layout = pars_[pit].layout();
+               int const endlabeltype = layout.endlabeltype;
+
+               if (endlabeltype != END_LABEL_NO_LABEL) {
+                       if (p + 1 == pit_type(pars_.size()))
+                               return endlabeltype;
+
+                       depth_type const next_depth =
+                               pars_[p + 1].getDepth();
+                       if (par_depth > next_depth ||
+                           (par_depth == next_depth && layout != pars_[p + 1].layout()))
+                               return endlabeltype;
+                       break;
+               }
+               if (par_depth == 0)
+                       break;
+               pit = outerHook(pit);
+               if (pit != pit_type(pars_.size()))
+                       par_depth = pars_[pit].getDepth();
+       }
+       return END_LABEL_NO_LABEL;
+}
+
+
 static void acceptOrRejectChanges(ParagraphList & pars,
        BufferParams const & bparams, Text::ChangeOp op)
 {
@@ -925,8 +954,8 @@ bool canInsertChar(Cursor const & cur, char_type c)
                                        "beginning of a paragraph. Please read the Tutorial."));
                        return false;
                }
-               // LASSERT: Is it safe to continue here?
-               LASSERT(cur.pos() > 0, /**/);
+               // If something is wrong, ignore this character.
+               LASSERT(cur.pos() > 0, return false);
                if ((par.isLineSeparator(cur.pos() - 1) || par.isNewline(cur.pos() - 1))
                                && !par.isDeleted(cur.pos() - 1)) {
                        cur.message(_(
@@ -971,14 +1000,19 @@ void Text::insertChar(Cursor & cur, char_type c)
        if (lyxrc.auto_number) {
                static docstring const number_operators = from_ascii("+-/*");
                static docstring const number_unary_operators = from_ascii("+-");
-               static docstring const number_separators = from_ascii(".,:");
 
+               // European Number Separators: comma, dot etc.
+               // European Number Terminators: percent, permille, degree, euro etc.
                if (cur.current_font.fontInfo().number() == FONT_ON) {
                        if (!isDigitASCII(c) && !contains(number_operators, c) &&
-                           !(contains(number_separators, c) &&
+                           !(isEuropeanNumberSeparator(c) &&
                              cur.pos() != 0 &&
                              cur.pos() != cur.lastpos() &&
                              tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
+                             tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON) &&
+                           !(isEuropeanNumberTerminator(c) &&
+                             cur.pos() != 0 &&
+                             tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
                              tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
                           )
                                number(cur); // Set current_font.number to OFF
@@ -996,7 +1030,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                  ) {
                                        setCharFont(pit, cur.pos() - 1, cur.current_font,
                                                tm.font_);
-                               } else if (contains(number_separators, ch)
+                               } else if (isEuropeanNumberSeparator(ch)
                                     && cur.pos() >= 2
                                     && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) {
                                        setCharFont(pit, cur.pos() - 1, cur.current_font,
@@ -1336,7 +1370,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
        pos_type endPos = cur.selectionEnd().pos();
 
        // keep selection info, because endPos becomes invalid after the first loop
-       bool endsBeforeEndOfPar = (endPos < pars_[endPit].size());
+       bool const endsBeforeEndOfPar = (endPos < pars_[endPit].size());
 
        // first, accept/reject changes within each individual paragraph (do not consider end-of-par)
        for (pit_type pit = begPit; pit <= endPit; ++pit) {
@@ -1355,8 +1389,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
                if (pit == endPit && endPos == 0)
                        break; // last iteration anyway
 
-               pos_type left  = (pit == begPit ? begPos : 0);
-               pos_type right = (pit == endPit ? endPos : parSize);
+               pos_type const left  = (pit == begPit ? begPos : 0);
+               pos_type const right = (pit == endPit ? endPos : parSize);
 
                if (left == right)
                        // there is no change here
@@ -1479,7 +1513,7 @@ void Text::deleteWordForward(Cursor & cur, bool const force)
                cursorForwardOneWord(cur);
                cur.setSelection();
                if (force || !cur.confirmDeletion()) {
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        cur.checkBufferStructure();
                }
        }
@@ -1497,7 +1531,7 @@ void Text::deleteWordBackward(Cursor & cur, bool const force)
                cursorBackwardOneWord(cur);
                cur.setSelection();
                if (force || !cur.confirmDeletion()) {
-                       cutSelection(cur, true, false);
+                       cutSelection(cur, false);
                        cur.checkBufferStructure();
                }
        }
@@ -1786,6 +1820,18 @@ bool Text::dissolveInset(Cursor & cur)
                for (; it != it_end; ++it)
                        it->changeLanguage(b.params(), latex_language, b.language());
 
+               /* If the inset is the only thing in paragraph and the layout
+                * is not plain, then the layout of the first paragraph of
+                * inset should be remembered.
+                * FIXME: this does not work as expected when change tracking
+                *   is on However, we do not really know what to do in this
+                *   case.
+                */
+               DocumentClass const & tclass = cur.buffer()->params().documentClass();
+               if (inset_it.lastpos() == 1
+                   && plist[0].layout().name() != tclass.plainLayoutName())
+                       cur.paragraph().makeSameLayout(plist[0]);
+
                pasteParagraphList(cur, plist, b.params().documentClassPtr(),
                                   b.errorList("Paste"));
        }
@@ -2042,7 +2088,7 @@ docstring Text::getPossibleLabel(DocIterator const & cur) const
        // We need a unique label
        docstring label = text;
        int i = 1;
-       while (cur.buffer()->insetLabel(label)) {
+       while (cur.buffer()->activeLabel(label)) {
                        label = text + '-' + convert<docstring>(i);
                        ++i;
                }
@@ -2194,7 +2240,8 @@ docstring Text::previousWord(CursorSlice const & sl) const
 bool Text::completionSupported(Cursor const & cur) const
 {
        Paragraph const & par = cur.paragraph();
-       return cur.pos() > 0
+       return !cur.selection()
+               && cur.pos() > 0
                && (cur.pos() >= par.size() || par.isWordSeparator(cur.pos()))
                && !par.isWordSeparator(cur.pos() - 1);
 }