mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-03 12:23:43 +02:00
SynCompletion: Improved positioning
git-svn-id: trunk@28012 -
This commit is contained in:
parent
a4f2917fbd
commit
cf7da2876f
@ -271,7 +271,9 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Execute(s: string; x, y: integer);
|
procedure Execute(s: string; x, y: integer); overload;
|
||||||
|
procedure Execute(s: string; TopLeft: TPoint); overload;
|
||||||
|
procedure Execute(s: string; TokenRect: TRect); overload; // Excute below or above the token // may be extended to adjust left corner too
|
||||||
procedure Deactivate;
|
procedure Deactivate;
|
||||||
function IsActive: boolean;
|
function IsActive: boolean;
|
||||||
function TheForm: TSynBaseCompletionForm;
|
function TheForm: TSynBaseCompletionForm;
|
||||||
@ -481,6 +483,7 @@ begin
|
|||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FItemList := TStringList.Create;
|
FItemList := TStringList.Create;
|
||||||
BorderStyle := bsNone;
|
BorderStyle := bsNone;
|
||||||
|
FormStyle := fsSystemStayOnTop;
|
||||||
Scroll := TScrollBar.Create(self);
|
Scroll := TScrollBar.Create(self);
|
||||||
Scroll.Kind := sbVertical;
|
Scroll.Kind := sbVertical;
|
||||||
{$IFNDEF SYN_LAZARUS}
|
{$IFNDEF SYN_LAZARUS}
|
||||||
@ -529,6 +532,7 @@ begin
|
|||||||
Color:=clNone;
|
Color:=clNone;
|
||||||
FBackgroundColor:=clWhite;
|
FBackgroundColor:=clWhite;
|
||||||
FHint := TSynBaseCompletionHint.Create(Self);
|
FHint := TSynBaseCompletionHint.Create(Self);
|
||||||
|
FHint.FormStyle := fsSystemStayOnTop;;
|
||||||
FHintTimer := TTimer.Create(nil);
|
FHintTimer := TTimer.Create(nil);
|
||||||
FHintTimer.OnTimer := {$IFDEF FPC}@{$ENDIF}OnHintTimer;
|
FHintTimer.OnTimer := {$IFDEF FPC}@{$ENDIF}OnHintTimer;
|
||||||
FHintTimer.Interval := 0;
|
FHintTimer.Interval := 0;
|
||||||
@ -593,7 +597,7 @@ begin
|
|||||||
M := Monitor;
|
M := Monitor;
|
||||||
P := ClientToScreen(Point(0, (AIndex - Scroll.Position) * FFontHeight));
|
P := ClientToScreen(Point(0, (AIndex - Scroll.Position) * FFontHeight));
|
||||||
case FLongLineHintType of
|
case FLongLineHintType of
|
||||||
sclpExtendHalfLeft: MinLeft := Max(M.Left, P.X - ClientWidth div 2);
|
sclpExtendHalfLeft: MinLeft := Max(M.Left, P.X - ClientWidth div 2); // ClientWidth may be too much, if part of the ClientWidth extends to another screen.
|
||||||
sclpExtendUnlimitedLeft: MinLeft := M.Left;
|
sclpExtendUnlimitedLeft: MinLeft := M.Left;
|
||||||
else MinLeft := P.X;
|
else MinLeft := P.X;
|
||||||
end;
|
end;
|
||||||
@ -751,7 +755,8 @@ begin
|
|||||||
//Writeln('[TSynBaseCompletionForm.Paint]');
|
//Writeln('[TSynBaseCompletionForm.Paint]');
|
||||||
|
|
||||||
// update scroll bar
|
// update scroll bar
|
||||||
Scroll.Visible := ItemList.Count > NbLinesInWindow;
|
Scroll.Enabled := ItemList.Count > NbLinesInWindow;
|
||||||
|
Scroll.Visible := (ItemList.Count > NbLinesInWindow) or ShowSizeDrag;
|
||||||
|
|
||||||
if Scroll.Visible then
|
if Scroll.Visible then
|
||||||
begin
|
begin
|
||||||
@ -1194,6 +1199,41 @@ begin
|
|||||||
Form.Position := Form.Position;
|
Form.Position := Form.Position;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletion.Execute(s: string; TopLeft: TPoint);
|
||||||
|
begin
|
||||||
|
Execute(s, TopLeft.x, TopLeft.y);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSynBaseCompletion.Execute(s: string; TokenRect: TRect);
|
||||||
|
var
|
||||||
|
SpaceBelow, SpaceAbove: Integer;
|
||||||
|
Mon: TMonitor;
|
||||||
|
begin
|
||||||
|
{$IFnDEF LCLGTK2}
|
||||||
|
Mon := Screen.MonitorFromPoint(TokenRect.TopLeft);
|
||||||
|
if Mon <> nil then
|
||||||
|
TokenRect.Left := Min(TokenRect.Left, Mon.Left + Mon.Width - Form.Width);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
SpaceBelow := Mon.Height - TokenRect.Bottom;
|
||||||
|
SpaceAbove := TokenRect.Top - Mon.Top;
|
||||||
|
if Form.Height < SpaceBelow then
|
||||||
|
Execute(s, TokenRect.Left, TokenRect.Bottom)
|
||||||
|
else
|
||||||
|
if Form.Height < SpaceAbove then
|
||||||
|
Execute(s, TokenRect.Left, TokenRect.Top - Form.Height)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if SpaceBelow > SpaceAbove then begin
|
||||||
|
Form.NbLinesInWindow := Max(SpaceBelow div Form.FontHeight, 3); // temporary height
|
||||||
|
Execute(s, TokenRect.Left, TokenRect.Bottom);
|
||||||
|
end else begin
|
||||||
|
Form.NbLinesInWindow := Max(SpaceAbove div Form.FontHeight, 3); // temporary height
|
||||||
|
Execute(s, TokenRect.Left, TokenRect.Top - Form.Height);
|
||||||
|
end;;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynBaseCompletion.GetCurrentString: string;
|
function TSynBaseCompletion.GetCurrentString: string;
|
||||||
begin
|
begin
|
||||||
result := Form.CurrentString;
|
result := Form.CurrentString;
|
||||||
|
@ -820,6 +820,7 @@ type
|
|||||||
procedure RegisterStatusChangedHandler(AStatusChangeProc: TStatusChangeEvent; AChanges: TSynStatusChanges);
|
procedure RegisterStatusChangedHandler(AStatusChangeProc: TStatusChangeEvent; AChanges: TSynStatusChanges);
|
||||||
procedure UnRegisterStatusChangedHandler(AStatusChangeProc: TStatusChangeEvent);
|
procedure UnRegisterStatusChangedHandler(AStatusChangeProc: TStatusChangeEvent);
|
||||||
|
|
||||||
|
// RowColumnToPixels: Physical coords
|
||||||
function RowColumnToPixels(
|
function RowColumnToPixels(
|
||||||
{$IFDEF SYN_LAZARUS}const {$ENDIF}RowCol: TPoint): TPoint;
|
{$IFDEF SYN_LAZARUS}const {$ENDIF}RowCol: TPoint): TPoint;
|
||||||
function SearchReplace(const ASearch, AReplace: string;
|
function SearchReplace(const ASearch, AReplace: string;
|
||||||
|
@ -877,11 +877,12 @@ type
|
|||||||
FActiveCompletionPlugin: TSourceEditorCompletionPlugin;
|
FActiveCompletionPlugin: TSourceEditorCompletionPlugin;
|
||||||
function GetDefaultCompletionForm: TSourceEditCompletion;
|
function GetDefaultCompletionForm: TSourceEditCompletion;
|
||||||
procedure FreeCompletionPlugins;
|
procedure FreeCompletionPlugins;
|
||||||
|
function GetScreenRectForToken(AnEditor: TCustomSynEdit; PhysColumn, PhysRow, EndColumn: Integer): TRect;
|
||||||
protected
|
protected
|
||||||
function GetActiveCompletionPlugin: TSourceEditorCompletionPlugin; override;
|
function GetActiveCompletionPlugin: TSourceEditorCompletionPlugin; override;
|
||||||
function GetCompletionBoxPosition: integer; override;
|
function GetCompletionBoxPosition: integer; override;
|
||||||
function GetCompletionPlugins(Index: integer): TSourceEditorCompletionPlugin; override;
|
function GetCompletionPlugins(Index: integer): TSourceEditorCompletionPlugin; override;
|
||||||
function FindIdentCompletionPlugin(SrcEdit: TSourceEditor; JumpToError: boolean;
|
function FindIdentCompletionPlugin(SrcEdit: TSourceEditor; JumpToError: boolean;
|
||||||
var s: string; var BoxX, BoxY: integer;
|
var s: string; var BoxX, BoxY: integer;
|
||||||
var UseWordCompletion: boolean): boolean;
|
var UseWordCompletion: boolean): boolean;
|
||||||
property DefaultCompletionForm: TSourceEditCompletion
|
property DefaultCompletionForm: TSourceEditCompletion
|
||||||
@ -3925,11 +3926,11 @@ end;
|
|||||||
procedure TSourceEditor.StartIdentCompletionBox(JumpToError: boolean);
|
procedure TSourceEditor.StartIdentCompletionBox(JumpToError: boolean);
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
P: TPoint;
|
|
||||||
TextS, TextS2: String;
|
TextS, TextS2: String;
|
||||||
LogCaret: TPoint;
|
LogCaret: TPoint;
|
||||||
UseWordCompletion: Boolean;
|
UseWordCompletion: Boolean;
|
||||||
Completion: TSourceEditCompletion;
|
Completion: TSourceEditCompletion;
|
||||||
|
CompletionRect: TRect;
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerboseIDECompletionBox}
|
{$IFDEF VerboseIDECompletionBox}
|
||||||
debugln(['TSourceEditor.StartIdentCompletionBox JumpToError: ',JumpToError]);
|
debugln(['TSourceEditor.StartIdentCompletionBox JumpToError: ',JumpToError]);
|
||||||
@ -3950,20 +3951,17 @@ begin
|
|||||||
dec(i);
|
dec(i);
|
||||||
TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1));
|
TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1));
|
||||||
end;
|
end;
|
||||||
with FEditor do begin
|
|
||||||
P := Point(CaretXPix - length(TextS2)*CharWidth,CaretYPix + LineHeight + 1);
|
|
||||||
P.X:=Max(0,Min(P.X,ClientWidth-Completion.Width));
|
|
||||||
P := ClientToScreen(p);
|
|
||||||
end;
|
|
||||||
UseWordCompletion:=false;
|
UseWordCompletion:=false;
|
||||||
|
CompletionRect := Manager.GetScreenRectForToken(FEditor, FEditor.CaretX-length(TextS2), FEditor.CaretY, FEditor.CaretX-1);
|
||||||
|
|
||||||
if not Manager.FindIdentCompletionPlugin
|
if not Manager.FindIdentCompletionPlugin
|
||||||
(Self, JumpToError, TextS2, P.X, P.Y, UseWordCompletion)
|
(Self, JumpToError, TextS2, CompletionRect.Top, CompletionRect.Left, UseWordCompletion)
|
||||||
then
|
then
|
||||||
exit;
|
exit;
|
||||||
if UseWordCompletion then
|
if UseWordCompletion then
|
||||||
Completion.CurrentCompletionType:=ctWordCompletion;
|
Completion.CurrentCompletionType:=ctWordCompletion;
|
||||||
|
|
||||||
Completion.Execute(TextS2,P.X,P.Y);
|
Completion.Execute(TextS2, CompletionRect);
|
||||||
{$IFDEF VerboseIDECompletionBox}
|
{$IFDEF VerboseIDECompletionBox}
|
||||||
debugln(['TSourceEditor.StartIdentCompletionBox END Completion.TheForm.Visible=',Completion.TheForm.Visible]);
|
debugln(['TSourceEditor.StartIdentCompletionBox END Completion.TheForm.Visible=',Completion.TheForm.Visible]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -3975,7 +3973,6 @@ var
|
|||||||
LogCaret: TPoint;
|
LogCaret: TPoint;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
TextS2: String;
|
TextS2: String;
|
||||||
P: TPoint;
|
|
||||||
Completion: TSourceEditCompletion;
|
Completion: TSourceEditCompletion;
|
||||||
begin
|
begin
|
||||||
if (FEditor.ReadOnly) then exit;
|
if (FEditor.ReadOnly) then exit;
|
||||||
@ -3993,12 +3990,8 @@ begin
|
|||||||
dec(i);
|
dec(i);
|
||||||
TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1));
|
TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1));
|
||||||
end;
|
end;
|
||||||
with FEditor do begin
|
Completion.Execute
|
||||||
P := Point(CaretXPix - length(TextS2)*CharWidth,CaretYPix + LineHeight + 1);
|
(TextS2, Manager.GetScreenRectForToken(FEditor, FEditor.CaretX-length(TextS2), FEditor.CaretY, FEditor.CaretX-1));
|
||||||
P.X:=Max(0,Min(P.X,ClientWidth - Completion.Width));
|
|
||||||
P := ClientToScreen(p);
|
|
||||||
end;
|
|
||||||
Completion.Execute(TextS2,P.X,P.Y);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSourceEditor.IncreaseIgnoreCodeBufferLock;
|
procedure TSourceEditor.IncreaseIgnoreCodeBufferLock;
|
||||||
@ -7838,6 +7831,13 @@ begin
|
|||||||
FCompletionPlugins.Clear;
|
FCompletionPlugins.Clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSourceEditorManagerBase.GetScreenRectForToken(AnEditor: TCustomSynEdit;
|
||||||
|
PhysColumn, PhysRow, EndColumn: Integer): TRect;
|
||||||
|
begin
|
||||||
|
Result.TopLeft := AnEditor.ClientToScreen(AnEditor.RowColumnToPixels(Point(PhysColumn, PhysRow)));
|
||||||
|
Result.BottomRight := AnEditor.ClientToScreen(AnEditor.RowColumnToPixels(Point(EndColumn+1, PhysRow+1)));
|
||||||
|
end;
|
||||||
|
|
||||||
function TSourceEditorManagerBase.GetMarklingProducers(Index: integer
|
function TSourceEditorManagerBase.GetMarklingProducers(Index: integer
|
||||||
): TSourceMarklingProducer;
|
): TSourceMarklingProducer;
|
||||||
begin
|
begin
|
||||||
@ -8707,21 +8707,15 @@ end;
|
|||||||
|
|
||||||
procedure TSourceEditorManager.OnCodeTemplateTokenNotFound(Sender: TObject;
|
procedure TSourceEditorManager.OnCodeTemplateTokenNotFound(Sender: TObject;
|
||||||
AToken: string; AnEditor: TCustomSynEdit; var Index: integer);
|
AToken: string; AnEditor: TCustomSynEdit; var Index: integer);
|
||||||
var
|
|
||||||
P:TPoint;
|
|
||||||
begin
|
begin
|
||||||
//writeln('TSourceNotebook.OnCodeTemplateTokenNotFound ',AToken,',',AnEditor.ReadOnly,',',DefaultCompletionForm.CurrentCompletionType=ctNone);
|
//writeln('TSourceNotebook.OnCodeTemplateTokenNotFound ',AToken,',',AnEditor.ReadOnly,',',DefaultCompletionForm.CurrentCompletionType=ctNone);
|
||||||
if (AnEditor.ReadOnly=false) and
|
if (AnEditor.ReadOnly=false) and
|
||||||
(DefaultCompletionForm.CurrentCompletionType=ctNone)
|
(DefaultCompletionForm.CurrentCompletionType=ctNone)
|
||||||
then begin
|
then begin
|
||||||
DefaultCompletionForm.CurrentCompletionType:=ctTemplateCompletion;
|
DefaultCompletionForm.CurrentCompletionType:=ctTemplateCompletion;
|
||||||
with AnEditor do begin
|
|
||||||
P := Point(CaretXPix - length(AToken)*CharWidth,CaretYPix + LineHeight + 1);
|
|
||||||
P.X:=Max(0,Min(P.X,ClientWidth-DefaultCompletionForm.Width));
|
|
||||||
P := ClientToScreen(p);
|
|
||||||
end;
|
|
||||||
DefaultCompletionForm.Editor:=AnEditor;
|
DefaultCompletionForm.Editor:=AnEditor;
|
||||||
DefaultCompletionForm.Execute(AToken,P.X,P.Y);
|
DefaultCompletionForm.Execute
|
||||||
|
(AToken, GetScreenRectForToken(AnEditor, AnEditor.CaretX-length(AToken), AnEditor.CaretY, AnEditor.CaretX-1));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user