From 6907fcf76e81dc35cb4ca8b9969a5018b475841a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 18 Mar 2013 23:35:23 +0100 Subject: [PATCH] more robust implementation of expand_unprintable --- src/highlighters.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index c38981766..c02255fb9 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -282,12 +282,12 @@ void expand_unprintable(DisplayBuffer& display_buffer) { for (auto& line : display_buffer.lines()) { - for (auto& atom : line) + for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it) { - if (atom.content.type() == AtomContent::BufferRange) + if (atom_it->content.type() == AtomContent::BufferRange) { - using Utf8It = utf8::utf8_iterator; - for (Utf8It it = atom.content.begin(), end = atom.content.end(); it != end; ++it) + using Utf8It = utf8::utf8_iterator; + for (Utf8It it = atom_it->content.begin(), end = atom_it->content.end(); it != end; ++it) { Codepoint cp = *it; if (cp != '\n' and not std::isprint((wchar_t)cp, std::locale())) @@ -295,10 +295,13 @@ void expand_unprintable(DisplayBuffer& display_buffer) std::ostringstream oss; oss << "U+" << std::hex << cp; String str = oss.str(); - highlight_range(display_buffer, - it.underlying_iterator(), (it+1).underlying_iterator(), - true, [&str](DisplayAtom& atom){ atom.content.replace(str); - atom.colors = { Color::Red, Color::Black }; }); + if (it.underlying_iterator() != atom_it->content.begin()) + atom_it = ++line.split(atom_it, it.underlying_iterator()); + if ((it+1).underlying_iterator() != atom_it->content.end()) + atom_it = line.split(atom_it, (it+1).underlying_iterator()); + atom_it->content.replace(str); + atom_it->colors = { Color::Red, Color::Black }; + break; } } }