Skip to content

Commit

Permalink
enhanced Workaround for N++ bug for highlighting last rows
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Jan 27, 2025
1 parent 580b629 commit cd8d197
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
34 changes: 12 additions & 22 deletions src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7012,7 +7012,7 @@ void MultiReplace::handleHighlightColumnsInDocument() {

// Iterate over each line's delimiter positions
for (LRESULT line = 0; line < totalLines; ++line) {
highlightColumnsInLine(line, totalLines);
highlightColumnsInLine(line);
}

// Show Row and Column Position
Expand All @@ -7026,24 +7026,16 @@ void MultiReplace::handleHighlightColumnsInDocument() {

}

void MultiReplace::highlightColumnsInLine(LRESULT line, LRESULT totalLines) {
void MultiReplace::highlightColumnsInLine(LRESULT line) {
const auto& lineInfo = lineDelimiterPositions[line];

// If the line length is zero, there's nothing to highlight
if (lineInfo.lineLength == 0) {
return; // It's an empty line, so exit early
}

// Determine if this is the last line in the document
bool isLastLine = (line == static_cast<LRESULT>(totalLines) - 1);

// Prepare a vector for styles
// If not the last line, exclude EOL from styling by subtracting eolLength
size_t styleLength = static_cast<size_t>(lineInfo.lineLength);
if (!isLastLine && eolLength > 0 && styleLength >= static_cast<size_t>(eolLength)) {
styleLength -= static_cast<size_t>(eolLength); // Exclude EOL from styling
}
std::vector<char> styles(styleLength, 0);
// Prepare a vector for styles (size = entire line length, including EOL)
std::vector<char> styles(static_cast<size_t>(lineInfo.lineLength), 0);

// If no delimiter present, highlight whole line as first column
if (lineInfo.positions.empty() &&
Expand All @@ -7070,7 +7062,7 @@ void MultiReplace::highlightColumnsInLine(LRESULT line, LRESULT totalLines) {
}

if (column == lineInfo.positions.size() + 1) {
end = lineInfo.lineLength - (isLastLine ? 0 : eolLength); // Exclude EOL if not last line
end = lineInfo.lineLength;
}
else {
end = lineInfo.positions[column - 1].offsetInLine;
Expand All @@ -7090,7 +7082,7 @@ void MultiReplace::highlightColumnsInLine(LRESULT line, LRESULT totalLines) {

// Apply the styles to Scintilla
send(SCI_STARTSTYLING, lineStartPos, 0);
send(SCI_SETSTYLINGEX, static_cast<int>(styles.size()), reinterpret_cast<sptr_t>(styles.data()));
send(SCI_SETSTYLINGEX, styles.size(), reinterpret_cast<sptr_t>(styles.data()));
}

void MultiReplace::handleClearColumnMarks() {
Expand Down Expand Up @@ -7133,9 +7125,6 @@ void MultiReplace::processLogForDelimiters()

std::vector<LogEntry> modifyLogEntries;

// Retrieve total number of lines once
LRESULT totalLines = send(SCI_GETLINECOUNT, 0, 0);

// Loop through the log entries in chronological order
for (auto& logEntry : logChanges) {
switch (logEntry.changeType) {
Expand Down Expand Up @@ -7185,17 +7174,18 @@ void MultiReplace::processLogForDelimiters()
updateDelimitersInDocument(static_cast<int>(modifyLogEntry.lineNumber), ChangeType::Modify);
if (isColumnHighlighted) {
//clearMarksInLine(modifyLogEntry.lineNumber);
highlightColumnsInLine(modifyLogEntry.lineNumber, totalLines);
highlightColumnsInLine(modifyLogEntry.lineNumber);
}
//this->messageBoxContent += "Line " + std::to_string(static_cast<int>(modifyLogEntry.lineNumber)) + " modified.\n";
}
}

// Workaround: Highlight last line to fix N++ bug causing loss of styling on last character whwn modification in any other line
// Workaround: Highlight last lines to fix N++ bug causing loss of styling on last character when modification in any other line
if (isColumnHighlighted) {
LRESULT lastLine = send(SCI_GETLINECOUNT, 0, 0) - 1;
if (lastLine >= 0) {
highlightColumnsInLine(lastLine, totalLines);
size_t lastLine = lineDelimiterPositions.size();
if (lastLine >= 2) {
highlightColumnsInLine(lastLine-2);
highlightColumnsInLine(lastLine-1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ class MultiReplace : public StaticDialog
ColumnInfo getColumnInfo(LRESULT startPosition);
void initializeColumnStyles();
void handleHighlightColumnsInDocument();
void highlightColumnsInLine(LRESULT line, LRESULT totalLines);
void highlightColumnsInLine(LRESULT line);
void handleClearColumnMarks();
std::wstring addLineAndColumnMessage(LRESULT pos);
void updateDelimitersInDocument(SIZE_T lineNumber, ChangeType changeType);
Expand Down

0 comments on commit cd8d197

Please sign in to comment.