From 5ff8245cc84a15d6a48bd2e19e4c70d4f8ae3f77 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 2 Dec 2016 13:59:34 +0000 Subject: [PATCH] =?UTF-8?q?Display=20non=20breaking=20spaces=20with=20?= =?UTF-8?q?=E2=8D=BD=20in=20show=5Fwhitespaces=20hihglighter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #167 --- src/highlighters.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 3cf93b02..ece03ca5 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -695,26 +695,29 @@ void show_whitespaces(const Context& context, HighlightFlags flags, DisplayBuffe auto begin = buffer.iterator_at(atom_it->begin()); auto end = buffer.iterator_at(atom_it->end()); - for (BufferIterator it = begin; it != end; ++it) + for (BufferIterator it = begin; it != end; ) { - auto c = *it; - if (c == '\t' or c == ' ' or c == '\n') + auto coord = it.coord(); + Codepoint cp = utf8::read_codepoint(it, end); + if (cp == '\t' or cp == ' ' or cp == '\n' or cp == 0xA0) { - if (it != begin) - atom_it = ++line.split(atom_it, it.coord()); - if (it+1 != end) - atom_it = line.split(atom_it, (it+1).coord()); + if (coord != begin.coord()) + atom_it = ++line.split(atom_it, coord); + if (it != end) + atom_it = line.split(atom_it, it.coord()); - if (c == '\t') + if (cp == '\t') { int column = (int)get_column(buffer, tabstop, it.coord()); int count = tabstop - (column % tabstop); atom_it->replace("→" + String(' ', CharCount{count-1})); } - else if (c == ' ') + else if (cp == ' ') atom_it->replace("·"); - else if (c == '\n') + else if (cp == '\n') atom_it->replace("¬"); + else if (cp == 0xA0) + atom_it->replace("⍽"); atom_it->face = whitespaceface; break; }