IDE, SourceEditor: implemented identifier-completion activates on typing. Issue #0033054 (different from patch)

git-svn-id: trunk@63314 -
This commit is contained in:
martin 2020-06-06 15:16:21 +00:00
parent dcc69156e5
commit f3f864d967
5 changed files with 292 additions and 72 deletions

View File

@ -66,6 +66,9 @@ type
FFilename: string;
FIdentComplAddDo: Boolean;
FIdentComplAddParameterBrackets: boolean;
FIdentComplOnTypeMinLength: Integer;
FIdentComplOnTypeOnlyWordEnd: boolean;
FIdentComplOnTypeUseTimer: boolean;
FIdentComplReplaceIdentifier: boolean;
FIdentComplJumpToError: boolean;
FIdentComplShowHelp: boolean;
@ -121,6 +124,7 @@ type
// identifier completion
FIdentComplAddSemicolon: Boolean;
FIdentComplAddAssignOperator: Boolean;
FIdentComplAutoInvokeOnType: boolean;
FIdentComplAutoStartAfterPoint: boolean;
FIdentComplAutoUseSingleIdent: boolean;
FIdentComplUseContainsFilter: Boolean;
@ -251,6 +255,14 @@ type
property IdentComplAddAssignOperator: Boolean read FIdentComplAddAssignOperator
write FIdentComplAddAssignOperator;
property IdentComplAddDo: Boolean read FIdentComplAddDo write FIdentComplAddDo;
property IdentComplAutoInvokeOnType: boolean read FIdentComplAutoInvokeOnType
write FIdentComplAutoInvokeOnType;
property IdentComplOnTypeUseTimer: boolean read FIdentComplOnTypeUseTimer
write FIdentComplOnTypeUseTimer;
property IdentComplOnTypeOnlyWordEnd: boolean read FIdentComplOnTypeOnlyWordEnd
write FIdentComplOnTypeOnlyWordEnd;
property IdentComplOnTypeMinLength: Integer read FIdentComplOnTypeMinLength
write FIdentComplOnTypeMinLength;
property IdentComplAutoStartAfterPoint: boolean read FIdentComplAutoStartAfterPoint
write FIdentComplAutoStartAfterPoint;
property IdentComplAutoUseSingleIdent: boolean read FIdentComplAutoUseSingleIdent
@ -571,6 +583,14 @@ begin
'CodeToolsOptions/IdentifierCompletion/AddAssignOperator',true);
FIdentComplAddDo:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/AddDo',true);
FIdentComplAutoInvokeOnType:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/AutoInvokeOnType',False);
FIdentComplOnTypeUseTimer:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/OnTypeUseTimer',true);
FIdentComplOnTypeOnlyWordEnd:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/OnTypeOnlyWordEnd',true);
FIdentComplOnTypeMinLength:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/OnTypeMinLength',2);
FIdentComplAutoStartAfterPoint:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',true);
FIdentComplAutoUseSingleIdent:=XMLConfig.GetValue(
@ -748,6 +768,14 @@ begin
FIdentComplAddAssignOperator,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AddDo',
FIdentComplAddDo,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoInvokeOnType',
FIdentComplAutoInvokeOnType,False);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/OnTypeUseTimer',
FIdentComplOnTypeUseTimer,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/OnTypeOnlyWordEnd',
FIdentComplOnTypeOnlyWordEnd,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/OnTypeMinLength',
FIdentComplOnTypeMinLength,2);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',
FIdentComplAutoStartAfterPoint,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoUseSingleIdent',
@ -907,6 +935,10 @@ begin
FIdentComplAddSemicolon:=CodeToolsOpts.FIdentComplAddSemicolon;
FIdentComplAddAssignOperator:=CodeToolsOpts.FIdentComplAddAssignOperator;
FIdentComplAddDo:=CodeToolsOpts.FIdentComplAddDo;
FIdentComplAutoInvokeOnType:=CodeToolsOpts.FIdentComplAutoInvokeOnType;
FIdentComplOnTypeUseTimer:=CodeToolsOpts.FIdentComplOnTypeUseTimer;
FIdentComplOnTypeOnlyWordEnd:=CodeToolsOpts.FIdentComplOnTypeOnlyWordEnd;
FIdentComplOnTypeMinLength:=CodeToolsOpts.FIdentComplOnTypeMinLength;
FIdentComplAutoStartAfterPoint:=CodeToolsOpts.FIdentComplAutoStartAfterPoint;
FIdentComplAutoUseSingleIdent:=CodeToolsOpts.FIdentComplAutoUseSingleIdent;
FIdentComplUseContainsFilter:=CodeToolsOpts.FIdentComplUseContainsFilter;
@ -975,6 +1007,10 @@ begin
FIdentComplAddSemicolon:=true;
FIdentComplAddAssignOperator:=true;
FIdentComplAddDo:=true;
FIdentComplAutoInvokeOnType:=False;
FIdentComplOnTypeUseTimer:=true;
FIdentComplOnTypeOnlyWordEnd:=true;
FIdentComplOnTypeMinLength:=2;
FIdentComplAutoStartAfterPoint:=true;
FIdentComplAutoUseSingleIdent:=true;
FIdentComplUseContainsFilter:=true;
@ -1062,6 +1098,10 @@ begin
and (FIdentComplAddSemicolon=CodeToolsOpts.FIdentComplAddSemicolon)
and (FIdentComplAddAssignOperator=CodeToolsOpts.FIdentComplAddAssignOperator)
and (FIdentComplAddDo=CodeToolsOpts.FIdentComplAddDo)
and (FIdentComplAutoInvokeOnType=CodeToolsOpts.FIdentComplAutoInvokeOnType)
and (FIdentComplOnTypeUseTimer=CodeToolsOpts.FIdentComplOnTypeUseTimer)
and (FIdentComplOnTypeOnlyWordEnd=CodeToolsOpts.FIdentComplOnTypeOnlyWordEnd)
and (FIdentComplOnTypeMinLength=CodeToolsOpts.FIdentComplOnTypeMinLength)
and (FIdentComplAutoStartAfterPoint=CodeToolsOpts.FIdentComplAutoStartAfterPoint)
and (FIdentComplAutoUseSingleIdent=CodeToolsOpts.FIdentComplAutoUseSingleIdent)
and (FIdentComplUseContainsFilter=CodeToolsOpts.FIdentComplUseContainsFilter)

