Skip to content

Commit

Permalink
Merge pull request #2510 from spnethw/fix_ctrl_add_alt_add_processing
Browse files Browse the repository at this point in the history
Fix CtrlAdd/AltAdd in consistency with full view mode (LeftCtrl-3)
  • Loading branch information
elfmz authored Dec 1, 2024
2 parents 4636286 + 1a830ef commit 69ba21c
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions far2l/src/panels/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,30 +3338,46 @@ long FileList::SelectFiles(int Mode, const wchar_t *Mask)
CurPtr = ListData[CurFile];
FARString strCurName = CurPtr->strName;

bool SkipPath = false;

if (Mode == SELECT_ADDEXT || Mode == SELECT_REMOVEEXT) {
if (strCurName == L"..")
return 0;
strCurName = PointToName(strCurName);
size_t pos;

if (strCurName.RPos(pos, L'.')) {
if (strCurName.RPos(pos, L'.') && pos != strCurName.GetLength() - 1 && pos != 0) {
// Учтем тот момент, что расширение может содержать символы-разделители
strRawMask.Format(L"\"*.%ls\"", strCurName.CPtr() + pos + 1);
strRawMask.Format(L"\"?*.%ls\"", strCurName.CPtr() + pos + 1);
WrapBrackets = true;

} else {
strMask = L"*.";
// file without extension, e.g.: "readme", ".readme" & "readme."
strMask = L"/^(?:[^.]+|\\.[^.]+|.+\\.)$/";
}

SkipPath = true;
Mode = (Mode == SELECT_ADDEXT) ? SELECT_ADD : SELECT_REMOVE;
} else {
if (Mode == SELECT_ADDNAME || Mode == SELECT_REMOVENAME) {
// Учтем тот момент, что имя может содержать символы-разделители
strRawMask = L"\"";
strRawMask+= strCurName;
if (strCurName == L"..")
return 0;
strCurName = PointToName(strCurName);

size_t pos;

if (strRawMask.RPos(pos, L'.') && pos != strRawMask.GetLength() - 1)
strRawMask.Truncate(pos);
if (strCurName.RPos(pos, L'.') && pos != strCurName.GetLength() - 1 && pos != 0) {
strCurName.Truncate(pos);
}

strRawMask+= L".*\"";
WrapBrackets = true;
auto fName = EscapeCmdStr(strCurName.CPtr(), L".^$*+-?()[]{}\\|"); // special PCRE characters

bool allowEmptyExtension = (!strCurName.RPos(pos, '.') || (pos == 0 || pos == strCurName.GetLength() - 1));
bool caseSensitive = Opt.PanelCaseSensitiveCompareSelect;

strMask.Format(L"/^%ls(?:\\.[^.]+)%ls$/", fName.c_str(), allowEmptyExtension ? L"?" : L"");
if (!caseSensitive) strMask+=L"i";

SkipPath = true;
Mode = (Mode == SELECT_ADDNAME) ? SELECT_ADD : SELECT_REMOVE;
} else {
if (Mode == SELECT_ADD || Mode == SELECT_REMOVE) {
Expand Down Expand Up @@ -3446,7 +3462,7 @@ long FileList::SelectFiles(int Mode, const wchar_t *Mask)
if (bUseFilter)
Match = Filter.FileInFilter(*CurPtr);
else {
Match = FileMask.Compare(CurPtr->strName, !Opt.PanelCaseSensitiveCompareSelect, false);
Match = FileMask.Compare(CurPtr->strName, !Opt.PanelCaseSensitiveCompareSelect, SkipPath);
}
}

Expand Down

0 comments on commit 69ba21c

Please sign in to comment.