diff --git a/highlight.cpp b/highlight.cpp index 3f4cde855..a1ac40b09 100644 --- a/highlight.cpp +++ b/highlight.cpp @@ -919,12 +919,14 @@ static void tokenize( const wchar_t * const buff, std::vector &color, const /* Highlight the parameter. highlight_param wants to write one more color than we have characters (hysterical raisins) so allocate one more in the vector. But don't copy it back. */ const wcstring param_str = param; - std::vector subcolors; - subcolors.resize(1 + param_str.size(), -1); int tok_pos = tok_get_pos(&tok); + + std::vector::const_iterator where = color.begin() + tok_pos; + std::vector subcolors(where, where + param_str.size()); + subcolors.push_back(-1); highlight_param(param_str, subcolors, pos-tok_pos, error); - /* Copy the subcolors into our colors array */ + /* Copy the subcolors back into our colors array */ std::copy(subcolors.begin(), subcolors.begin() + param_str.size(), color.begin() + tok_pos); } else