]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Provide proper fallback if a bibliography processor is not found
[lyx.git] / src / Text.cpp
index d5d729a2770935d2722d756ef0438594cf9c3b15..8337e6db4f9bacf13809d626aed7aa90bd9c23d8 100644 (file)
@@ -693,6 +693,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
 
                tmp->params().depth(par.params().depth());
                tmp->params().noindent(par.params().noindent());
+               tmp->params().spacing(par.params().spacing());
 
                // move everything behind the break position
                // to the new paragraph
@@ -866,8 +867,8 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
                                ++pos;
                                space_inserted = true;
                        }
-               } else if (!isPrintable(*cit)) {
-                       // Ignore unprintables
+               } else if (!isPrintable(*cit) && *cit != 0x200c) {
+                       // Ignore unprintables, except for ZWNJ (0x200c)
                        continue;
                } else {
                        // just insert the character
@@ -968,14 +969,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(".,:");
 
+               // Common 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) &&
+                           !(isCommonNumberSeparator(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
@@ -993,7 +999,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                  ) {
                                        setCharFont(pit, cur.pos() - 1, cur.current_font,
                                                tm.font_);
-                               } else if (contains(number_separators, c)
+                               } else if (isCommonNumberSeparator(c)
                                     && cur.pos() >= 2
                                     && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) {
                                        setCharFont(pit, cur.pos() - 1, cur.current_font,
@@ -1476,7 +1482,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();
                }
        }
@@ -1494,7 +1500,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();
                }
        }
@@ -1892,7 +1898,7 @@ bool Text::read(Lexer & lex,
 }
 
 
-// Returns the current font and depth as a message.
+// Returns the current state (font, depth etc.) as a message for status bar.
 docstring Text::currentState(Cursor const & cur, bool devel_mode) const
 {
        LBUFERR(this == cur.text());
@@ -1922,7 +1928,7 @@ docstring Text::currentState(Cursor const & cur, bool devel_mode) const
        os << bformat(_("Font: %1$s"), font.stateText(&buf.params()));
 
        // The paragraph depth
-       int depth = cur.paragraph().getDepth();
+       int depth = par.getDepth();
        if (depth > 0)
                os << bformat(_(", Depth: %1$d"), depth);
 
@@ -1950,6 +1956,11 @@ docstring Text::currentState(Cursor const & cur, bool devel_mode) const
                }
        }
 
+       // Custom text style
+       InsetLayout const & layout = cur.inset().getLayout();
+       if (layout.lyxtype() == InsetLayout::CHARSTYLE)
+               os << _(", Style: ") << translateIfPossible(layout.labelstring());
+
        if (devel_mode) {
                os << _(", Inset: ") << &cur.inset();
                os << _(", Paragraph: ") << cur.pit();
@@ -1972,12 +1983,44 @@ docstring Text::currentState(Cursor const & cur, bool devel_mode) const
 
 docstring Text::getPossibleLabel(Cursor const & cur) const
 {
-       pit_type pit = cur.pit();
+       pit_type textpit = cur.pit();
+       Layout const * layout = &(pars_[textpit].layout());
 
-       Layout const * layout = &(pars_[pit].layout());
+       // Will contain the label prefix.
+       docstring name;
+
+       // For captions, we just take the caption type
+       Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE);
+       if (caption_inset) {
+               string const & ftype = static_cast<InsetCaption *>(caption_inset)->floattype();
+               FloatList const & fl = cur.buffer()->params().documentClass().floats();
+               if (fl.typeExist(ftype)) {
+                       Floating const & flt = fl.getType(ftype);
+                       name = from_utf8(flt.refPrefix());
+               }
+               if (name.empty())
+                       name = from_utf8(ftype.substr(0,3));
+       } else {
+               // For section, subsection, etc...
+               if (layout->latextype == LATEX_PARAGRAPH && textpit != 0) {
+                       Layout const * layout2 = &(pars_[textpit - 1].layout());
+                       if (layout2->latextype != LATEX_PARAGRAPH) {
+                               --textpit;
+                               layout = layout2;
+                       }
+               }
+               if (layout->latextype != LATEX_PARAGRAPH)
+                       name = layout->refprefix;
+
+               // If none of the above worked, see if the inset knows.
+               if (name.empty()) {
+                       InsetLayout const & il = cur.inset().getLayout();
+                       name = il.refprefix();
+               }
+       }
 
        docstring text;
-       docstring par_text = pars_[pit].asString();
+       docstring par_text = pars_[textpit].asString(AS_STR_SKIPDELETE);
 
        // The return string of math matrices might contain linebreaks
        par_text = subst(par_text, '\n', '-');
@@ -1998,46 +2041,13 @@ docstring Text::getPossibleLabel(Cursor const & cur) const
        if (text.size() > max_label_length)
                text.resize(max_label_length);
 
-       // Will contain the label prefix.
-       docstring name;
-
-       // For section, subsection, etc...
-       if (layout->latextype == LATEX_PARAGRAPH && pit != 0) {
-               Layout const * layout2 = &(pars_[pit - 1].layout());
-               if (layout2->latextype != LATEX_PARAGRAPH) {
-                       --pit;
-                       layout = layout2;
-               }
-       }
-       if (layout->latextype != LATEX_PARAGRAPH)
-               name = layout->refprefix;
-
-       // For captions, we just take the caption type
-       Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE);
-       if (caption_inset) {
-               string const & ftype = static_cast<InsetCaption *>(caption_inset)->floattype();
-               FloatList const & fl = cur.buffer()->params().documentClass().floats();
-               if (fl.typeExist(ftype)) {
-                       Floating const & flt = fl.getType(ftype);
-                       name = from_utf8(flt.refPrefix());
-               }
-               if (name.empty())
-                       name = from_utf8(ftype.substr(0,3));
-       }
-
-       // If none of the above worked, see if the inset knows.
-       if (name.empty()) {
-               InsetLayout const & il = cur.inset().getLayout();
-               name = il.refprefix();
-       }
-
        if (!name.empty())
                text = name + ':' + text;
 
        // 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;
                }
@@ -2189,7 +2199,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);
 }