From 75640b66e503f5ca310e6f5b3a636989d0d750fe Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 15 Jul 2015 21:38:55 +0200 Subject: [PATCH] When adding completion to a row, add also the unique part The unique and non-unique parts of the completion are show in different colors. --- src/TextMetrics.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index ec35d10188..07064b6ca0 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -810,14 +810,10 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit #endif // check for possible inline completion - DocIterator const & inlineCompletionPos = bv_->inlineCompletionPos(); - pos_type inlineCompletionLPos = -1; - if (inlineCompletionPos.inTexted() - && inlineCompletionPos.text() == text_ - && inlineCompletionPos.pit() == pit) { - // draw logically behind the previous character - inlineCompletionLPos = inlineCompletionPos.pos() - 1; - } + DocIterator const & ic_it = bv_->inlineCompletionPos(); + pos_type ic_pos = -1; + if (ic_it.inTexted() && ic_it.text() == text_ && ic_it.pit() == pit) + ic_pos = ic_it.pos(); // Now we iterate through until we reach the right margin // or the end of the par, then build a representation of the row. @@ -855,12 +851,18 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit row.add(i, c, *fi, par.lookupChange(i)); // add inline completion width - if (inlineCompletionLPos == i && - !bv_->inlineCompletion().empty()) { + // draw logically behind the previous character + if (ic_pos == i + 1 && !bv_->inlineCompletion().empty()) { + docstring const comp = bv_->inlineCompletion(); + size_t const uniqueTo =bv_->inlineCompletionUniqueChars(); Font f = *fi; - f.fontInfo().setColor(Color_inlinecompletion); - row.addVirtual(i + 1, bv_->inlineCompletion(), - f, Change()); + + if (uniqueTo > 0) { + f.fontInfo().setColor(Color_inlinecompletion); + row.addVirtual(i + 1, comp.substr(0, uniqueTo), f, Change()); + } + f.fontInfo().setColor(Color_nonunique_inlinecompletion); + row.addVirtual(i + 1, comp.substr(uniqueTo), f, Change()); } // Handle some situations that abruptly terminate the row