From 3efa484835ce0173c7ac3e9a26d50492fc73e874 Mon Sep 17 00:00:00 2001 From: "jdg.gehrig@gmail.com" Date: Mon, 7 Dec 2020 02:16:41 -0500 Subject: [PATCH] Issue 735: GuiRenderLigatures emoji cursor incorrect QString::at does not handle multi-byte Unicode characters. A naive call will only select the first byte from the sequence. Use the entire UTF8 grapheme. --- src/gui/shellwidget/shellwidget.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui/shellwidget/shellwidget.cpp b/src/gui/shellwidget/shellwidget.cpp index 71e20b980..b213ff8ea 100644 --- a/src/gui/shellwidget/shellwidget.cpp +++ b/src/gui/shellwidget/shellwidget.cpp @@ -723,8 +723,15 @@ void ShellWidget::paintForegroundTextBlock( blockRect.left() + (m_cellSize.width() * cursorPos), blockRect.top() + m_ascent + (m_lineSpace / 2) }; + // Issue 735: Some characters (emoji) contain multiple bytes. + // FIXME Is QTextBoundary a better approach? Will this work for 3+ byte chars? + QString cursorText{ text.at(cursorPos) }; + if (cell.IsDoubleWidth() && IsValidIndex(text, cursorPos + 1)) { + cursorText += text.at(cursorPos + 1); + } + paintNeovimCursorBackground(p, neovimCursorRect()); - paintNeovimCursorForeground(p, neovimCursorRect(), cursorDrawPos, text.at(cursorPos)); + paintNeovimCursorForeground(p, neovimCursorRect(), cursorDrawPos, cursorText); } }