@@ -343,7 +343,7 @@ namespace
343
343
344
344
MapsFileInfoList::iterator it = lists.begin ();
345
345
for ( ; it != lists.end (); ++it ) {
346
- if ( ( *it ). filename == lastfile ) {
346
+ if ( it-> filename == lastfile ) {
347
347
break ;
348
348
}
349
349
}
@@ -422,12 +422,11 @@ namespace
422
422
const size_t lengthLimit{ 255 };
423
423
424
424
LocalEvent & le = LocalEvent::Get ();
425
- bool listUpdated = false ;
426
425
427
426
while ( le.HandleEvents () && result.empty () ) {
428
427
buttonOk.drawOnState ( le.isMouseLeftButtonPressedAndHeldInArea ( buttonOk.area () ) );
429
428
buttonCancel.drawOnState ( le.isMouseLeftButtonPressedAndHeldInArea ( buttonCancel.area () ) );
430
- buttonSort.drawOnState (le.isMouseLeftButtonPressedAndHeldInArea (buttonSort.area ()) );
429
+ buttonSort.drawOnState ( le.isMouseLeftButtonPressedAndHeldInArea ( buttonSort.area () ) );
431
430
if ( isEditing ) {
432
431
buttonVirtualKB->drawOnState ( le.isMouseLeftButtonPressedAndHeldInArea ( buttonVirtualKB->area () ) );
433
432
}
@@ -443,6 +442,7 @@ namespace
443
442
bool isListboxSelected = listbox.isSelected ();
444
443
445
444
bool needRedraw = ( listId != listbox.getCurrentId () );
445
+ bool listUpdated = false ;
446
446
447
447
if ( le.isKeyPressed ( fheroes2::Key::KEY_DELETE ) && isListboxSelected ) {
448
448
listbox.SetCurrent ( listId );
@@ -483,10 +483,31 @@ namespace
483
483
}
484
484
}
485
485
else if ( le.MouseClickLeft ( buttonSort.area () ) ) {
486
+ const int currentId = listbox.getCurrentId ();
487
+
486
488
settings.CycleSaveFileSortType ();
487
489
(void )settings.Save ( Settings::configFileName );
488
490
sortMapInfos ( lists );
489
491
listUpdated = true ;
492
+
493
+ // re-select the last selected file if any, unless we're typing in the list box
494
+ if ( !filename.empty () && !isListboxSelected ) {
495
+ const std::string lastChoice = System::concatPath ( Game::GetSaveDir (), filename + Game::GetSaveFileExtension () );
496
+
497
+ MapsFileInfoList::const_iterator it = lists.cbegin ();
498
+ for ( ; it != lists.end (); ++it ) {
499
+ if ( it->filename == lastChoice ) {
500
+ break ;
501
+ }
502
+ }
503
+ if ( it != lists.cend () ) {
504
+ const int newId = static_cast <int >( std::distance ( lists.cbegin (), it ) );
505
+ if ( newId != currentId ) {
506
+ listbox.SetCurrent ( newId );
507
+ needRedraw = true ;
508
+ }
509
+ }
510
+ }
490
511
}
491
512
else if ( isEditing ) {
492
513
assert ( textInput != nullptr );
0 commit comments