diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 127e2c397..8f2cacf59 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -352,11 +352,6 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) SG_LOG(SG_AUTOPILOT, SG_WARN, "removeWayptAtIndex with invalid index:" << aIndex); return NULL; } - - if (_currentIndex > index) { - --_currentIndex; // shift current index down if necessary - } - WayptVec::iterator it = _route.begin(); it += index; @@ -364,6 +359,15 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) _route.erase(it); update_mirror(); + + if (_currentIndex == index) { + currentWaypointChanged(); // current waypoint was removed + } + else + if (_currentIndex > index) { + --_currentIndex; // shift current index down if necessary + } + _edited->fireValueChanged(); checkFinished(); @@ -680,7 +684,7 @@ void FGRouteMgr::insertWayptAtIndex(Waypt* aWpt, int aIndex) WayptVec::iterator it = _route.begin(); it += index; - if (_currentIndex > index) { + if (_currentIndex >= index) { ++_currentIndex; } diff --git a/src/GUI/WaypointList.cxx b/src/GUI/WaypointList.cxx index 31c5e480c..f525f213b 100644 --- a/src/GUI/WaypointList.cxx +++ b/src/GUI/WaypointList.cxx @@ -83,9 +83,15 @@ public: --destIndex; } + int currentWpIndex = currentWaypoint(); WayptRef w(_rm->removeWayptAtIndex(srcIndex)); SG_LOG(SG_GENERAL, SG_INFO, "wpt:" << w->ident()); _rm->insertWayptAtIndex(w, destIndex); + + if (srcIndex == currentWpIndex) { + // current waypoint was moved + _rm->jumpToIndex(destIndex); + } } virtual void setUpdateCallback(SGCallback* cb)