Skip to content

Commit

Permalink
Weekly Scintilla sync up.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Dec 8, 2024
1 parent 850b8c5 commit 5bbf685
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 75 deletions.
13 changes: 6 additions & 7 deletions scintilla/src/CaseFolder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ CaseFolderTable::CaseFolderTable() noexcept {
size_t CaseFolderTable::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) {
if (lenMixed > sizeFolded) {
return 0;
} else {
for (size_t i = 0; i < lenMixed; i++) {
folded[i] = mapping[IndexFromChar(mixed[i])];
}
return lenMixed;
}
for (size_t i = 0; i < lenMixed; i++) {
folded[i] = mapping[IndexFromChar(mixed[i])];
}
return lenMixed;
}

void CaseFolderTable::SetTranslation(char ch, char chTranslation) noexcept {
mapping[static_cast<unsigned char>(ch)] = chTranslation;
mapping[IndexFromChar(ch)] = chTranslation;
}

CaseFolderUnicode::CaseFolderUnicode() {
Expand All @@ -53,7 +52,7 @@ CaseFolderUnicode::CaseFolderUnicode() {

size_t CaseFolderUnicode::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) {
if ((lenMixed == 1) && (sizeFolded > 0)) {
folded[0] = mapping[static_cast<unsigned char>(mixed[0])];
folded[0] = mapping[IndexFromChar(mixed[0])];
return 1;
} else {
return converter->CaseConvertString(folded, sizeFolded, mixed, lenMixed);
Expand Down
58 changes: 32 additions & 26 deletions scintilla/src/CellBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class ILineVector {
using namespace Scintilla;
using namespace Scintilla::Internal;

namespace {

template <typename POS>
class LineStartIndex final {
// line_cast(): cast Sci::Line to either 32-bit or 64-bit value
Expand Down Expand Up @@ -334,28 +336,23 @@ class LineVector final : public ILineVector {
}
};

SplitView::SplitView(const SplitVector<char> &instance) noexcept {
length = instance.Length();
length1 = instance.GapPosition();
if (length1 == 0) {
// Assign segment2 to segment1 / length1 to avoid useless test against 0 length1
length1 = length;
}
segment1 = instance.ElementPointer(0);
segment2 = instance.ElementPointer(length1) - length1;
std::unique_ptr<ILineVector> LineVectorCreate(bool largeDocument) {
if (largeDocument)
return std::make_unique<LineVector<Sci::Position>>();
else
return std::make_unique<LineVector<int>>();
}

}

CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) :
hasStyles(hasStyles_), largeDocument(largeDocument_) {
hasStyles(hasStyles_), largeDocument(largeDocument_),
uh{std::make_unique<UndoHistory>()},
plv{LineVectorCreate(largeDocument_)} {
readOnly = false;
utf8Substance = false;
utf8LineEnds = LineEndType::Default;
collectingUndo = true;
uh = std::make_unique<UndoHistory>();
if (largeDocument)
plv = std::make_unique<LineVector<Sci::Position>>();
else
plv = std::make_unique<LineVector<int>>();
}

CellBuffer::~CellBuffer() noexcept = default;
Expand All @@ -364,10 +361,6 @@ char CellBuffer::CharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
}

unsigned char CellBuffer::UCharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
}

void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept {
if ((position | lengthRetrieve) <= 0) {
return;
Expand Down Expand Up @@ -425,7 +418,18 @@ Sci::Position CellBuffer::GapPosition() const noexcept {
}

SplitView CellBuffer::AllView() const noexcept {
return SplitView(substance);
const size_t length = substance.Length();
size_t length1 = substance.GapPosition();
if (length1 == 0) {
// Assign segment2 to segment1 / length1 to avoid useless test against 0 length1
length1 = length;
}
return SplitView {
substance.ElementPointer(0),
length1,
substance.ElementPointer(length1) - length1,
length
};
}

// The char* returned is to an allocation owned by the undo history
Expand Down Expand Up @@ -705,7 +709,7 @@ void CellBuffer::ResetLineEnds() {
unsigned char chBeforePrev = 0;
unsigned char chPrev = 0;
for (Sci::Position i = 0; i < length; i++) {
const unsigned char ch = substance.ValueAt(position + i);
const unsigned char ch = substance[position + 1];
if (ch == '\r') {
InsertLine(lineInsert, (position + i) + 1, atLineStart);
lineInsert++;
Expand Down Expand Up @@ -1260,11 +1264,13 @@ void CellBuffer::BasicDeleteChars(const Sci::Position position, const Sci::Posit
} else {
RemoveLine(lineRemove);
}
} else if (utf8LineEnds != LineEndType::Default && !UTF8IsAscii(ch)) {
const unsigned char next3[3] = { ch, chNext,
static_cast<unsigned char>(substance.ValueAt(position + i + 2)) };
if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) {
RemoveLine(lineRemove);
} else if (utf8LineEnds != LineEndType::Default) {
if (!UTF8IsAscii(ch)) {
const unsigned char next3[3] = { ch, chNext,
static_cast<unsigned char>(substance.ValueAt(position + i + 2)) };
if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) {
RemoveLine(lineRemove);
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions scintilla/src/CellBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ struct SplitView {
const char *segment2 = nullptr;
size_t length = 0;

SplitView(const SplitVector<char> &instance) noexcept;

char operator[](size_t position) const noexcept {
if (position < length1) {
return segment1[position];
Expand Down Expand Up @@ -84,11 +82,11 @@ class CellBuffer {
SplitVector<char> style;

bool collectingUndo;
std::unique_ptr<UndoHistory> uh;
const std::unique_ptr<UndoHistory> uh;

std::unique_ptr<ChangeHistory> changeHistory;

std::unique_ptr<ILineVector> plv;
const std::unique_ptr<ILineVector> plv;

bool UTF8LineEndOverlaps(Sci::Position position) const noexcept;
bool UTF8IsCharacterBoundary(Sci::Position position) const;
Expand All @@ -110,7 +108,9 @@ class CellBuffer {

/// Retrieving positions outside the range of the buffer works and returns 0
char CharAt(Sci::Position position) const noexcept;
unsigned char UCharAt(Sci::Position position) const noexcept;
unsigned char UCharAt(Sci::Position position) const noexcept {
return CharAt(position);
}
void GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept;
char StyleAt(Sci::Position position) const noexcept;
void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const noexcept;
Expand Down
5 changes: 2 additions & 3 deletions scintilla/src/Document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ CharacterExtracted::CharacterExtracted(const unsigned char *charBytes, size_t wi

Document::Document(DocumentOption options) :
cb(!FlagSet(options, DocumentOption::StylesNone), FlagSet(options, DocumentOption::TextLarge)),
durationStyleOneUnit(1e-6) {
durationStyleOneUnit(1e-6),
decorations{DecorationListCreate(IsLarge())} {

perLineData[ldMarkers] = std::make_unique<LineMarkers>();
perLineData[ldLevels] = std::make_unique<LineLevels>();
Expand All @@ -151,8 +152,6 @@ Document::Document(DocumentOption options) :
perLineData[ldAnnotation] = std::make_unique<LineAnnotation>();
perLineData[ldEOLAnnotation] = std::make_unique<LineAnnotation>();

decorations = DecorationListCreate(IsLarge());

cb.SetPerLine(this);
cb.SetUTF8Substance(CpUtf8 == dbcsCodePage);
}
Expand Down
2 changes: 1 addition & 1 deletion scintilla/src/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Document : PerLine, public Scintilla::IDocument, public Scintilla::ILoader
uint8_t asciiBackwardSafeChar = 0xff;
ActionDuration durationStyleOneUnit;

std::unique_ptr<IDecorationList> decorations;
const std::unique_ptr<IDecorationList> decorations;

explicit Document(Scintilla::DocumentOption options);
// Deleted so Document objects can not be copied.
Expand Down
7 changes: 4 additions & 3 deletions scintilla/src/EditModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ using namespace Scintilla::Internal;
Caret::Caret() noexcept :
active(false), on(false), period(500) {}

EditModel::EditModel() : durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0.01 / 16) {
EditModel::EditModel() :
reprs{std::make_unique<SpecialRepresentations>()},
pcs{ContractionStateCreate(false)},
durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0.01 / 16) {
inOverstrike = false;
trackLineWidth = false;
hasFocus = false;
Expand All @@ -77,11 +80,9 @@ EditModel::EditModel() : durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0
hotspotSingleLine = true;
hoverIndicatorPos = Sci::invalidPosition;
wrapWidth = LineLayout::wrapWidthInfinite;
reprs = std::make_unique<SpecialRepresentations>();
// before setting a lexer, style buffer is useless.
pdoc = new Document(DocumentOption::StylesNone);
pdoc->AddRef();
pcs = ContractionStateCreate(pdoc->IsLarge());

SYSTEM_INFO info;
GetNativeSystemInfo(&info);
Expand Down
2 changes: 1 addition & 1 deletion scintilla/src/EditModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EditModel {
bool primarySelection;
int xOffset; ///< Horizontal scrolled amount in pixels

std::unique_ptr<SpecialRepresentations> reprs;
const std::unique_ptr<SpecialRepresentations> reprs;
Caret caret;
SelectionPosition posDrag;
Sci::Position braces[2];
Expand Down
12 changes: 8 additions & 4 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,14 @@ void Editor::RedrawSelMargin(Sci::Line line, bool allAfter) noexcept {
}

PRectangle Editor::RectangleFromRange(Range r, int overlap) const noexcept {
const Sci::Line minLine = pcs->DisplayFromDoc(
pdoc->SciLineFromPosition(r.First()));
const Sci::Line maxLine = pcs->DisplayLastFromDoc(
pdoc->SciLineFromPosition(r.Last()));
const Sci::Line docLineFirst = pdoc->SciLineFromPosition(r.First());
const Sci::Line minLine = pcs->DisplayFromDoc(docLineFirst);
Sci::Line docLineLast = docLineFirst; // Common case where range is wholly in one document line
if (r.Last() >= pdoc->LineStart(docLineFirst + 1)) {
// Range covers multiple lines so need last line
docLineLast = pdoc->SciLineFromPosition(r.Last());
}
const Sci::Line maxLine = pcs->DisplayLastFromDoc(docLineLast);
const PRectangle rcClientDrawing = GetClientDrawingRectangle();
PRectangle rc;
const int leftTextOverlap = ((xOffset == 0) && (vs.leftMarginWidth > 0)) ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion scintilla/src/Partitioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Partitioning {
T upper = partition;
do {
const T middle = (upper + lower + 1) / 2; // Round high
T posMiddle = body.ValueAt(middle);
T posMiddle = body[middle];
if (middle > stepPartition)
posMiddle += stepLength;
if (pos < posMiddle) {
Expand Down
6 changes: 3 additions & 3 deletions scintilla/src/PerLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LineLevels final : public PerLine {
SplitVector<int> levels;
Scintilla::FoldLevel GetFoldLevel(Sci::Line line) const noexcept;
public:
LineLevels() = default;
LineLevels() noexcept = default;
void Init() override;
bool IsActive() const noexcept override;
void InsertLine(Sci::Line line) override;
Expand All @@ -80,7 +80,7 @@ class LineLevels final : public PerLine {
class LineState final : public PerLine {
SplitVector<int> lineStates;
public:
LineState() = default;
LineState() noexcept = default;
void Init() override;
bool IsActive() const noexcept override;
void InsertLine(Sci::Line line) override;
Expand All @@ -94,7 +94,7 @@ class LineState final : public PerLine {
class LineAnnotation : public PerLine {
SplitVector<std::unique_ptr<char[]>> annotations;
public:
LineAnnotation() = default;
LineAnnotation() noexcept = default;

[[nodiscard]] bool Empty() const noexcept;
void Init() override;
Expand Down
2 changes: 1 addition & 1 deletion scintilla/src/PositionCache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,
//printf("USE line=%zd/%zd, caret=%zd/%zd top=%zd, pos=%zu, clock=%d\n",
// lineNumber, ret->lineNumber, lineCaret, lastCaretSlot, topLine, pos, styleClock_);
ret->Free();
new (ret) LineLayout(lineNumber, maxChars);
::new (ret) LineLayout(lineNumber, maxChars);
} else {
//printf("HIT line=%zd, caret=%zd/%zd top=%zd, pos=%zu, clock=%d, validity=%d\n",
// lineNumber, lineCaret, lastCaretSlot, topLine, pos, styleClock_, ret->validity);
Expand Down
26 changes: 20 additions & 6 deletions scintilla/src/RunStyles.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ void RunStyles<DISTANCE, STYLE>::RemoveRunIfSameAsPrevious(DISTANCE run) {

template <typename DISTANCE, typename STYLE>
RunStyles<DISTANCE, STYLE>::RunStyles() {
starts = Partitioning<DISTANCE>(8);
styles = SplitVector<STYLE>();
styles.InsertValue(0, 2, 0);
}

Expand Down Expand Up @@ -137,7 +135,8 @@ FillResult<DISTANCE> RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE position, ST
return resultNoChange;
}
DISTANCE runEnd = RunFromPosition(end);
if (styles.ValueAt(runEnd) == value) {
const STYLE valueCurrent = styles.ValueAt(runEnd);
if (valueCurrent == value) {
// End already has value so trim range.
end = starts.PositionFromPartition(runEnd);
if (position >= end) {
Expand All @@ -146,6 +145,22 @@ FillResult<DISTANCE> RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE position, ST
}
fillLength = end - position;
} else {
const DISTANCE startRun = starts.PositionFromPartition(runEnd);
if (position > startRun) {
const DISTANCE runNext = runEnd + 1;
const DISTANCE endRun = starts.PositionFromPartition(runNext);
if (end < endRun) {
// New piece is completely inside a run with a different value so its a simple
// insertion of two points [ (position, value), (end, valueCurrent) ]
const DISTANCE range[] { position, end};
starts.InsertPartitions(runEnd + 1, range, 2);
// Temporary runEndIndex silences non-useful arithmetic overflow warnings
const ptrdiff_t runEndIndex = runEnd;
styles.Insert(runEndIndex + 1, value);
styles.Insert(runEndIndex + 2, valueCurrent);
return { true, position, fillLength };
}
}
runEnd = SplitRun(end);
}
DISTANCE runStart = RunFromPosition(position);
Expand Down Expand Up @@ -173,9 +188,8 @@ FillResult<DISTANCE> RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE position, ST
runEnd = RunFromPosition(end);
RemoveRunIfEmpty(runEnd);
return result;
} else {
return resultNoChange;
}
return resultNoChange;
}

template <typename DISTANCE, typename STYLE>
Expand Down Expand Up @@ -214,7 +228,7 @@ void RunStyles<DISTANCE, STYLE>::InsertSpace(DISTANCE position, DISTANCE insertL

template <typename DISTANCE, typename STYLE>
void RunStyles<DISTANCE, STYLE>::DeleteAll() {
starts = Partitioning<DISTANCE>(8);
starts = Partitioning<DISTANCE>();
styles = SplitVector<STYLE>();
styles.InsertValue(0, 2, 0);
}
Expand Down
4 changes: 1 addition & 3 deletions scintilla/src/SparseVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class SparseVector {

public:
SparseVector() {
starts = Partitioning<Sci::Position>(8);
values = SplitVector<T>();
values.InsertEmpty(0, 2);
}

Expand Down Expand Up @@ -177,7 +175,7 @@ class SparseVector {
}

void DeleteAll() {
starts = Partitioning<Sci::Position>(8);
starts = Partitioning<Sci::Position>();
values = SplitVector<T>();
values.InsertEmpty(0, 2);
}
Expand Down
Loading

0 comments on commit 5bbf685

Please sign in to comment.