Skip to content

Commit

Permalink
Merge branch 'notepad-plus-plus:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
artpoli authored Dec 15, 2024
2 parents 1120d52 + 471a308 commit f2c9186
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5460,23 +5460,27 @@ wstring & Finder::prepareStringForClipboard(wstring & s) const

void Finder::copy()
{
if (_scintView.execute(SCI_GETSELECTIONS) > 1) // multi-selection
{
// don't do anything if user has made a column/rectangular selection
return;
}
const pair<size_t, size_t> lineRange = _scintView.getSelectionLinesRange();
size_t fromLine = lineRange.first;
size_t toLine = lineRange.second;

size_t fromLine = 0, toLine = 0;
if (_scintView.execute(SCI_GETSELECTIONEMPTY) || fromLine == toLine)
{
const pair<size_t, size_t> lineRange = _scintView.getSelectionLinesRange();
fromLine = lineRange.first;
toLine = lineRange.second;

// Abuse fold levels to find out which lines to copy to clipboard.
// We get the current line and then the next line which has a smaller fold level (SCI_GETLASTCHILD).
// Then we loop all lines between them and determine which actually contain search results.
const int selectedLineFoldLevel = _scintView.execute(SCI_GETFOLDLEVEL, fromLine) & SC_FOLDLEVELNUMBERMASK;
toLine = _scintView.execute(SCI_GETLASTCHILD, toLine, selectedLineFoldLevel);
if (selectedLineFoldLevel != resultLevel)
{
// caret on Search "..." header line
// or
// caret is on a line with a pathname

// locate the final resultLevel line under its parent grouping
toLine = _scintView.execute(SCI_GETLASTCHILD, fromLine, selectedLineFoldLevel);
const int toLineFoldLevel = _scintView.execute(SCI_GETFOLDLEVEL, toLine) & SC_FOLDLEVELNUMBERMASK;
if (toLineFoldLevel != resultLevel)
{
return; // the search had 0 hits, so no resultLevel lines, nothing to copy
}
}
}

std::vector<wstring> lines;
Expand Down

0 comments on commit f2c9186

Please sign in to comment.