View File

@ -16,10 +16,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 99
Width = 161
Top = 179
Width = 162
Caption = 'ICAddSemicolonCheckBox'
TabOrder = 3
TabOrder = 7
end
object ICAddAssignOperatorCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -28,12 +28,12 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 118
Width = 187
Top = 198
Width = 188
Caption = 'ICAddAssignOperatorCheckBox'
TabOrder = 4
TabOrder = 8
end
object ICAutoStartAfterPointCheckBox: TCheckBox
object ICAutoInvokeOnTypeCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICOpenDividerBevel
AnchorSideTop.Side = asrBottom
@ -41,10 +41,22 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
Left = 0
Height = 19
Top = 25
Width = 187
Caption = 'ICAutoStartAfterPointCheckBox'
Width = 186
Caption = 'ICAutoInvokeOnTypeCheckBox'
TabOrder = 0
end
object ICAutoStartAfterPointCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAutoOnTypeMinLength
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 105
Width = 188
Caption = 'ICAutoStartAfterPointCheckBox'
TabOrder = 4
end
object ICAutoAddParameterBracketsCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAddDoCheckBox
@ -52,10 +64,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 156
Width = 229
Top = 236
Width = 230
Caption = 'ICAutoAddParameterBracketsCheckBox'
TabOrder = 6
TabOrder = 10
end
object ICShowHelpCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -64,12 +76,12 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 63
Width = 137
Top = 143
Width = 138
Caption = 'ICShowHelpCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 2
TabOrder = 6
end
object ICReplaceCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -78,12 +90,12 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 365
Width = 124
Top = 445
Width = 125
Caption = 'ICReplaceCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 13
TabOrder = 16
end
object ICAddDoCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -92,10 +104,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 137
Width = 120
Top = 217
Width = 121
Caption = 'ICAddDoCheckBox'
TabOrder = 5
TabOrder = 9
end
object ICSortForHistoryCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -103,10 +115,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 192
Width = 159
Top = 272
Width = 160
Caption = 'ICSortForHistoryCheckBox'
TabOrder = 7
TabOrder = 11
end
object ICSortForScopeCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -114,12 +126,12 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 211
Width = 153
Top = 291
Width = 154
Caption = 'ICSortForScopeCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 8
TabOrder = 12
end
object ICOpenDividerBevel: TDividerBevel
AnchorSideLeft.Control = Owner
@ -142,7 +154,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 84
Top = 164
Width = 537
Caption = 'ICAddDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -158,7 +170,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 177
Top = 257
Width = 537
Caption = 'ICSortDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -174,7 +186,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 350
Top = 430
Width = 537
Caption = 'ICMiscDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -189,26 +201,27 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 384
Top = 464
Width = 151
Caption = 'ICJumpToErrorCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 14
TabOrder = 17
end
object ICAutoUseSingleIdent: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAutoStartAfterPointCheckBox
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 0
Left = 20
Height = 19
Top = 44
Top = 124
Width = 135
BorderSpacing.Left = 20
Caption = 'ICAutoUseSingleIdent'
ParentShowHint = False
ShowHint = True
TabOrder = 1
TabOrder = 5
end
object ICContainsFilterCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -216,10 +229,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 247
Width = 156
Top = 327
Width = 157
Caption = 'ICContainsFilterCheckBox'
TabOrder = 9
TabOrder = 18
end
object ICAppearanceDividerBevel: TDividerBevel
AnchorSideLeft.Control = Owner
@ -229,7 +242,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 314
Top = 394
Width = 537
Caption = 'ICAppearanceDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -243,10 +256,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 329
Width = 222
Top = 409
Width = 224
Caption = 'ICUseIconsInCompletionBoxCheckBox'
TabOrder = 12
TabOrder = 15
end
object ICContentDividerBevel: TDividerBevel
AnchorSideLeft.Control = Owner
@ -256,7 +269,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 232
Top = 312
Width = 537
Caption = 'ICContentDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -269,7 +282,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrCenter
Left = 0
Height = 15
Top = 272
Top = 352
Width = 112
Caption = 'ICIncludeWordsLabel'
ParentColor = False
@ -281,13 +294,13 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 117
Height = 23
Top = 268
Top = 348
Width = 200
BorderSpacing.Left = 5
BorderSpacing.Top = 2
ItemHeight = 15
Style = csDropDownList
TabOrder = 10
TabOrder = 13
end
object ICIncludeCodeTemplatesCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -295,10 +308,67 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 293
Top = 373
Width = 205
BorderSpacing.Top = 2
Caption = 'ICIncludeCodeTemplatesCheckBox'
TabOrder = 11
TabOrder = 14
end
object ICAutoOnTypeUseTimer: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAutoInvokeOnTypeCheckBox
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 20
Height = 19
Top = 44
Width = 147
BorderSpacing.Left = 20
Caption = 'ICAutoOnTypeUseTimer'
ParentShowHint = False
ShowHint = True
TabOrder = 1
end
object ICAutoOnTypeOnlyWordEnd: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAutoOnTypeUseTimer
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 20
Height = 19
Top = 63
Width = 172
BorderSpacing.Left = 20
Caption = 'ICAutoOnTypeOnlyWordEnd'
ParentShowHint = False
ShowHint = True
TabOrder = 2
end
object ICAutoOnTypeMinLengthLbl: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAutoOnTypeMinLength
AnchorSideTop.Side = asrCenter
Left = 20
Height = 15
Top = 86
Width = 151
BorderSpacing.Left = 20
Caption = 'ICAutoOnTypeMinLengthLbl'
ParentColor = False
end
object ICAutoOnTypeMinLength: TSpinEdit
AnchorSideLeft.Control = ICAutoOnTypeMinLengthLbl
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ICAutoOnTypeOnlyWordEnd
AnchorSideTop.Side = asrBottom
Left = 176
Height = 23
Top = 82
Width = 50
BorderSpacing.Left = 5
MaxValue = 99
MinValue = 1
TabOrder = 3
Value = 2
end
end

