]> git.lyx.org Git - features.git/commitdiff
Paste some special chars as insets
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 23 Mar 2020 11:07:47 +0000 (12:07 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 23 Mar 2020 11:07:47 +0000 (12:07 +0100)
See #11790

src/Text.cpp
src/insets/InsetSpecialChar.cpp

index 25ce684d22221f7d50e5cba5db21569781ba53a1..4a447577f22c9e91d0139a739525d3a276f1538c 100644 (file)
@@ -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<wchar_t, InsetSpecialChar::Kind> 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
index 76da971ea0bbea1e03250ea1727e658f6e96fc31..740061e0312ea85a2ef60aa639f478ccbfdefd5d 100644 (file)
@@ -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 << "\\@.";