Skip to content

Commit

Permalink
Fixes an error that caused elastic tabstops processing to be applied …
Browse files Browse the repository at this point in the history
…after Replace All or Replace All in All Opened Documents in Notepad++ Search whether elastic tabstops are enabled or not.

Fix some omissions that caused failure to apply elastic tabstops processing to both views when the same document is shown in both views.

Update changelog and set version 1.1.1.
  • Loading branch information
Coises committed May 23, 2024
1 parent 26fa8ed commit b19b7ea
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Columns++ for Notepad++ -- Releases

## Version 1.1.1 -- May 23rd, 2024

* Fixed an error that caused elastic tabstop processing to be applied after using **Replace All** or **Replace All in All Opened Documents** in the Notepad++ **Search** dialog when elastic tabstops is not enabled. Expected to resolve issue #24. (Note: This error has been present since Columns++ version 1.0.4 when used with Notepad++ versions 8.6.5 or greater.)

* Fixed some errors that could cause elastic tabstops layout to fail to update properly in the inactive view when the same document is visible in both views.

## Version 1.1 -- May 21st, 2024

### Fixes and improvements:
Expand Down
54 changes: 46 additions & 8 deletions src/ColumnsPlusPlus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,30 @@ bool ElasticProgressInfo::setTabstops(bool stepless) {


void ColumnsPlusPlusData::analyzeTabstops(DocumentData& dd) {
ElasticProgressInfo epi(*this, dd);
if (!epi.lineTabsSet) return;
dd.elasticAnalysisRequired = false;
dd.deleteWithoutLayoutChange = false;
dd.width24b = sci.TextWidth(STYLE_DEFAULT, " ");
dd.width24d = sci.TextWidth(STYLE_DEFAULT, "123456789012345678901234");
dd.width24w = sci.TextWidth(STYLE_DEFAULT, "WWWWWWWWWWWWWWWWWWWWWWWW");
dd.assumeMonospace = dd.settings.monospace == ElasticTabsProfile::MonospaceBest ? guessMonospaced()
: dd.settings.monospace == ElasticTabsProfile::MonospaceAlways;
int ccsym = settings.monospaceNoMnemonics && dd.assumeMonospace ? '!' : 0;
if (sci.ControlCharSymbol() != ccsym) sci.SetControlCharSymbol(ccsym);
ElasticProgressInfo epi(*this, dd);
if (epi.lineTabsSet) epi.lineTabsSet->assign(sci.LineCount(), 0);
const int ccsym = settings.monospaceNoMnemonics && dd.assumeMonospace ? '!' : 0;
const Scintilla::Line lineCount = sci.LineCount();
if (bothViewsShowSameDocument()) {
view1TabsSet.assign(lineCount, 0);
view2TabsSet.assign(lineCount, 0);
SendMessage(nppData._scintillaMainHandle , SCI_SETCONTROLCHARSYMBOL, ccsym, 0);
SendMessage(nppData._scintillaSecondHandle, SCI_SETCONTROLCHARSYMBOL, ccsym, 0);
}
else {
sci.SetControlCharSymbol(ccsym);
epi.lineTabsSet->assign(lineCount, 0);
}
epi.isAnalyze = true;
epi.firstNeeded = 0;
epi.lastNeeded = sci.LineCount() - 1;
epi.lastNeeded = lineCount - 1;
unsigned long long before, after;
before = GetTickCount64();
double timeLimit = elasticProgressTime;
Expand Down Expand Up @@ -432,7 +442,11 @@ void ColumnsPlusPlusData::scnModified(const Scintilla::NotificationData* scnp) {
if (width > tlb->width) {
tlb->width = width;
auto lineTabsSet = getLineTabsSet();
if (lineTabsSet) for (Scintilla::Line ln = tlb->firstLine; ln <= tlb->lastLine; ++ln) (*lineTabsSet)[ln] = 0;
if (lineTabsSet) {
if (bothViewsShowSameDocument())
for (Scintilla::Line ln = tlb->firstLine; ln <= tlb->lastLine; ++ln) view1TabsSet[ln] = view2TabsSet[ln] = 0;
else for (Scintilla::Line ln = tlb->firstLine; ln <= tlb->lastLine; ++ln) (*lineTabsSet)[ln] = 0;
}
}
}
return;
Expand Down Expand Up @@ -609,9 +623,15 @@ void ColumnsPlusPlusData::modifyAll(const NMHDR* nmhdr) {
bool visible2 = cdi2 < 0 ? false : bufferID == static_cast<UINT_PTR>(SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, cdi2, 1));
if (visible1 || visible2) {
DocumentData* ddp = getDocument(visible1 ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle);
if (!ddp) return;
if (!ddp || !ddp->settings.elasticEnabled) return;
analyzeTabstops(*ddp);
setTabstops(*ddp);
if (visible1 && visible2) {
activeScintilla = nppData._scintillaSecondHandle;
pointerScintilla = SendMessage(activeScintilla, static_cast<UINT>(Scintilla::Message::GetDirectPointer), 0, 0);
sci.SetFnPtr(directStatusScintilla, pointerScintilla);
setTabstops(*ddp);
}
}
else for (auto i = documents.begin(); i != documents.end(); ++i) if (i->second.buffer == bufferID) {
DocumentData& dd = i->second;
Expand All @@ -634,13 +654,31 @@ void ColumnsPlusPlusData::toggleElasticEnabled() {
sci.SetTabIndents(0);
analyzeTabstops(*ddp);
setTabstops(*ddp);
} else {
}
else {
if (settings.overrideTabSize) sci.SetTabWidth(ddp->tabOriginal);
sci.SetTabIndents(1);
if (sci.ControlCharSymbol()) sci.SetControlCharSymbol(0);
Scintilla::Line lineCount = sci.LineCount();
for (Scintilla::Line lineNum = 0; lineNum < lineCount; ++lineNum) sci.ClearTabStops(lineNum);
}
if (bothViewsShowSameDocument()) {
activeScintilla = activeScintilla == nppData._scintillaMainHandle ? nppData._scintillaSecondHandle : nppData._scintillaMainHandle;
pointerScintilla = SendMessage(activeScintilla, static_cast<UINT>(Scintilla::Message::GetDirectPointer), 0, 0);
sci.SetFnPtr(directStatusScintilla, pointerScintilla);
if (settings.elasticEnabled) {
if (settings.overrideTabSize) sci.SetTabWidth(settings.minimumOrLeadingTabSize);
sci.SetTabIndents(0);
setTabstops(*ddp);
}
else {
if (settings.overrideTabSize) sci.SetTabWidth(ddp->tabOriginal);
sci.SetTabIndents(1);
if (sci.ControlCharSymbol()) sci.SetControlCharSymbol(0);
Scintilla::Line lineCount = sci.LineCount();
for (Scintilla::Line lineNum = 0; lineNum < lineCount; ++lineNum) sci.ClearTabStops(lineNum);
}
}
}


Expand Down
7 changes: 7 additions & 0 deletions src/ColumnsPlusPlus.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ class ColumnsPlusPlusData {

DocumentData* getDocument(const Scintilla::NotificationData* scnp) { return getDocument(reinterpret_cast<HWND>(scnp->nmhdr.hwndFrom)); }

bool bothViewsShowSameDocument() {
intptr_t cdi1 = SendMessage(nppData._nppHandle, NPPM_GETCURRENTDOCINDEX, 0, 0);
intptr_t cdi2 = SendMessage(nppData._nppHandle, NPPM_GETCURRENTDOCINDEX, 0, 1);
if (cdi1 < 0 || cdi2 < 0) return false;
return SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, cdi1, 0) == SendMessage(nppData._nppHandle, NPPM_GETBUFFERIDFROMPOS, cdi2, 1);
}

std::vector<char>* getLineTabsSet() {
if (activeScintilla == nppData._scintillaMainHandle ) return &view1TabsSet;
if (activeScintilla == nppData._scintillaSecondHandle) return &view2TabsSet;
Expand Down
Binary file modified src/ColumnsPlusPlus.rc
Binary file not shown.

0 comments on commit b19b7ea

Please sign in to comment.