mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 05:39:17 +02:00
SrcEdit: improve vertical placement on jumps (codetools)
git-svn-id: trunk@32157 -
This commit is contained in:
parent
f751ca687f
commit
50ac7e45f9
12
ide/main.pp
12
ide/main.pp
@ -13604,9 +13604,7 @@ begin
|
||||
end;
|
||||
SrcEdit.EditorComponent.LogicalCaretXY:=LogCaretXY;
|
||||
SrcEdit.EditorComponent.TopLine:=TopLine;
|
||||
with SrcEdit.EditorComponent do begin
|
||||
LeftChar:=Max(LogCaretXY.X - (CharsInWindow * 4 div 5),1);
|
||||
end;
|
||||
SrcEdit.CenterCursorHoriz(hcmSoftKeepEOL);
|
||||
SrcEdit.ErrorLine:=LogCaretXY.Y;
|
||||
end;
|
||||
end else begin
|
||||
@ -13712,10 +13710,9 @@ begin
|
||||
try
|
||||
SrcEdit.BeginUpdate;
|
||||
SrcEdit.EditorComponent.LogicalCaretXY:=LogCaretXY;
|
||||
if not SrcEdit.IsLocked then
|
||||
if not SrcEdit.IsLocked then begin
|
||||
SrcEdit.CenterCursor(True);
|
||||
with SrcEdit.EditorComponent do begin
|
||||
LeftChar:= Math.Max(LogCaretXY.X - (CharsInWindow * 4 div 5),1);
|
||||
SrcEdit.CenterCursorHoriz(hcmSoftKeepEOL);
|
||||
end;
|
||||
finally
|
||||
SrcEdit.EndUpdate;
|
||||
@ -15020,8 +15017,7 @@ begin
|
||||
NewSrcEdit.TopLine:=NewTopLine;
|
||||
end;
|
||||
//DebugLn('TMainIDE.DoJumpToCodePos NewY=',dbgs(NewY),' ',dbgs(TopLine),' ',dbgs(NewTopLine));
|
||||
with NewSrcEdit.EditorComponent do
|
||||
LeftChar:=Max(NewX - (CharsInWindow * 4 div 5), 1);
|
||||
NewSrcEdit.CenterCursorHoriz(hcmSoftKeepEOL);
|
||||
finally
|
||||
NewSrcEdit.EndUpdate;
|
||||
end;
|
||||
|
@ -84,6 +84,15 @@ type
|
||||
|
||||
TCharSet = set of Char;
|
||||
|
||||
// for TSourcEditor.CenterCursorHoriz
|
||||
TSourceEditHCenterMode =
|
||||
( hcmCenter, // Center X-Caret to exact middle of Screen
|
||||
hcmCenterKeepEOL, // Center X-Caret to middle of Screen, but keep EOL at right border
|
||||
hcmSoft, // Soft Center (distance to screen edge) Caret
|
||||
hcmSoftKeepEOL // Soft Center (distance to screen edge) Caret, but keep EOL at right border
|
||||
);
|
||||
|
||||
|
||||
{ TSynEditPlugin1 }
|
||||
|
||||
TSynEditPlugin1 = class(TSynEditPlugin)
|
||||
@ -416,7 +425,8 @@ type
|
||||
function CaretInSelection(const ACaretPos: TPoint): Boolean;
|
||||
|
||||
// cursor
|
||||
procedure CenterCursor(SoftCenter: Boolean = False);
|
||||
procedure CenterCursor(SoftCenter: Boolean = False); // vertical
|
||||
procedure CenterCursorHoriz(HCMode: TSourceEditHCenterMode); // horiz
|
||||
function TextToScreenPosition(const Position: TPoint): TPoint; override;
|
||||
function ScreenToTextPosition(const Position: TPoint): TPoint; override;
|
||||
function ScreenToPixelPosition(const Position: TPoint): TPoint; override;
|
||||
@ -4558,6 +4568,38 @@ begin
|
||||
EditorComponent.TopView := NewTopLine;
|
||||
end;
|
||||
|
||||
procedure TSourceEditor.CenterCursorHoriz(HCMode: TSourceEditHCenterMode);
|
||||
var
|
||||
i, j: Integer;
|
||||
begin
|
||||
case HCMode of
|
||||
hcmCenter:
|
||||
with EditorComponent do begin
|
||||
LeftChar:=Max(LogicalCaretXY.X - (CharsInWindow div 2), 1);
|
||||
end;
|
||||
hcmCenterKeepEOL:
|
||||
with EditorComponent do begin
|
||||
i := LogicalToPhysicalPos(Point(Length(Lines[CaretY]) + 1, CaretY)).X;
|
||||
LeftChar:=Max(Min(LogicalCaretXY.X - (CharsInWindow div 2),
|
||||
i - CharsInWindow
|
||||
), 1);
|
||||
end;
|
||||
hcmSoft:
|
||||
// TODO: offset on left side
|
||||
with EditorComponent do begin
|
||||
LeftChar:=Max(LogicalCaretXY.X - (CharsInWindow * 4 div 5), 1);
|
||||
end;
|
||||
hcmSoftKeepEOL:
|
||||
// TODO: offset on left side
|
||||
with EditorComponent do begin
|
||||
i := LogicalToPhysicalPos(Point(Length(Lines[CaretY]) + 1, CaretY)).X;
|
||||
LeftChar:=Max(Min(LogicalCaretXY.X - (CharsInWindow * 4 div 5),
|
||||
i - CharsInWindow
|
||||
), 1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSourceEditor.TextToScreenPosition(const Position: TPoint): TPoint;
|
||||
begin
|
||||
Result:=FEditor.LogicalToPhysicalPos(Position);
|
||||
|
Loading…
Reference in New Issue
Block a user