Make possible to go backward to the first TOC section

This commit removes code duplication, allows to go backwards in any case except if the new TOC section will be positioned after the current one (which means the navigation becomes circular). Didn't find the project tests to run.