Skip to content

Commit 3f00173

Browse files
committed
Use custom is_printable instead of iswprint to fix emojis on OSX
If its good enough for musl, its likely good enough for us, and the github issue shows that (at least some) terminal emulators do not seem to rely on the libc iswprint in the first place. Fixes #3059
1 parent 1f525cb commit 3f00173

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/highlighters.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,13 @@ void highlight_selections(HighlightContext context, DisplayBuffer& display_buffe
12301230

12311231
void expand_unprintable(HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
12321232
{
1233+
auto is_printable = [](Codepoint cp) { // follow musl iswprint set of printable characters, but with straightforward impl
1234+
if (cp < 0xff)
1235+
return cp == '\n' or cp >= ' ';
1236+
else if (cp == 0x2028 or cp == 0x2029 or (cp >= 0xFFF9 and cp <= 0xFFFB))
1237+
return false;
1238+
return true;
1239+
};
12331240
const auto& buffer = context.context.buffer();
12341241
auto error = context.context.faces()[FaceSpec{{}, "Error"}];
12351242
for (auto& line : display_buffer.lines())
@@ -1245,7 +1252,7 @@ void expand_unprintable(HighlightContext context, DisplayBuffer& display_buffer,
12451252
{
12461253
auto next = it;
12471254
Codepoint cp = utf8::read_codepoint(next, end);
1248-
if (cp != '\n' and (cp < ' ' or cp > '~') and not iswprint((wchar_t)cp))
1255+
if (not is_printable(cp))
12491256
{
12501257
if (ByteCount pos(it - line_data); pos != begin.column)
12511258
atom_it = ++line.split(atom_it, {begin.line, pos});

0 commit comments

Comments
 (0)