@@ -68,6 +68,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68
68
#include " wakeful.hpp"
69
69
#include " WideMB.h"
70
70
#include " UtfConvert.hpp"
71
+ #include < algorithm>
71
72
72
73
#define MAX_VIEWLINE 0x2000
73
74
@@ -577,16 +578,20 @@ void Viewer::ShowPage(int nMode)
577
578
auto visualSelLength = printer->Length (StringI.Chars (StringI.nSelStart ),
578
579
StringI.nSelEnd - StringI.nSelStart );
579
580
580
- if (!VM.Wrap && AdjustSelPosition
581
- && (visualSelStart < LeftPos
582
- || (visualSelStart > LeftPos
583
- && visualSelStart + visualSelLength > LeftPos + XX2 - X1))) {
584
- LeftPos = visualSelStart > 1 ? visualSelStart - 1 : 0 ;
585
- AdjustSelPosition = FALSE ;
586
- Show ();
587
- return ;
581
+ if (!VM.Wrap && AdjustSelPosition) {
582
+ const int correctedWidth = Width - (ViOpt.ShowArrows ? 2 : 0 );
583
+ if (visualSelStart < LeftPos || visualSelStart + visualSelLength > LeftPos + correctedWidth) {
584
+ int newLeftPos = (visualSelLength <= correctedWidth)
585
+ ? (visualSelStart + visualSelLength / 2 - correctedWidth / 2 )
586
+ : (visualSelStart - (ViOpt.ShowArrows ? 1 : 0 ));
587
+ LeftPos = std::clamp (newLeftPos, 0 , std::max (StrLen - correctedWidth, 0 ));
588
+ AdjustSelPosition = FALSE ;
589
+ Show ();
590
+ return ;
591
+ }
588
592
}
589
593
594
+
590
595
int SelX1 = X1, SelSkip = 0 ;
591
596
if (visualSelStart > LeftPos)
592
597
SelX1+= visualSelStart - LeftPos;
0 commit comments