The attached patch fixes items 3288113 and 3288121:
Missing marks when searching through mark next from peers:
Endless loop with mark prev from peer text widget:
The patch is against the latest Fossil sources.
The existing textMark.test suite passes with no failure.
Plus I have added one test item for each issue above that the patch is fixing.