FIX: Viewer - Ctrl+End (go to file end) goes incorrect (fixes #817)

This commit is contained in:
Alexander Koblov 2024-09-19 20:44:51 +03:00
commit 1da73f2809

View file

@ -1777,6 +1777,16 @@ var
CharLenInBytes: Integer;
DataLength: PtrInt;
sText: String;
procedure DrawCaret(X, Y: Integer; LinePos: PtrInt);
begin
if FShowCaret and (FCaretPos = LinePos) then
begin
LCLIntf.SetCaretPos(X, Y);
if not FCaretVisible then FCaretVisible:= LCLIntf.ShowCaret(Handle);
end;
end;
begin
iPos := FPosition;
if Mode = vcmBook then
@ -1789,9 +1799,18 @@ begin
begin
for yIndex := 0 to GetClientHeightInLines(False) - 1 do
begin
if iPos >= FHighLimit then
if iPos > FHighLimit then
Break;
if iPos = FHighLimit then
begin
if GetPrevCharAsAscii(iPos, CharLenInBytes) = 10 then
begin
DrawCaret(0, yIndex * FTextHeight, iPos);
end;
Break;
end;
AddLineOffset(iPos);
LineStart := iPos;
@ -1799,8 +1818,9 @@ begin
if i > FHLowEnd then FHLowEnd:= i;
if DataLength > 0 then
begin
if DataLength = 0 then
DrawCaret(0, yIndex * FTextHeight, LineStart)
else begin
if (Mode = vcmText) and (FHPosition > 0) then
begin
for i:= 1 to FHPosition do
@ -1938,7 +1958,10 @@ begin
// Don't allow empty lines at the bottom of the control.
LinesTooMany := GetClientHeightInLines - GetLinesTillEnd(Value, LastLineReached);
if LinesTooMany > 0 then
ScrollPosition(Value, -LinesTooMany); // scroll back upwards
begin
// scroll back upwards
ScrollPosition(Value, -LinesTooMany);
end;
FPosition := Value;
if Assigned(FOnPositionChanged) then
@ -2019,9 +2042,10 @@ end;
function TViewerControl.GetLinesTillEnd(FromPosition: PtrInt;
out LastLineReached: Boolean): Integer;
var
iPos: PtrInt;
yIndex: Integer;
iPos: PtrInt;
DataLength: PtrInt;
CharLenInBytes: Integer;
begin
Result := 0;
iPos := FromPosition;
@ -2040,6 +2064,11 @@ begin
end;
end;
LastLineReached := (iPos >= FHighLimit);
if LastLineReached and (FViewerControlMode in [vcmText, vcmWrap, vcmBook]) then
begin
if (GetPrevCharAsAscii(FHighLimit, CharLenInBytes) = 10) then
Inc(Result);
end;
end;
procedure TViewerControl.SetShowCaret(AValue: Boolean);
@ -2394,8 +2423,7 @@ begin
VK_END:
begin
Key := 0;
GetPrevCharAsAscii(FHighLimit, CharLenInBytes);
CaretPos := (FHighLimit - CharLenInBytes);
CaretPos := FHighLimit;
MakeVisible(FCaretPos);
end;
else