X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Frowpainter.cpp;h=6d56c27b60db69ccbb6743e91c3930cc8d68000e;hb=2455bc258f3b62c29ec4a41cb88070ff8518e842;hp=ccb3364a69f735652cae778ceccfdcdd512cd5c5;hpb=45bc27809bae95259e251a2215b39f945d8835ca;p=lyx.git diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index ccb3364a69..6d56c27b60 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -224,10 +224,6 @@ void RowPainter::paintChars(pos_type & vpos, FontInfo const & font, { // This method takes up 70% of time when typing pos_type pos = bidi_.vis2log(vpos); - pos_type const end = row_.endpos(); - FontSpan const font_span = par_.fontSpan(pos); - Change::Type const prev_change = par_.lookupChange(pos).type; - // first character vector str; str.reserve(100); @@ -242,11 +238,12 @@ void RowPainter::paintChars(pos_type & vpos, FontInfo const & font, str[0] = par_.transformChar(c, pos); } + pos_type const end = row_.endpos(); + FontSpan const font_span = par_.fontSpan(pos); + // Track-change status. + Change::Type const change_type = par_.lookupChange(pos).type; // selected text? - pit_type const p0 = pi_.base.bv->cursor().selBegin().pit(); - bool selection = row_.sel_beg > -1 && row_.sel_beg != row_.sel_end - && ((pit_ == p0 && (pos >= row_.sel_beg && pos < row_.sel_end)) - || (pit_ > p0 && pos < row_.sel_end)); + bool const selection = pos >= row_.sel_beg && pos < row_.sel_end; // collect as much similar chars as we can for (++vpos ; vpos < end ; ++vpos) { @@ -254,11 +251,13 @@ void RowPainter::paintChars(pos_type & vpos, FontInfo const & font, if (pos < font_span.first || pos > font_span.last) break; - if (row_.sel_beg > -1 && row_.sel_beg != row_.sel_end && - ((pit_ == p0 && pos == row_.sel_beg) || pos == row_.sel_end)) + bool const new_selection = pos >= row_.sel_beg && pos < row_.sel_end; + if (new_selection != selection) + // Selection ends or starts here. break; - if (prev_change != par_.lookupChange(pos).type) + if (change_type != par_.lookupChange(pos).type) + // Track change type has changed. break; char_type c = par_.getChar(pos); @@ -307,19 +306,20 @@ void RowPainter::paintChars(pos_type & vpos, FontInfo const & font, docstring s(&str[0], str.size()); - if (selection || prev_change != Change::UNCHANGED) { - FontInfo copy = font; - if (selection) { - copy.setColor(Color_selectiontext); - } else if (prev_change == Change::DELETED) { - copy.setColor(Color_deletedtext); - } else if (prev_change == Change::INSERTED) { - copy.setColor(Color_addedtext); - } - x_ += pi_.pain.text(int(x_), yo_, s, copy); - } else { + if (!selection && change_type == Change::UNCHANGED) { x_ += pi_.pain.text(int(x_), yo_, s, font); + return; } + + FontInfo copy = font; + if (change_type == Change::DELETED) + copy.setColor(Color_deletedtext); + else if (change_type == Change::INSERTED) + copy.setColor(Color_addedtext); + else if (selection) + copy.setColor(Color_selectiontext); + + x_ += pi_.pain.text(int(x_), yo_, s, copy); } @@ -838,8 +838,6 @@ void RowPainter::paintInlineCompletion(Font const & font) // right to left? if (rtl) { swap(s1, s2); - reverse(s1.begin(), s1.end()); - reverse(s2.begin(), s2.end()); swap(c1, c2); }