Paste some special chars as insets

See #11790
This commit is contained in:
Juergen Spitzmueller 2020-03-23 12:07:47 +01:00
parent 92c4bb4682
commit 52cd43dfdc
2 changed files with 24 additions and 3 deletions

View 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

View 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 << "\\@.";