mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 01:16:18 +02:00
identifier completion now adds the end of token key
git-svn-id: trunk@8808 -
This commit is contained in:
parent
724d607c66
commit
bb71ab95c8
@ -62,9 +62,16 @@ type
|
||||
function(const AKey: string; ACanvas: TCanvas;
|
||||
Selected: boolean; Index: integer): TPoint of object;
|
||||
{$ENDIF}
|
||||
TCodeCompletionEvent = procedure(var Value: string; Shift: TShiftState)
|
||||
of object;
|
||||
TValidateEvent = procedure(Sender: TObject; Shift: TShiftState) of object;
|
||||
TCodeCompletionEvent = procedure(var Value: string;
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
KeyChar: TUTF8Char;
|
||||
{$ENDIF}
|
||||
Shift: TShiftState) of object;
|
||||
TValidateEvent = procedure(Sender: TObject;
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
KeyChar: TUTF8Char;
|
||||
{$ENDIF}
|
||||
Shift: TShiftState) of object;
|
||||
TSynBaseCompletionSearchPosition = procedure(var Position :integer) of object;
|
||||
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
@ -79,7 +86,7 @@ type
|
||||
protected
|
||||
procedure Paint; override;
|
||||
public
|
||||
constructor Create(AOwner: TSynBaseCompletionForm);
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
function CalcHintRect(MaxWidth: Integer; const AHint: string;
|
||||
AData: Pointer): TRect; override;
|
||||
property Index: Integer read FIndex write FIndex;
|
||||
@ -287,10 +294,11 @@ type
|
||||
procedure SetEditor(const Value: TCustomSynEdit);
|
||||
procedure backspace(Sender: TObject);
|
||||
procedure Cancel(Sender: TObject);
|
||||
procedure Validate(Sender: TObject; Shift: TShiftState);
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
procedure Validate(Sender: TObject; KeyChar: TUTF8Char; Shift: TShiftState);
|
||||
procedure UTF8KeyPress(Sender: TObject; var Key: TUTF8Char);
|
||||
{$ELSE}
|
||||
procedure Validate(Sender: TObject; Shift: TShiftState);
|
||||
procedure KeyPress(Sender: TObject; var Key: char);
|
||||
{$ENDIF}
|
||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
@ -479,7 +487,8 @@ begin
|
||||
case Key of
|
||||
// added the VK_XXX codes to make it more readable / maintainable
|
||||
VK_RETURN:
|
||||
if Assigned(OnValidate) then OnValidate(Self, Shift);
|
||||
if Assigned(OnValidate) then
|
||||
OnValidate(Self, {$IFDEF SYN_LAZARUS}'',{$ENDIF} Shift);
|
||||
VK_ESCAPE{$IFNDEF SYN_LAZARUS}, VK_SPACE{$ENDIF}:
|
||||
if Assigned(OnCancel) then OnCancel(Self);
|
||||
// I do not think there is a worst way to do this, but laziness rules :-)
|
||||
@ -552,7 +561,7 @@ begin
|
||||
else
|
||||
{$ifdef SYN_LAZARUS}
|
||||
if (ord(key)>=32) and Assigned(OnValidate) then begin
|
||||
OnValidate(Self, []);
|
||||
OnValidate(Self, Key, []);
|
||||
Key:=#0;
|
||||
end else begin
|
||||
if Assigned(OnCancel) then OnCancel(Self);
|
||||
@ -714,7 +723,7 @@ begin
|
||||
and (not (UTF8Key[1] in ['a'..'z','A'..'Z','0'..'9','_'])) then begin
|
||||
// non identifier character
|
||||
if Assigned(OnValidate) then
|
||||
OnValidate(Self,[]);
|
||||
OnValidate(Self,UTF8Key,[]);
|
||||
UTF8Key:='';
|
||||
end else if (UTF8Key<>'') then begin
|
||||
// identifier character
|
||||
@ -942,7 +951,7 @@ begin
|
||||
OnExecute(Self);
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
if (ItemList.Count=1) and Assigned(OnValidate) then begin
|
||||
OnValidate(Form, []);
|
||||
OnValidate(Form, '', []);
|
||||
exit;
|
||||
end;
|
||||
if (ItemList.Count=0) and Assigned(OnCancel) then begin
|
||||
@ -1218,7 +1227,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynCompletion.Validate(Sender: TObject; Shift: TShiftState);
|
||||
procedure TSynCompletion.Validate(Sender: TObject;
|
||||
{$IFDEF SYN_LAZARUS}KeyChar: TUTF8Char;{$ENDIF}
|
||||
Shift: TShiftState);
|
||||
var
|
||||
F: TSynBaseCompletionForm;
|
||||
Value, CurLine: string;
|
||||
@ -1262,7 +1273,7 @@ begin
|
||||
if Position>=0 then begin
|
||||
if Assigned(FOnCodeCompletion) then begin
|
||||
Value := ItemList[Position];
|
||||
FOnCodeCompletion(Value, Shift);
|
||||
FOnCodeCompletion(Value,{$IFDEF SYN_LAZARUS}KeyChar{$ENDIF}, Shift);
|
||||
SelText := Value;
|
||||
end else
|
||||
SelText := ItemList[Position];
|
||||
@ -1759,11 +1770,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TSynBaseCompletionHint.Create(AOwner: TSynBaseCompletionForm);
|
||||
constructor TSynBaseCompletionHint.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FCompletionForm := AOwner;
|
||||
Color := AOwner.BackgroundColor;
|
||||
FCompletionForm := AOwner as TSynBaseCompletionForm;
|
||||
Color := FCompletionForm.BackgroundColor;
|
||||
AutoHide := False;
|
||||
Visible := False;
|
||||
end;
|
||||
|
@ -35,7 +35,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, BasicCodeTools, CodeTree, CodeToolManager,
|
||||
PascalParserTool, IdentCompletionTool, GraphType, Graphics,
|
||||
LCLType, PascalParserTool, IdentCompletionTool, GraphType, Graphics,
|
||||
TextTools, EditorOptions,
|
||||
SynEdit, SynRegExpr, SynCompletion, MainIntf;
|
||||
|
||||
@ -52,7 +52,8 @@ function PaintCompletionItem(const AKey: string; ACanvas: TCanvas;
|
||||
MeasureOnly: Boolean = False): TPoint;
|
||||
|
||||
function GetIdentCompletionValue(aCompletion : TSynCompletion;
|
||||
var ValueType: TIdentComplValue; var CursorToLeft: integer): string;
|
||||
AddChar: TUTF8Char;
|
||||
out ValueType: TIdentComplValue; out CursorToLeft: integer): string;
|
||||
function BreakLinesInText(const s: string; MaxLineLength: integer): string;
|
||||
|
||||
implementation
|
||||
@ -311,7 +312,8 @@ begin
|
||||
end;
|
||||
|
||||
function GetIdentCompletionValue(aCompletion : TSynCompletion;
|
||||
var ValueType: TIdentComplValue; var CursorToLeft: integer): string;
|
||||
AddChar: TUTF8Char;
|
||||
out ValueType: TIdentComplValue; out CursorToLeft: integer): string;
|
||||
var
|
||||
Index: Integer;
|
||||
IdentItem: TIdentifierListItem;
|
||||
@ -373,6 +375,9 @@ begin
|
||||
Result:=Result+' := ';
|
||||
CursorAtEnd:=false;
|
||||
end;}
|
||||
|
||||
if AddChar<>'' then
|
||||
Result:=Result+AddChar;
|
||||
|
||||
// add semicolon for statement ends
|
||||
if (ilcfContextNeedsEndSemicolon in IdentList.ContextFlags) then begin
|
||||
|
@ -491,11 +491,12 @@ type
|
||||
|
||||
procedure ccExecute(Sender: TObject);
|
||||
procedure ccCancel(Sender: TObject);
|
||||
procedure ccComplete(var Value: ansistring; Shift: TShiftState);
|
||||
procedure ccComplete(var Value: ansistring; KeyChar: TUTF8Char;
|
||||
Shift: TShiftState);
|
||||
function OnSynCompletionPaintItem(const AKey: string; ACanvas: TCanvas;
|
||||
X, Y: integer; ItemSelected: boolean; Index: integer): boolean;
|
||||
X, Y: integer; ItemSelected: boolean; Index: integer): boolean;
|
||||
function OnSynCompletionMeasureItem(const AKey: string; ACanvas: TCanvas;
|
||||
ItemSelected: boolean; Index: integer): TPoint;
|
||||
ItemSelected: boolean; Index: integer): TPoint;
|
||||
procedure OnSynCompletionSearchPosition(var APosition: integer);
|
||||
procedure OnSynCompletionCompletePrefix(Sender: TObject);
|
||||
procedure OnSynCompletionNextChar(Sender: TObject);
|
||||
@ -506,11 +507,11 @@ type
|
||||
procedure InitIdentCompletion(S: TStrings);
|
||||
|
||||
procedure EditorMouseMove(Sender: TObject; Shift: TShiftstate;
|
||||
X,Y: Integer);
|
||||
X,Y: Integer);
|
||||
procedure EditorMouseDown(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftstate; X,Y: Integer);
|
||||
Shift: TShiftstate; X,Y: Integer);
|
||||
procedure EditorMouseUp(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftstate; X,Y: Integer);
|
||||
Shift: TShiftstate; X,Y: Integer);
|
||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
|
||||
//hintwindow stuff
|
||||
@ -3092,9 +3093,9 @@ begin
|
||||
if CurCompletionControl=nil then exit;
|
||||
if (System.Pos(Key,CurCompletionControl.EndOfTokenChr)>0) then begin
|
||||
// identifier completed
|
||||
//debugln('TSourceNotebook.OnSynCompletionKeyPress A');
|
||||
CurCompletionControl.TheForm.OnValidate(Sender,[]);
|
||||
//debugln('TSourceNotebook.OnSynCompletionKeyPress B');
|
||||
debugln('TSourceNotebook.OnSynCompletionKeyPress A');
|
||||
CurCompletionControl.TheForm.OnValidate(Sender,Key,[]);
|
||||
debugln('TSourceNotebook.OnSynCompletionKeyPress B');
|
||||
Key:=#0;
|
||||
end;
|
||||
end;
|
||||
@ -3106,9 +3107,9 @@ begin
|
||||
if (length(UTF8Key)=1)
|
||||
and (System.Pos(UTF8Key[1],CurCompletionControl.EndOfTokenChr)>0) then begin
|
||||
// identifier completed
|
||||
//debugln('TSourceNotebook.OnSynCompletionUTF8KeyPress A');
|
||||
CurCompletionControl.TheForm.OnValidate(Sender,[]);
|
||||
//debugln('TSourceNotebook.OnSynCompletionKeyPress B');
|
||||
debugln('TSourceNotebook.OnSynCompletionUTF8KeyPress A');
|
||||
CurCompletionControl.TheForm.OnValidate(Sender,UTF8Key,[]);
|
||||
debugln('TSourceNotebook.OnSynCompletionKeyPress B');
|
||||
UTF8Key:='';
|
||||
end else begin
|
||||
aCompletion.Editor.CommandProcessor(ecChar,UTF8Key,nil);
|
||||
@ -3160,7 +3161,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceNotebook.ccComplete(var Value: ansistring; Shift: TShiftState);
|
||||
procedure TSourceNotebook.ccComplete(var Value: ansistring; KeyChar: TUTF8Char;
|
||||
Shift: TShiftState);
|
||||
// completion selected -> deactivate completion form
|
||||
// Called when user has selected a completion item
|
||||
|
||||
@ -3208,7 +3210,8 @@ Begin
|
||||
CodeToolBoss.IdentifierHistory.Add(
|
||||
CodeToolBoss.IdentifierList.FilteredItems[aCompletion.Position]);
|
||||
// get value
|
||||
NewValue:=GetIdentCompletionValue(aCompletion,ValueType,CursorToLeft);
|
||||
NewValue:=GetIdentCompletionValue(aCompletion,KeyChar,
|
||||
ValueType,CursorToLeft);
|
||||
// insert value plus special chars like brackets, semicolons, ...
|
||||
SrcEdit:=GetActiveSE;
|
||||
Editor:=SrcEdit.EditorComponent;
|
||||
|
Loading…
Reference in New Issue
Block a user