Prevent corruption possibility when using -p command line parameter

Fix #9142, close #9143
This commit is contained in:
Scott Sumner 2020-11-12 20:25:22 -05:00 committed by Don HO
parent b54b8ee54f
commit 26428bd2ba
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

View File

@ -5918,24 +5918,28 @@ std::vector<generic_string> Notepad_plus::loadCommandlineParams(const TCHAR * co
} }
if (ln != -1 || cpos != -1) if (ln != -1 || cpos != -1)
{ //we have to move the cursor manually {
//we have to move the cursor manually
int iView = currentView(); //store view since fileswitch can cause it to change int iView = currentView(); //store view since fileswitch can cause it to change
switchToFile(bufID); //switch to the file. No deferred loading, but this way we can easily move the cursor to the right position switchToFile(bufID); //switch to the file. No deferred loading, but this way we can easily move the cursor to the right position
if (cpos != -1) if (cpos != -1)
{ {
// make sure not jumping into the middle of a multibyte character
// or into the middle of a CR/LF pair for Windows files
auto before = _pEditView->execute(SCI_POSITIONBEFORE, cpos);
cpos = static_cast<int>(_pEditView->execute(SCI_POSITIONAFTER, before));
_pEditView->execute(SCI_GOTOPOS, cpos); _pEditView->execute(SCI_GOTOPOS, cpos);
} }
else else if (cn == -1)
if (cn == -1)
{ {
_pEditView->execute(SCI_GOTOLINE, ln-1); _pEditView->execute(SCI_GOTOLINE, ln-1);
} }
else else
{ {
auto pos = _pEditView->execute(SCI_FINDCOLUMN, ln-1, cn-1); auto pos = _pEditView->execute(SCI_FINDCOLUMN, ln-1, cn-1);
_pEditView->execute(SCI_GOTOPOS, pos); _pEditView->execute(SCI_GOTOPOS, pos);
} }
_pEditView->scrollPosToCenter(_pEditView->execute(SCI_GETCURRENTPOS)); _pEditView->scrollPosToCenter(_pEditView->execute(SCI_GETCURRENTPOS));