View File

@ -27,7 +27,7 @@ interface
uses
SysUtils,
// LCL
Forms, StdCtrls,
Forms, StdCtrls, Spin,
// LazControls
DividerBevel,
// IdeIntf
@ -41,12 +41,15 @@ type
TCodetoolsIndentifierCompletionOptionsFrame = class(TAbstractIDEOptionsEditor)
ICAddWordsComboBox: TComboBox;
ICAutoOnTypeUseTimer: TCheckBox;
ICAutoOnTypeOnlyWordEnd: TCheckBox;
ICContainsFilterCheckBox: TCheckBox;
ICAddDoCheckBox: TCheckBox;
ICAutoAddParameterBracketsCheckBox: TCheckBox;
ICIncludeCodeTemplatesCheckBox: TCheckBox;
ICMiscDividerBevel: TDividerBevel;
ICOpenDividerBevel: TDividerBevel;
ICAutoInvokeOnTypeCheckBox: TCheckBox;
ICAutoStartAfterPointCheckBox: TCheckBox;
ICAddAssignOperatorCheckBox: TCheckBox;
ICAddSemicolonCheckBox: TCheckBox;
@ -62,6 +65,8 @@ type
ICSortForScopeCheckBox: TCheckBox;
ICUseIconsInCompletionBoxCheckBox: TCheckBox;
ICIncludeWordsLabel: TLabel;
ICAutoOnTypeMinLengthLbl: TLabel;
ICAutoOnTypeMinLength: TSpinEdit;
private
public
function GetTitle: String; override;
@ -86,6 +91,10 @@ procedure TCodetoolsIndentifierCompletionOptionsFrame.Setup(
ADialog: TAbstractOptionsEditorDialog);
begin
ICOpenDividerBevel.Caption:=lisIdCOpening;
ICAutoInvokeOnTypeCheckBox.Caption:=lisAutomaticallyInvokeOnType;
ICAutoOnTypeUseTimer.Caption:=lisAutomaticallyInvokeOnTypeUseTimer;
ICAutoOnTypeOnlyWordEnd.Caption:=lisAutomaticallyInvokeOnTypeOnlyWordEnd;
ICAutoOnTypeMinLengthLbl.Caption:=lisAutomaticallyInvokeOnTypeMinLength;
ICAutoStartAfterPointCheckBox.Caption:=lisAutomaticallyInvokeAfterPoint;
ICAutoUseSingleIdent.Caption:=lisAutomaticallyUseSinglePossibleIdent;
ICAutoUseSingleIdent.Hint:=
@ -131,6 +140,10 @@ begin
ICAddSemicolonCheckBox.Checked := IdentComplAddSemicolon;
ICAddAssignOperatorCheckBox.Checked := IdentComplAddAssignOperator;
ICAddDoCheckBox.Checked := IdentComplAddDo;
ICAutoInvokeOnTypeCheckBox.Checked := IdentComplAutoInvokeOnType;
ICAutoOnTypeUseTimer.Checked := IdentComplOnTypeUseTimer;
ICAutoOnTypeOnlyWordEnd.Checked := IdentComplOnTypeOnlyWordEnd;
ICAutoOnTypeMinLength.Value := IdentComplOnTypeMinLength;
ICAutoStartAfterPointCheckBox.Checked := IdentComplAutoStartAfterPoint;
ICAutoUseSingleIdent.Checked := IdentComplAutoUseSingleIdent;
ICAutoAddParameterBracketsCheckBox.Checked:=IdentComplAddParameterBrackets;
@ -159,6 +172,10 @@ begin
IdentComplAddSemicolon := ICAddSemicolonCheckBox.Checked;
IdentComplAddAssignOperator := ICAddAssignOperatorCheckBox.Checked;
IdentComplAddDo := ICAddDoCheckBox.Checked;
IdentComplAutoInvokeOnType := ICAutoInvokeOnTypeCheckBox.Checked;
IdentComplOnTypeUseTimer := ICAutoOnTypeUseTimer.Checked;
IdentComplOnTypeOnlyWordEnd := ICAutoOnTypeOnlyWordEnd.Checked;
IdentComplOnTypeMinLength := ICAutoOnTypeMinLength.Value;
IdentComplAutoStartAfterPoint := ICAutoStartAfterPointCheckBox.Checked;
IdentComplAutoUseSingleIdent := ICAutoUseSingleIdent.Checked;
IdentComplAddParameterBrackets:=ICAutoAddParameterBracketsCheckBox.Checked;

