From b4b5016f20e865603e45496dc7933eda77e895c5 Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 11 Jul 2010 11:27:44 +0000 Subject: [PATCH] codetools: completeblock: complete if unindent and cursor at unindent or in empty line git-svn-id: trunk@26594 - --- components/codetools/basiccodetools.pas | 29 +++++++++++ components/codetools/keywordfunclists.pas | 2 +- components/codetools/stdcodetools.pas | 61 ++++++++++++++++++----- 3 files changed, 79 insertions(+), 13 deletions(-) diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index cd0c646b55..3d23246e65 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -64,6 +64,7 @@ function ExtractCommentContent(const ASource: string; CommentStart: integer; TrimStart: boolean = false; TrimEnd: boolean = false; TrimPasDoc: boolean = false): string; function FindMainUnitHint(const ASource: string; out Filename: string): boolean; +function InEmptyLine(const ASource: string; StartPos: integer): boolean; // indent function GetLineIndent(const Source: string; Position: integer): integer; @@ -3287,6 +3288,34 @@ begin Result:=true; end; +function InEmptyLine(const ASource: string; StartPos: integer): boolean; +var + p: LongInt; + SrcLen: Integer; +begin + Result:=false; + SrcLen:=length(ASource); + if (StartPos<1) or (StartPos>SrcLen) or (not IsSpaceChar[ASource[StartPos]]) + then exit; + p:=StartPos; + while (p>1) do begin + case ASource[p-1] of + ' ',#9: dec(p); + #10,#13: break; + else exit; + end; + end; + p:=StartPos; + while p<=SrcLen do begin + case ASource[p] of + ' ',#9: inc(p); + #10,#13: break; + else exit; + end; + end; + Result:=true; +end; + function CompareIdentifiers(Identifier1, Identifier2: PChar): integer; begin if (Identifier1<>nil) then begin diff --git a/components/codetools/keywordfunclists.pas b/components/codetools/keywordfunclists.pas index 97b2e4a24f..4c489ea2dc 100644 --- a/components/codetools/keywordfunclists.pas +++ b/components/codetools/keywordfunclists.pas @@ -154,7 +154,7 @@ var : TKeyWordFunctionList; UpChars: array[char] of char; - IsSpaceChar, + IsSpaceChar, // [#0..#32] IsLineEndChar, IsWordChar, // ['a'..'z','A'..'Z'] IsNonWordChar, // [#0..#127]-IsIdentChar diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 71b74211c8..d44fd03663 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -5105,6 +5105,7 @@ type var CleanCursorPos: integer; StartNode: TCodeTreeNode; + CursorInEmptyLine: Boolean; procedure InitStack(out Stack: TBlockStack); begin @@ -5351,14 +5352,44 @@ var if (Indent skip']); + DebugLn(['CompleteStatements code behind is indented more (Behind=',GetLineIndent(Src,BehindPos),' > Indent=',Indent,') => skip']); {$ENDIF} exit; end; @@ -5767,6 +5802,8 @@ begin [btSetIgnoreErrorPos]); StartNode:=FindDeepestNodeAtPos(CleanCursorPos,true); + CursorInEmptyLine:=InEmptyLine(Src,CleanCursorPos); + //debugln(['TStandardCodeTool.CompleteBlock ',CursorInEmptyLine,' ',dbgstr(copy(Src,CleanCursorPos-10,10)),'|',dbgstr(copy(Src,CleanCursorPos,10))]); SourceChangeCache.MainScanner:=Scanner; InitStack(Stack); try