Skip to content

Commit

Permalink
Temporarly disable Scintilla's layout cache if word wrap is on and ta…
Browse files Browse the repository at this point in the history
…b positions are changed. Resolves issue #20.

Update version info and change log.
  • Loading branch information
Coises committed Mar 26, 2024
1 parent 39e20ae commit d1a09c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Columns++ for Notepad++ -- Releases

## Version 1.0.6 -- March 26th, 2024

* Avoid display errors that could occur when editing a wrapped line containing elastic tabstops. Under certain circumstances, an empty magenta line might appear following the edited line, or text at the end of the line might not be wrapped properly.

## Version 1.0.5 -- February 29th, 2024

* Correction to support for the new notification planned in Notepad++ 8.6.5.
Expand Down
11 changes: 11 additions & 0 deletions src/ColumnsPlusPlus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ struct ElasticProgressInfo {

static constexpr int stepSize = 100;

Scintilla::LineCache lineCache;
enum { LineCacheIgnore, LineCacheRemove, LineCacheRestore } lineCacheStatus;

ElasticProgressInfo(ColumnsPlusPlusData& data, DocumentData& dd) : data(data), dd(dd) {}

Scintilla::Line processed() const { return step * stepSize + (secondTime ? lastNeeded - firstNeeded + 1 : 0); }
Scintilla::Line objective() const { return lastNeeded - firstNeeded + (lastMonospaceFail < 0 ? 0 : lastMonospaceFail - firstNeeded + 1); }

bool analyzeTabstops();
bool setTabstops(bool stepless = false);

};


Expand Down Expand Up @@ -126,6 +130,7 @@ void ColumnsPlusPlusData::setTabstops(DocumentData& dd, Scintilla::Line firstNee
ElasticProgressInfo epi(*this, dd);
const Scintilla::Line lineCount = sci.LineCount();
const Scintilla::Line linesOnScreen = sci.LinesOnScreen();
epi.lineCacheStatus = sci.WrapMode() == Scintilla::Wrap::None ? ElasticProgressInfo::LineCacheIgnore : ElasticProgressInfo::LineCacheRemove;
if (firstNeeded == -1) {
epi.firstNeeded = sci.FirstVisibleLine();
epi.lastNeeded = std::min(epi.firstNeeded + linesOnScreen, lineCount - 1);
Expand Down Expand Up @@ -154,6 +159,7 @@ void ColumnsPlusPlusData::setTabstops(DocumentData& dd, Scintilla::Line firstNee
}
sci.PointXFromPosition(0); // This appears to clear a cache from which Scintilla may read a stale value for ChooseCaretX
sci.ChooseCaretX();
if (epi.lineCacheStatus == ElasticProgressInfo::LineCacheRestore) sci.SetLayoutCache(epi.lineCache);
}


Expand Down Expand Up @@ -209,6 +215,11 @@ bool ElasticProgressInfo::setTabstops(bool stepless) {
}
}
if (!unchanged) {
if (lineCacheStatus == LineCacheRemove) {
lineCache = sci.LayoutCache();
lineCacheStatus = LineCacheRestore;
sci.SetLayoutCache(Scintilla::LineCache::None);
}
sci.ClearTabStops(lineNum);
for (size_t i = 0; i < tabs.size(); ++i) sci.AddTabStop(lineNum, tabs[i]);
}
Expand Down
Binary file modified src/ColumnsPlusPlus.rc
Binary file not shown.

0 comments on commit d1a09c4

Please sign in to comment.