View File

@ -5962,6 +5962,10 @@ resourcestring
+'exist. Values were not checked.';
lisInsertPrintShortTag = 'Insert PrintShort tag';
lisIdCOpening = 'Opening';
lisAutomaticallyInvokeOnType = 'Automatically invoke on typing';
lisAutomaticallyInvokeOnTypeUseTimer = 'Use completion box delay';
lisAutomaticallyInvokeOnTypeOnlyWordEnd = 'Only complete when at end of word';
lisAutomaticallyInvokeOnTypeMinLength = 'Only complete if word is longer or equal';
lisAutomaticallyInvokeAfterPoint = 'Automatically invoke after point';
lisAutomaticallyUseSinglePossibleIdent = 'Automatically use single possible identifier';
lisWhenThereIsOnlyOnePossibleCompletionItemUseItImmed = 'When there is only '

View File

@ -248,6 +248,10 @@ type
// when text is inserted/deleted
FOnIfdefNodeStateRequest: TSynMarkupIfdefStateRequest;
FLastIfDefNodeScannerStep: integer;
FCodeCompletionState: record
State: (ccsReady, ccsCancelled, ccsDot, ccsOnTyping, ccsOnTypingScheduled);
LastTokenStartPos: TPoint;
end;
FSyncroLockCount: Integer;
FPageName: string;
@ -462,7 +466,10 @@ type
procedure MoveToWindow(AWindowIndex: Integer); override;
procedure CopyToWindow(AWindowIndex: Integer); override;
function GetCodeAttributeName(LogXY: TPoint): String;
// used to get the word at the mouse cursor
function CurrentWordLogStartOrCaret: TPoint;
function GetWordFromCaret(const ACaretPos: TPoint): String;
function GetWordAtCurrentCaret: String;
function GetOperandFromCaret(const ACaretPos: TPoint): String;
@ -2135,6 +2142,8 @@ begin
FAutoHideHintTimer.Enabled := False;
if AutoStartCompletionBoxTimer<>nil then
AutoStartCompletionBoxTimer.Enabled:=false;
if FManager.ActiveEditor.FCodeCompletionState.State in [ccsDot, ccsOnTyping] then
FManager.ActiveEditor.FCodeCompletionState.State := ccsReady;
if FAutoShown then
HideHint;
end;
@ -2389,6 +2398,11 @@ begin
end;
//debugln(GetStackTrace(true));
{$ENDIF}
with Manager.ActiveEditor do begin
FCodeCompletionState.LastTokenStartPos := CurrentWordLogStartOrCaret;
FCodeCompletionState.State := ccsCancelled;
end;
end;
procedure TSourceEditCompletion.ccComplete(var Value: string;
@ -2516,10 +2530,12 @@ Begin
Manager.DeactivateCompletionForm;
//DebugLn(['TSourceNotebook.ccComplete ',KeyChar,' ',OldCompletionType=ctIdentCompletion]);
Manager.ActiveEditor.FCodeCompletionState.State := ccsReady;
if (KeyChar='.') and (OldCompletionType=ctIdentCompletion) then
begin
SourceCompletionCaretXY:=Editor.LogicalCaretXY;
AutoStartCompletionBoxTimer.AutoEnabled:=true;
Manager.ActiveEditor.FCodeCompletionState.State := ccsDot;
end
else if prototypeAdded and EditorOpts.AutoDisplayFunctionPrototypes then
begin
@ -3876,13 +3892,16 @@ procedure TSourceEditor.ProcessCommand(Sender: TObject;
// define extra actions here
// for non synedit keys (bigger than ecUserFirst) use ProcessUserCommand
var
AddChar: Boolean;
s: String;
i: Integer;
AddChar, IsIdent, ok: Boolean;
s, AttrName: String;
i, WordStart, WordEnd: Integer;
p: TPoint;
begin
//DebugLn('TSourceEditor.ProcessCommand Command=',dbgs(Command));
FSharedValues.SetActiveSharedEditor(Self);
AutoStartCompletionBoxTimer.AutoEnabled:=false;
if FCodeCompletionState.State in [ccsDot, ccsOnTyping] then
FCodeCompletionState.State := ccsReady;
if (Command=ecChar) and (AChar=#27) then begin
// close hint windows
@ -3969,19 +3988,62 @@ begin
ecChar:
begin
AddChar:=true;
IsIdent:=FEditor.IsIdentChar(aChar);
//debugln(['TSourceEditor.ProcessCommand AChar="',AChar,'" AutoIdentifierCompletion=',dbgs(EditorOpts.AutoIdentifierCompletion),' Interval=',AutoStartCompletionBoxTimer.Interval,' ',Dbgs(FEditor.CaretXY),' ',FEditor.IsIdentChar(aChar)]);
if (aChar=' ') and AutoCompleteChar(aChar,AddChar,acoSpace) then begin
// completed
end
else if (not FEditor.IsIdentChar(aChar))
else
if (not IsIdent)
and AutoCompleteChar(aChar,AddChar,acoWordEnd) then begin
// completed
end else if CodeToolsOpts.IdentComplAutoStartAfterPoint then begin
// store caret position to detect caret changes
end
else
if CodeToolsOpts.IdentComplAutoInvokeOnType and
( IsIdent or (AChar='.') )
then begin
// store caret position to detect caret changes // add the char
p := FEditor.LogicalCaretXY;
SourceCompletionCaretXY:=p;
inc(SourceCompletionCaretXY.x,length(AChar));
AttrName := GetCodeAttributeName(p);
ok := (AttrName <> SYNS_XML_AttrComment) and
(AttrName <> SYNS_XML_AttrDirective) and
(AttrName <> SYNS_XML_AttrString);
if ok then begin
if AChar = '.' then begin
ok := CodeToolsOpts.IdentComplAutoStartAfterPoint;
end
else
if (CodeToolsOpts.IdentComplOnTypeMinLength > 1) or CodeToolsOpts.IdentComplOnTypeOnlyWordEnd
then begin
FEditor.GetWordBoundsAtRowCol(p, WordStart, WordEnd);
ok := (p.x <= WordEnd) and // inside word
((not CodeToolsOpts.IdentComplOnTypeOnlyWordEnd) or (p.x = WordEnd)) and // at word end?
((WordEnd-WordStart+1) >= CodeToolsOpts.IdentComplOnTypeMinLength);
end;
end;
if ok then begin
if CodeToolsOpts.IdentComplOnTypeUseTimer then begin
AutoStartCompletionBoxTimer.AutoEnabled:=true;
FCodeCompletionState.State := ccsOnTyping;
end
else begin
FCodeCompletionState.State := ccsOnTypingScheduled;
end;
end;
end
else
if CodeToolsOpts.IdentComplAutoStartAfterPoint and
(AChar='.')
then begin
// store caret position to detect caret changes // add the char
SourceCompletionCaretXY:=FEditor.LogicalCaretXY;
// add the char
inc(SourceCompletionCaretXY.x,length(AChar));
AutoStartCompletionBoxTimer.AutoEnabled:=true;
FCodeCompletionState.State := ccsDot;
end;
//DebugLn(['TSourceEditor.ProcessCommand ecChar AddChar=',AddChar]);
if not AddChar then Command:=ecNone;
@ -4138,8 +4200,15 @@ procedure TSourceEditor.UserCommandProcessed(Sender: TObject;
var Handled: boolean;
begin
Handled:=true;
case Command of
if (Command <> ecCompleteCode) and (Command <> ecCompleteCodeInteractive) and
(FCodeCompletionState.State = ccsCancelled)
then begin
if CompareCaret(FCodeCompletionState.LastTokenStartPos, CurrentWordLogStartOrCaret) <> 0 then
FCodeCompletionState.State := ccsReady;
end;
case Command of
ecNone: ;
ecChar:
@ -4149,6 +4218,11 @@ begin
if EditorOpts.AutoDisplayFunctionPrototypes then
if (aChar = '(') or (aChar = ',') then
SourceNotebook.StartShowCodeContext(False);
if FCodeCompletionState.State = ccsOnTypingScheduled then begin
FCodeCompletionState.State := ccsOnTyping;
StartIdentCompletionBox(false,false);
end;
end;
else
@ -5195,7 +5269,9 @@ begin
if UseWordCompletion then
Completion.CurrentCompletionType:=ctWordCompletion;
Completion.AutoUseSingleIdent := CanAutoComplete and CodeToolsOpts.IdentComplAutoUseSingleIdent;
Completion.AutoUseSingleIdent := CanAutoComplete and
(FCodeCompletionState.State = ccsDot) and
CodeToolsOpts.IdentComplAutoUseSingleIdent;
Completion.Execute(TextS2, CompletionRect);
{$IFDEF VerboseIDECompletionBox}
debugln(['TSourceEditor.StartIdentCompletionBox END Completion.TheForm.Visible=',Completion.TheForm.Visible]);
@ -5834,6 +5910,16 @@ begin
FEditor.Lines:=AValue;
end;
function TSourceEditor.CurrentWordLogStartOrCaret: TPoint;
var
StartX, EndX: integer;
begin
Result := FEditor.LogicalCaretXY;
FEditor.GetWordBoundsAtRowCol(Result, StartX, EndX);
if (Result.x >= StartX) and (Result.x <= EndX) then
Result.x := StartX;
end;
function TSourceEditor.GetProjectFile: TLazProjectFile;
begin
Result:=LazarusIDE.GetProjectFileForProjectEditor(Self);
@ -6118,6 +6204,19 @@ begin
SourceNotebook.CopyEditor(PageIndex, AWindowIndex, -1)
end;
function TSourceEditor.GetCodeAttributeName(LogXY: TPoint): String;
var
Token: string;
Attri: TSynHighlighterAttributes;
begin
Result := '';
if EditorComponent.GetHighlighterAttriAtRowCol(LogXY,Token,Attri)
and (Attri<>nil) then
begin
Result := Attri.StoredName;
end;
end;
procedure TSourceEditor.LineInfoNotificationChange(const ASender: TObject; const ASource: String);
begin
if ASource = FileName then begin
@ -11042,25 +11141,15 @@ procedure TSourceEditorManager.OnSourceCompletionTimer(Sender: TObject);
function CheckCodeAttribute (XY: TPoint; out CodeAttri: String): Boolean;
var
SrcEdit: TSourceEditor;
Token: string;
Attri: TSynHighlighterAttributes;
begin
Result := False;
SrcEdit := ActiveEditor;
if SrcEdit = nil then exit;
Token:='';
Attri:=nil;
dec(XY.X);
if SrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(XY,Token,Attri)
and (Attri<>nil) then
begin
CodeAttri := Attri.StoredName;
Result := True;
end;
CodeAttri := SrcEdit.GetCodeAttributeName(XY);
Result := CodeAttri <> '';
end;
function CheckStartIdentCompletion: boolean;
@ -11069,7 +11158,6 @@ procedure TSourceEditorManager.OnSourceCompletionTimer(Sender: TObject);
LogCaret: TPoint;
SrcEdit: TSourceEditor;
CodeAttribute: String;
aChar: Char;
begin
Result := false;
SrcEdit := ActiveEditor;
@ -11083,7 +11171,8 @@ procedure TSourceEditorManager.OnSourceCompletionTimer(Sender: TObject);
// check if last character is a point
if (Line='') or (LogCaret.X<=1) or (LogCaret.X-1>length(Line))
or (Line[LogCaret.X-1]<>'.') then
or ((SrcEdit.FCodeCompletionState.State = ccsDot) and (Line[LogCaret.X-1]<>'.'))
then
exit;
if not CheckCodeAttribute(LogCaret, CodeAttribute) then