Improve Copy-Selected-Lines

Follow the spec: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/15803#issuecomment-2515580625

Fix #15803, close #15854
This commit is contained in:
Alan Kilborn 2024-11-25 20:17:22 -05:00 committed by Don Ho
parent 10ae99e790
commit 471a308bca

View File

@ -5459,24 +5459,28 @@ 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;
}
size_t fromLine = 0, toLine = 0;
{
const pair<size_t, size_t> lineRange = _scintView.getSelectionLinesRange();
fromLine = lineRange.first;
toLine = lineRange.second;
size_t fromLine = lineRange.first;
size_t 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.
if (_scintView.execute(SCI_GETSELECTIONEMPTY) || fromLine == toLine)
{
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;