diff options
author | Neil <nyamatongwe@gmail.com> | 2022-08-15 17:06:21 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-08-15 17:06:21 +1000 |
commit | f8236d657fd29f392c3474e96d43a2c73ea216e8 (patch) | |
tree | ac214aaad6346a7af948eb43dde77c734fa4e705 | |
parent | d93312d7c9a65b5a41bc4dbf53e81f98d5f2be1f (diff) | |
download | scintilla-mirror-f8236d657fd29f392c3474e96d43a2c73ea216e8.tar.gz |
Fix bug where deletion at line end indicated with point disappeared when text
inserted on line.
Ensure not using old data by clearing all positions - this was hiding problems
because deleted positions were still set.
-rw-r--r-- | src/EditView.cxx | 13 | ||||
-rw-r--r-- | src/PositionCache.cxx | 13 | ||||
-rw-r--r-- | src/PositionCache.h | 2 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index a40c6c3b8..a7b98e233 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -536,7 +536,7 @@ void EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSt segments.push_back(bfLayout.Next()); } - std::fill(&ll->positions[0], &ll->positions[numCharsInLine], 0.0f); + ll->ClearPositions(); if (!segments.empty()) { @@ -1238,14 +1238,13 @@ static void DrawIndicator(int indicNum, Sci::Position startPos, Sci::Position en int value, bool bidiEnabled, int tabWidthMinimumPixels) { const XYPOSITION subLineStart = ll->positions[ll->LineStart(subLine)]; + const XYPOSITION horizontalOffset = xStart - subLineStart; std::vector<PRectangle> rectangles; - const PRectangle rcIndic( - ll->positions[startPos] + xStart - subLineStart, - rcLine.top + vsDraw.maxAscent, - ll->positions[endPos] + xStart - subLineStart, - rcLine.top + vsDraw.maxAscent + 3); + const XYPOSITION left = ll->XInLine(startPos) + horizontalOffset; + const XYPOSITION right = ll->XInLine(endPos) + horizontalOffset; + const PRectangle rcIndic(left, rcLine.top + vsDraw.maxAscent, right, rcLine.top + vsDraw.maxAscent + 3); if (bidiEnabled) { ScreenLine screenLine(ll, subLine, vsDraw, rcLine.right - xStart, tabWidthMinimumPixels); @@ -1269,7 +1268,7 @@ static void DrawIndicator(int indicNum, Sci::Position startPos, Sci::Position en // Allow full descent space for character indicators rcFirstCharacter.bottom = rcLine.top + vsDraw.maxAscent + vsDraw.maxDescent; if (secondCharacter >= 0) { - rcFirstCharacter.right = ll->positions[secondCharacter] + xStart - subLineStart; + rcFirstCharacter.right = ll->XInLine(secondCharacter) + horizontalOffset; } else { // Indicator continued from earlier line so make an empty box and don't draw rcFirstCharacter.right = rcFirstCharacter.left; diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 0104b8660..d36e3e629 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -116,6 +116,10 @@ void LineLayout::Free() noexcept { bidiData.reset(); } +void LineLayout::ClearPositions() { + std::fill(&positions[0], &positions[maxLineLength + 2], 0.0f); +} + void LineLayout::Invalidate(ValidLevel validity_) noexcept { if (validity > validity_) validity = validity_; @@ -301,6 +305,15 @@ Point LineLayout::PointFromPosition(int posInLine, int lineHeight, PointEnd pe) return pt; } +XYPOSITION LineLayout::XInLine(Sci::Position index) const noexcept { + // For positions inside line return value from positions + // For positions after line return last position + 1.0 + if (index <= numCharsInLine) { + return positions[index]; + } + return positions[numCharsInLine] + 1.0; +} + int LineLayout::EndLineStyle() const noexcept { return styles[numCharsBeforeEOL > 0 ? numCharsBeforeEOL-1 : 0]; } diff --git a/src/PositionCache.h b/src/PositionCache.h index 4d44f96e4..24e4e2d5a 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -86,6 +86,7 @@ public: void Resize(int maxLineLength_); void EnsureBidiData(); void Free() noexcept; + void ClearPositions(); void Invalidate(ValidLevel validity_) noexcept; Sci::Line LineNumber() const noexcept; bool CanHold(Sci::Line lineDoc, int lineLength_) const noexcept; @@ -103,6 +104,7 @@ public: int FindBefore(XYPOSITION x, Range range) const noexcept; int FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const noexcept; Point PointFromPosition(int posInLine, int lineHeight, PointEnd pe) const noexcept; + XYPOSITION XInLine(Sci::Position index) const noexcept; int EndLineStyle() const noexcept; }; |