From 8dbce64dd06e45707540fc76f7e698e5f1b01aa4 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 3 May 2017 01:34:41 +0200 Subject: [PATCH] completion menu, add special closing chars --- docs/widgets_editor.md | 2 ++ src/ce_editoroptions.pas | 22 ++++++++++++++++++++++ src/ce_synmemo.pas | 19 +++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/docs/widgets_editor.md b/docs/widgets_editor.md index d55ce0ef..47e0ce0f 100644 --- a/docs/widgets_editor.md +++ b/docs/widgets_editor.md @@ -118,6 +118,8 @@ The shortcuts are editable in the [shortcut editor](options_shortcuts_editor), u - **autoDotDelay**: Sets, in milliseconds, how responsive is the completion menu after a `.`. - **blockIndentation**: By default 4 for the D style. - **bracketMatch**: Defines the visual style applied to matching brackets pairs. +- **closeCompletionChars**: Defines the characters that, in addition to close the completion menu, are inserted after the proposal. +- **closeCompletionCharsWithSapce**: Defines the characters that, in addition to close the completion menu, are inserted after the proposal and a space. - **currentLine**: Defines the visual style applied to the current line. - **ddocDelay**: Sets, in milliseconds, how responsive is the popup that displays the inline documentation. - **detectIndentMode**: If checked the the indentation style (tabs or spaces) is detected when a document is opened. It's applied automatically when TAB is used. diff --git a/src/ce_editoroptions.pas b/src/ce_editoroptions.pas index b394bc91..ff86b110 100644 --- a/src/ce_editoroptions.pas +++ b/src/ce_editoroptions.pas @@ -65,6 +65,8 @@ type fSmartDdocNewline: boolean; fInsertPlusDdoc: boolean; fAutoCallCompletion: boolean; + fCloseCompletionCharsWithSpace: AnsiString; + fCloseCompletionChars: AnsiString; // procedure setPhobosDocRoot(value: TCEPathname); procedure setFont(value: TFont); @@ -91,6 +93,8 @@ type property blockIndentation: Integer read fBlockIdent write fBlockIdent default 4; property bracketMatch: TSynSelectedColor read fBracketMatchAttribs write setBracketMatchColor; property characterSpacing: Integer read fCharSpacing write fCharSpacing default 0; + property closeCompletionCharsWithSpace: AnsiString read fCloseCompletionCharsWithSpace write fCloseCompletionCharsWithSpace; + property closeCompletionChars: AnsiString read fCloseCompletionChars write fCloseCompletionChars; property completionMenuCaseCare: boolean read fCompletionMenuCaseCare write fCompletionMenuCaseCare; property completionMenuLines: byte read fCompletionMenuLines write setCompletionMenuLines; property completionMenuWidth: integer read fCompletionMenuWidth write fCompletionMenuWidth; @@ -240,6 +244,9 @@ begin fCurrLineAttribs.Background := 15789545; fCurrLineAttribs.Foreground := clNone; // + fCloseCompletionCharsWithSpace := '*+-/^=~><'; + fCloseCompletionChars:= ',;)}]!'; + // options1 := [eoAutoIndent, eoBracketHighlight, eoGroupUndo, eoTabsToSpaces, eoTrimTrailingSpaces, eoDragDropEditing, eoShowCtrlMouseLinks, eoEnhanceHomeKey, eoTabIndent]; @@ -310,6 +317,8 @@ begin fPhobosDocRoot:=srcopt.fPhobosDocRoot; fInsertPlusDdoc:= srcopt.fInsertPlusDdoc; fAutoCallCompletion:= srcopt.fAutoCallCompletion; + fCloseCompletionChars:=srcopt.fCloseCompletionChars; + fCloseCompletionCharsWithSpace:=srcopt.fCloseCompletionCharsWithSpace; fSmartDdocNewline:=srcopt.fSmartDdocNewline; if fSmartDdocNewline then @@ -637,6 +646,8 @@ var kst: TSynEditKeyStroke; dup: boolean; savedSize: integer; + cs: TSysCharSet; + c: char; begin anEditor.D2Highlighter.Assign(D2Syn); anEditor.TxtHighlighter.Assign(TxtSyn); @@ -682,6 +693,17 @@ begin anEditor.smartDdocNewline:= fSmartDdocNewline; anEditor.insertPlusDdoc:= fInsertPlusDdoc; anEditor.autoCallCompletion:= fAutoCallCompletion; + + cs := []; + for c in fCloseCompletionCharsWithSpace do + include(cs, c); + anEditor.closeCompletionCharsWithSpace:=cs; + + cs := []; + for c in fCloseCompletionChars do + include(cs, c); + anEditor.closeCompletionChars:=cs; + 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 b323863a..5c4708a3 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -13,8 +13,7 @@ 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_dlangutils; + ce_sharedres, ce_dlang, ce_stringrange, ce_dbgitf, ce_observer, ce_diff; type @@ -184,6 +183,8 @@ type fDebugger: ICEDebugger; fInsertPlusDdoc: boolean; fAutoCallCompletion: boolean; + fCloseCompletionCharsWithSpace: TSysCharSet; + fCloseCompletionChars: TSysCharSet; procedure decCallTipsLvl; procedure setMatchOpts(value: TIdentifierMatchOptions); function getMouseBytePosition: Integer; @@ -311,6 +312,8 @@ type property smartDdocNewline: boolean read fSmartDdocNewline write fSmartDdocNewline; property insertPlusDdoc: boolean read fInsertPlusDdoc write fInsertPlusDdoc; property autoCallCompletion: boolean read fAutoCallCompletion write fAutoCallCompletion; + property closeCompletionCharsWithSpace: TSysCharSet read fCloseCompletionCharsWithSpace write fCloseCompletionCharsWithSpace; + property closeCompletionChars: TSysCharSet read fCloseCompletionChars write fCloseCompletionChars; end; TSortDialog = class(TForm) @@ -2089,10 +2092,18 @@ procedure TCESynMemo.completionCodeCompletion(var value: string; SourceValue: string; var SourceStart, SourceEnd: TPoint; KeyChar: TUTF8Char; Shift: TShiftState); begin - if (isOperator1(KeyChar[1])) or (KeyChar[1] = ' ') then - value := SourceValue + KeyChar + if (KeyChar[1] = ' ') then + begin + value := sourceValue + KeyChar; + end else + begin fLastCompletion := value; + if KeyChar[1] in fCloseCompletionCharsWithSpace then + value += ' ' + KeyChar + else if KeyChar[1] in fCloseCompletionChars then + value += KeyChar; + end; end; procedure TCESynMemo.completionFormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);