#include "support/debug.h"
#include "support/textutils.h"
-#include "support/assert.h"
+#include "support/lassert.h"
#include <boost/crc.hpp>
-#include <ostream>
-
using namespace std;
namespace lyx {
{
// 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<char_type> str;
str.reserve(100);
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) {
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);
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 (selection)
+ copy.setColor(Color_selectiontext);
+ else if (change_type == Change::DELETED)
+ copy.setColor(Color_deletedtext);
+ else if (change_type == Change::INSERTED)
+ copy.setColor(Color_addedtext);
+
+ x_ += pi_.pain.text(int(x_), yo_, s, copy);
}
// right to left?
if (rtl) {
swap(s1, s2);
- reverse(s1.begin(), s1.end());
- reverse(s2.begin(), s2.end());
swap(c1, c2);
}