Skip to content

Commit

Permalink
Avoid change underline character and style buffers when wrap lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Dec 4, 2024
1 parent 90f96e5 commit b798b3c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
8 changes: 6 additions & 2 deletions scintilla/src/CellBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,12 @@ const char *CellBuffer::RangePointer(Sci::Position position, Sci::Position range
return substance.RangePointer(position, rangeLength);
}

const char *CellBuffer::StyleRangePointer(Sci::Position position, Sci::Position rangeLength) noexcept {
return hasStyles ? style.RangePointer(position, rangeLength) : nullptr;
int CellBuffer::CheckRange(const char *chars, const char *styles, Sci::Position position, Sci::Position rangeLength) const noexcept {
int result = substance.CheckRange(chars, position, rangeLength);
if (hasStyles) {
result |= style.CheckRange(styles, position, rangeLength);
}
return result;
}

Sci::Position CellBuffer::GapPosition() const noexcept {
Expand Down
2 changes: 1 addition & 1 deletion scintilla/src/CellBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CellBuffer {
void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept;
const char *BufferPointer();
const char *RangePointer(Sci::Position position, Sci::Position rangeLength) noexcept;
const char *StyleRangePointer(Sci::Position position, Sci::Position rangeLength) noexcept;
int CheckRange(const char *chars, const char *styles, Sci::Position position, Sci::Position rangeLength) const noexcept;
Sci::Position GapPosition() const noexcept;
SplitView AllView() const noexcept;

Expand Down
6 changes: 3 additions & 3 deletions scintilla/src/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,6 @@ class Document : PerLine, public Scintilla::IDocument, public Scintilla::ILoader
const char *RangePointer(Sci::Position position, Sci::Position rangeLength) noexcept {
return cb.RangePointer(position, rangeLength);
}
const char *StyleRangePointer(Sci::Position position, Sci::Position rangeLength) noexcept {
return cb.StyleRangePointer(position, rangeLength);
}
Sci::Position GapPosition() const noexcept {
return cb.GapPosition();
}
Expand Down Expand Up @@ -545,6 +542,9 @@ class Document : PerLine, public Scintilla::IDocument, public Scintilla::ILoader
void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept {
cb.GetStyleRange(buffer, position, lengthRetrieve);
}
int CheckRange(const char *chars, const char *styles, Sci::Position position, Sci::Position rangeLength) const noexcept {
return cb.CheckRange(chars, styles, position, rangeLength);
}
MarkerMask GetMark(Sci::Line line, bool includeChangeHistory) const noexcept;
Sci::Line MarkerNext(Sci::Line lineStart, MarkerMask mask) const noexcept;
int AddMark(Sci::Line line, int markerNum);
Expand Down
10 changes: 1 addition & 9 deletions scintilla/src/EditView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -599,15 +599,7 @@ uint64_t EditView::LayoutLine(const EditModel &model, Surface *surface, const Vi
const uint8_t *styles = ll->styles.get();

if (lineLength != 0) {
const char *docStyles = model.pdoc->StyleRangePointer(posLineStart, lineLength);
if (docStyles) { // HasStyles
allSame = memcmp(docStyles, styles, lineLength);
}

const char *docChars = model.pdoc->RangePointer(posLineStart, lineLength);
const char *chars = ll->chars.get();
// NOLINTNEXTLINE(bugprone-suspicious-string-compare)
allSame |= memcmp(docChars, chars, lineLength);
allSame = model.pdoc->CheckRange(ll->chars.get(), reinterpret_cast<const char *>(styles), posLineStart, lineLength);
}

const int styleByteLast = (posLineEnd == posLineStart) ? 0 : model.pdoc->StyleIndexAt(posLineEnd - 1);
Expand Down
28 changes: 24 additions & 4 deletions scintilla/src/SplitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,34 @@ class SplitVector {
void GetRange(T *buffer, ptrdiff_t position, ptrdiff_t retrieveLength) const noexcept {
// Split into up to 2 ranges, before and after the split then use memcpy on each.
ptrdiff_t range1Length = 0;
const T* data = body.data() + position;
if (position < part1Length) {
range1Length = std::min(retrieveLength, part1Length - position);
memcpy(buffer, data, range1Length*sizeof(T));
}
if (range1Length < retrieveLength) {
data += range1Length + gapLength;
const ptrdiff_t range2Length = retrieveLength - range1Length;
memcpy(buffer + range1Length, data, range2Length*sizeof(T));
}
}

int CheckRange(const T *buffer, ptrdiff_t position, ptrdiff_t rangeLength) const noexcept {
// Split into up to 2 ranges, before and after the split then use memcmp on each.
ptrdiff_t range1Length = 0;
int result = 0;
const T* data = body.data() + position;
std::copy_n(data, range1Length, buffer);
data += range1Length + gapLength;
const ptrdiff_t range2Length = retrieveLength - range1Length;
std::copy_n(data, range2Length, buffer + range1Length);
if (position < part1Length) {
range1Length = std::min(rangeLength, part1Length - position);
result = memcmp(data, buffer, range1Length*sizeof(T));
}
if (range1Length < rangeLength) {
data += range1Length + gapLength;
const ptrdiff_t range2Length = rangeLength - range1Length;
// NOLINTNEXTLINE(bugprone-suspicious-string-compare)
result |= memcmp(data, buffer + range1Length, range2Length*sizeof(T));
}
return result;
}

/// Compact the buffer and return a pointer to the first element.
Expand Down

0 comments on commit b798b3c

Please sign in to comment.