From 1f20bd9b6ccae66e2de2a7ca2e2045b1f5e29fa9 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Tue, 2 May 2017 17:20:07 +0200 Subject: [PATCH] add option to auto call completion features, close #134 --- src/ce_editoroptions.pas | 4 ++++ src/ce_synmemo.pas | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ce_editoroptions.pas b/src/ce_editoroptions.pas index 731c0c62..b394bc91 100644 --- a/src/ce_editoroptions.pas +++ b/src/ce_editoroptions.pas @@ -64,6 +64,7 @@ type fAutoClosedPairs: TAutoClosePairs; fSmartDdocNewline: boolean; fInsertPlusDdoc: boolean; + fAutoCallCompletion: boolean; // procedure setPhobosDocRoot(value: TCEPathname); procedure setFont(value: TFont); @@ -82,6 +83,7 @@ type procedure setLineNumEvery(value: integer); published property alwaysAdvancedFeatures: boolean read fAlwaysAdvancedFeatures write fAlwaysAdvancedFeatures; + property autoCallCompletion: boolean read fAutoCallCompletion write fAutoCallCompletion; property autoCloseCurlyBrace: TBraceAutoCloseStyle read fAutoCloseCurlyBrace write fAutoCloseCurlyBrace default TBraceAutoCloseStyle.autoCloseNever; property autoClosedPairs: TAutoClosePairs read fAutoClosedPairs write fAutoClosedPairs default[]; property autoDotDelay: integer read fAutoDotDelay write SetautoDotDelay; @@ -307,6 +309,7 @@ begin detectIndentMode:=srcopt.detectIndentMode; fPhobosDocRoot:=srcopt.fPhobosDocRoot; fInsertPlusDdoc:= srcopt.fInsertPlusDdoc; + fAutoCallCompletion:= srcopt.fAutoCallCompletion; fSmartDdocNewline:=srcopt.fSmartDdocNewline; if fSmartDdocNewline then @@ -678,6 +681,7 @@ begin anEditor.alwaysAdvancedFeatures:=fAlwaysAdvancedFeatures; anEditor.smartDdocNewline:= fSmartDdocNewline; anEditor.insertPlusDdoc:= fInsertPlusDdoc; + anEditor.autoCallCompletion:= fAutoCallCompletion; for i := 0 to anEditor.Keystrokes.Count-1 do begin kst := anEditor.Keystrokes.Items[i]; diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index c34a6b78..42d7309f 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -13,7 +13,8 @@ uses //SynEditMarkupFoldColoring, Clipbrd, fpjson, jsonparser, LazUTF8, LazUTF8Classes, Buttons, StdCtrls, ce_common, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs, ce_dastworx, - ce_sharedres, ce_dlang, ce_stringrange, ce_dbgitf, ce_observer, ce_diff; + ce_sharedres, ce_dlang, ce_stringrange, ce_dbgitf, ce_observer, ce_diff, + ce_dlangutils; type @@ -182,6 +183,7 @@ type fLastCompletion: string; fDebugger: ICEDebugger; fInsertPlusDdoc: boolean; + fAutoCallCompletion: boolean; procedure decCallTipsLvl; procedure setMatchOpts(value: TIdentifierMatchOptions); function getMouseBytePosition: Integer; @@ -307,6 +309,7 @@ type property autoClosedPairs: TAutoClosePairs read fAutoClosedPairs write fAutoClosedPairs; property smartDdocNewline: boolean read fSmartDdocNewline write fSmartDdocNewline; property insertPlusDdoc: boolean read fInsertPlusDdoc write fInsertPlusDdoc; + property autoCallCompletion: boolean read fAutoCallCompletion write fAutoCallCompletion; end; TSortDialog = class(TForm) @@ -2084,8 +2087,8 @@ procedure TCESynMemo.completionCodeCompletion(var value: string; SourceValue: string; var SourceStart, SourceEnd: TPoint; KeyChar: TUTF8Char; Shift: TShiftState); begin - if KeyChar = '.' then - value := '.' + if (isOperator1(KeyChar[1])) or (KeyChar[1] = ' ') then + value := SourceValue + KeyChar else fLastCompletion := value; end; @@ -2610,7 +2613,7 @@ begin inherited; highlightCurrentIdentifier; if fCompletion.IsActive then - fCompletion.CurrentString:= GetWordAtRowCol(LogicalCaretXY); + fCompletion.CurrentString:= GetWordAtRowCol(LogicalCaretXY); case Key of VK_BROWSER_BACK: fPositions.back; VK_BROWSER_FORWARD: fPositions.next; @@ -2637,7 +2640,12 @@ begin VK_OEM_PERIOD, VK_DECIMAL: fCanAutoDot := true; end; inherited; - + if fAutoCallCompletion and fIsDSource and (not fCompletion.IsActive) and + (Key < $80) and (char(Key) in ['a'..'z', 'A'..'Z']) then + begin + fCompletion.Execute(GetWordAtRowCol(LogicalCaretXY), + ClientToScreen(point(CaretXPix, CaretYPix + LineHeight))); + end; if StaticEditorMacro.automatic then StaticEditorMacro.Execute; end;