mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 19:59:14 +02:00
SynEdit: Handle pixel to row, for row > Lines.Count Issue #0019509
git-svn-id: trunk@33738 -
This commit is contained in:
parent
a2059d628c
commit
f2ffcef2ba
@ -328,6 +328,10 @@ type
|
|||||||
Sender: TObject; X, Y: Integer; var AllowMouseLink: Boolean) of object;
|
Sender: TObject; X, Y: Integer; var AllowMouseLink: Boolean) of object;
|
||||||
|
|
||||||
TSynHomeMode = (synhmDefault, synhmFirstWord);
|
TSynHomeMode = (synhmDefault, synhmFirstWord);
|
||||||
|
|
||||||
|
TSynCoordinateMappingFlag = (scmLimitToLines, scmIncludePartVisible);
|
||||||
|
TSynCoordinateMappingFlags = set of TSynCoordinateMappingFlag;
|
||||||
|
|
||||||
{ TCustomSynEdit }
|
{ TCustomSynEdit }
|
||||||
|
|
||||||
TCustomSynEdit = class(TSynEditBase)
|
TCustomSynEdit = class(TSynEditBase)
|
||||||
@ -802,9 +806,9 @@ type
|
|||||||
procedure Notification(AComponent: TComponent;
|
procedure Notification(AComponent: TComponent;
|
||||||
Operation: TOperation); override;
|
Operation: TOperation); override;
|
||||||
procedure PasteFromClipboard;
|
procedure PasteFromClipboard;
|
||||||
function PixelsToRowColumn(Pixels: TPoint): TPoint;
|
function PixelsToRowColumn(Pixels: TPoint; aFlags: TSynCoordinateMappingFlags = [scmLimitToLines]): TPoint;
|
||||||
function PixelsToLogicalPos(const Pixels: TPoint): TPoint;
|
function PixelsToLogicalPos(const Pixels: TPoint): TPoint;
|
||||||
function ScreenRowToRow(ScreenRow: integer): integer;
|
function ScreenRowToRow(ScreenRow: integer; LimitToLines: Boolean = True): integer;
|
||||||
function RowToScreenRow(PhysicalRow: integer): integer;
|
function RowToScreenRow(PhysicalRow: integer): integer;
|
||||||
procedure Redo;
|
procedure Redo;
|
||||||
procedure RegisterCommandHandler(AHandlerProc: THookedCommandEvent;
|
procedure RegisterCommandHandler(AHandlerProc: THookedCommandEvent;
|
||||||
@ -1418,7 +1422,7 @@ begin
|
|||||||
PrimarySelection.OnRequest:=nil;
|
PrimarySelection.OnRequest:=nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSynEdit.PixelsToRowColumn(Pixels: TPoint): TPoint;
|
function TCustomSynEdit.PixelsToRowColumn(Pixels: TPoint; aFlags: TSynCoordinateMappingFlags = [scmLimitToLines]): TPoint;
|
||||||
// converts the client area coordinate
|
// converts the client area coordinate
|
||||||
// to Caret position (screen position, (1,1) based)
|
// to Caret position (screen position, (1,1) based)
|
||||||
// To get the text/physical position use PixelsToLogicalPos
|
// To get the text/physical position use PixelsToLogicalPos
|
||||||
@ -1430,12 +1434,12 @@ begin
|
|||||||
- TextLeftPixelOffset
|
- TextLeftPixelOffset
|
||||||
) / fCharWidth
|
) / fCharWidth
|
||||||
)+1;
|
)+1;
|
||||||
|
if (not(scmIncludePartVisible in aFlags)) and (Pixels.Y >= fLinesInWindow * fTextHeight) then begin
|
||||||
// don't return a partially visible last line
|
// don't return a partially visible last line
|
||||||
if Pixels.Y >= fLinesInWindow * fTextHeight then begin
|
|
||||||
Pixels.Y := fLinesInWindow * fTextHeight - 1;
|
Pixels.Y := fLinesInWindow * fTextHeight - 1;
|
||||||
if Pixels.Y < 0 then Pixels.Y := 0;
|
if Pixels.Y < 0 then Pixels.Y := 0;
|
||||||
end;
|
end;
|
||||||
Result := Point(RoundOff(f), ScreenRowToRow(Pixels.Y div fTextHeight));
|
Result := Point(RoundOff(f), ScreenRowToRow(Pixels.Y div fTextHeight, scmLimitToLines in aFlags));
|
||||||
{$IFDEF SYN_MBCSSUPPORT}
|
{$IFDEF SYN_MBCSSUPPORT}
|
||||||
if (Result.Y >= 1) and (Result.Y <= Lines.Count) then begin
|
if (Result.Y >= 1) and (Result.Y <= Lines.Count) then begin
|
||||||
s := Lines[Result.Y - 1];
|
s := Lines[Result.Y - 1];
|
||||||
@ -1454,11 +1458,13 @@ begin
|
|||||||
Result:=PhysicalToLogicalPos(PixelsToRowColumn(Pixels));
|
Result:=PhysicalToLogicalPos(PixelsToRowColumn(Pixels));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSynEdit.ScreenRowToRow(ScreenRow: integer): integer;
|
function TCustomSynEdit.ScreenRowToRow(ScreenRow: integer; LimitToLines: Boolean = True): integer;
|
||||||
// ScreenRow is 0-base
|
// ScreenRow is 0-base
|
||||||
// result is 1-based
|
// result is 1-based
|
||||||
begin
|
begin
|
||||||
Result := FFoldedLinesView.ScreenLineToTextIndex(ScreenRow)+1;
|
Result := FFoldedLinesView.ScreenLineToTextIndex(ScreenRow)+1;
|
||||||
|
if LimitToLines and (Result >= Lines.Count) then
|
||||||
|
Result := Lines.Count;
|
||||||
// DebugLn(['=== SrceenRow TO Row In:',ScreenRow,' out:',Result, ' topline=',TopLine, ' view topline=',FFoldedLinesView.TopLine]);
|
// DebugLn(['=== SrceenRow TO Row In:',ScreenRow,' out:',Result, ' topline=',TopLine, ' view topline=',FFoldedLinesView.TopLine]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -2906,8 +2906,6 @@ end;
|
|||||||
|
|
||||||
function TSynEditFoldedView.ViewPosToTextIndex(aViewPos : Integer) : Integer;
|
function TSynEditFoldedView.ViewPosToTextIndex(aViewPos : Integer) : Integer;
|
||||||
begin
|
begin
|
||||||
if aViewPos > Count then
|
|
||||||
aViewPos := Count;
|
|
||||||
result := aViewPos - 1 + fFoldTree.FindFoldForFoldedLine(aViewPos).FoldedBefore;
|
result := aViewPos - 1 + fFoldTree.FindFoldForFoldedLine(aViewPos).FoldedBefore;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user