From: Juergen Spitzmueller Date: Mon, 23 Mar 2020 11:07:47 +0000 (+0100) Subject: Paste some special chars as insets X-Git-Tag: lyx-2.4.0dev-acb2ca7b~1075 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=52cd43dfdcffa3d293cec1be11ac9d4fa55b46bd;p=features.git Paste some special chars as insets See #11790 --- diff --git a/src/Text.cpp b/src/Text.cpp index 25ce684d22..4a447577f2 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -866,6 +866,13 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, pit_type pit = cur.pit(); pos_type pos = cur.pos(); + // The special chars we handle + map specialchars; + specialchars[0x200c] = InsetSpecialChar::LIGATURE_BREAK; + specialchars[0x200b] = InsetSpecialChar::ALLOWBREAK; + specialchars[0x2026] = InsetSpecialChar::LDOTS; + specialchars[0x2011] = InsetSpecialChar::NOBREAKDASH; + // insert the string, don't insert doublespace bool space_inserted = true; for (auto const & ch : str) { @@ -895,8 +902,15 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, ++pos; space_inserted = true; } - } else if (!isPrintable(ch) && ch != 0x200c) { - // Ignore unprintables, except for ZWNJ (0x200c) + } else if (specialchars.find(ch) != specialchars.end()) { + par.insertInset(pos, new InsetSpecialChar(specialchars.find(ch)->second), + font, bparams.track_changes ? + Change(Change::INSERTED) + : Change(Change::UNCHANGED)); + ++pos; + space_inserted = false; + } else if (!isPrintable(ch)) { + // Ignore (other) unprintables continue; } else { // just insert the character diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 76da971ea0..740061e031 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -15,6 +15,7 @@ #include "InsetSpecialChar.h" #include "Dimension.h" +#include "Encoding.h" #include "Font.h" #include "Language.h" #include "LaTeXFeatures.h" @@ -384,6 +385,7 @@ void InsetSpecialChar::latex(otexstream & os, OutputParams const & rp) const { bool const rtl = rp.local_font->isRightToLeft(); + bool const utf8 = rp.encoding->iconvName() == "UTF-8"; string lswitch = ""; string lswitche = ""; if (rtl && !rp.use_polyglossia) { @@ -399,10 +401,15 @@ void InsetSpecialChar::latex(otexstream & os, os << "\\-"; break; case ALLOWBREAK: + // U+200B not yet supported by utf8 inputenc os << "\\LyXZeroWidthSpace" << termcmd; break; case LIGATURE_BREAK: - os << "\\textcompwordmark" << termcmd; + if (utf8) + // U+200C ZERO WIDTH NON-JOINER + os.put(0x200c); + else + os << "\\textcompwordmark" << termcmd; break; case END_OF_SENTENCE: os << "\\@.";