X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText.cpp;h=ca2d06eabba30265abe53588670a65600a0d5862;hb=c41f9f7ed7a890523acd387868472080d0c68df2;hp=e1c37faf3ab2700376d70f2d2f2e0ca2b4e3fc8a;hpb=9fe8190364d27a538efa3928d2166b09e1cef2d5;p=lyx.git diff --git a/src/Text.cpp b/src/Text.cpp index e1c37faf3a..ca2d06eabb 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -933,15 +933,12 @@ bool canInsertChar(Cursor const & cur, char_type c) } } - // Prevent to insert uncodable characters in verbatim and ERT - // (workaround for bug 9012) - // Don't do it for listings inset, since InsetListings::latex() tries - // to switch to a usable encoding which works in many cases (bug 9102). - if (par.isPassThru() && cur.inset().lyxCode() != LISTINGS_CODE && - cur.current_font.language()) { - Encoding const * e = cur.current_font.language()->encoding(); + // Prevent to insert uncodable characters in verbatim and ERT. + // The encoding is inherited from the context here. + if (par.isPassThru() && cur.getEncoding()) { + Encoding const * e = cur.getEncoding(); if (!e->encodable(c)) { - cur.message(_("Character is uncodable in verbatim paragraphs.")); + cur.message(_("Character is uncodable in this verbatim context.")); return false; } } @@ -971,14 +968,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 +998,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 (isEuropeanNumberSeparator(c) && cur.pos() >= 2 && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) { setCharFont(pit, cur.pos() - 1, cur.current_font, @@ -1975,12 +1977,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()); + + // 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(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; - Layout const * layout = &(pars_[pit].layout()); + // 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', '-'); @@ -2001,39 +2035,6 @@ 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(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; @@ -2192,7 +2193,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); }