mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-28 05:08:57 +02:00
codetools: complete blocks for inner blocks
git-svn-id: trunk@20210 -
This commit is contained in:
parent
e289f31627
commit
20fca2cad7
@ -5247,7 +5247,7 @@ var
|
|||||||
LastPos: Integer;
|
LastPos: Integer;
|
||||||
LineStart: boolean; // Atom is first atom of a line in cursor block (not in sub block)
|
LineStart: boolean; // Atom is first atom of a line in cursor block (not in sub block)
|
||||||
Indent: Integer;
|
Indent: Integer;
|
||||||
CursorBlockIndent: LongInt;
|
CursorBlockInnerIndent, CursorBlockOuterIndent: LongInt;
|
||||||
CursorBlock: TBlock;
|
CursorBlock: TBlock;
|
||||||
BehindCursorBlock: Boolean; // atom behind cursor block
|
BehindCursorBlock: Boolean; // atom behind cursor block
|
||||||
InCursorBlock: Boolean;
|
InCursorBlock: Boolean;
|
||||||
@ -5272,7 +5272,8 @@ var
|
|||||||
MoveCursorToNodeStart(StartNode);
|
MoveCursorToNodeStart(StartNode);
|
||||||
CursorBlockLvl:=-2;
|
CursorBlockLvl:=-2;
|
||||||
LastPos:=-1;
|
LastPos:=-1;
|
||||||
CursorBlockIndent:=0;
|
CursorBlockOuterIndent:=0;
|
||||||
|
CursorBlockInnerIndent:=0;
|
||||||
Indent:=0;
|
Indent:=0;
|
||||||
CursorBlock.StartPos:=0;
|
CursorBlock.StartPos:=0;
|
||||||
BehindCursorBlock:=false;
|
BehindCursorBlock:=false;
|
||||||
@ -5291,7 +5292,8 @@ var
|
|||||||
exit;
|
exit;
|
||||||
end else begin
|
end else begin
|
||||||
CursorBlock:=Stack.Stack[CursorBlockLvl];
|
CursorBlock:=Stack.Stack[CursorBlockLvl];
|
||||||
CursorBlockIndent:=GetLineIndent(Src,CursorBlock.StartPos);
|
CursorBlockOuterIndent:=GetLineIndent(Src,CursorBlock.StartPos);
|
||||||
|
CursorBlockInnerIndent:=GetLineIndent(Src,CurPos.StartPos);
|
||||||
end;
|
end;
|
||||||
//DebugLn(['ReadStatements CursorBlockLvl=',CursorBlockLvl,' Indent=',CursorBlockIndent]);
|
//DebugLn(['ReadStatements CursorBlockLvl=',CursorBlockLvl,' Indent=',CursorBlockIndent]);
|
||||||
end;
|
end;
|
||||||
@ -5300,8 +5302,30 @@ var
|
|||||||
if (CurPos.StartPos>SrcLen) or (CurPos.StartPos>=StartNode.EndPos) then
|
if (CurPos.StartPos>SrcLen) or (CurPos.StartPos>=StartNode.EndPos) then
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// check if line start vs outer indent
|
||||||
InCursorBlock:=(CursorBlockLvl>=0) and (CursorBlockLvl=Stack.Top)
|
InCursorBlock:=(CursorBlockLvl>=0) and (CursorBlockLvl=Stack.Top)
|
||||||
and (not BehindCursorBlock);
|
and (not BehindCursorBlock);
|
||||||
|
LineStart:=InCursorBlock and (LastPos>0)
|
||||||
|
and not PositionsInSameLine(Src,LastPos,CurPos.StartPos);
|
||||||
|
if LineStart then
|
||||||
|
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
||||||
|
|
||||||
|
if LineStart then begin
|
||||||
|
// atom is in same block as cursor (not sub block)
|
||||||
|
// and first atom of a line
|
||||||
|
// => check indent
|
||||||
|
if Indent<CursorBlockOuterIndent then begin
|
||||||
|
// for example:
|
||||||
|
// begin
|
||||||
|
// |
|
||||||
|
// end;
|
||||||
|
//DebugLn(['ReadStatements Indent=',Indent,' < CursorBlockIndent=',CursorBlockIndent]);
|
||||||
|
{$IFDEF ShowCompleteBlock}
|
||||||
|
DebugLn(['ReadStatements NeedCompletion: at ',CleanPosToStr(CurPos.StartPos),' Indent=',Indent,' < CursorBlockOuterIndent=',CursorBlockOuterIndent]);
|
||||||
|
{$ENDIF}
|
||||||
|
NeedCompletion:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
// check block starts/ends
|
// check block starts/ends
|
||||||
case CurPos.Flag of
|
case CurPos.Flag of
|
||||||
@ -5434,19 +5458,19 @@ var
|
|||||||
// check if line start
|
// check if line start
|
||||||
InCursorBlock:=(CursorBlockLvl>=0) and (CursorBlockLvl=Stack.Top)
|
InCursorBlock:=(CursorBlockLvl>=0) and (CursorBlockLvl=Stack.Top)
|
||||||
and (not BehindCursorBlock);
|
and (not BehindCursorBlock);
|
||||||
LineStart:=InCursorBlock and (LastPos>0)
|
if LineStart and InCursorBlock then begin
|
||||||
and not PositionsInSameLine(Src,LastPos,CurPos.StartPos);
|
|
||||||
if LineStart then
|
|
||||||
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
||||||
|
|
||||||
if LineStart then begin
|
|
||||||
// atom is in same block as cursor (not sub block)
|
// atom is in same block as cursor (not sub block)
|
||||||
// and first atom of a line
|
// and first atom of a line
|
||||||
// => check indent
|
// => check indent
|
||||||
if Indent<CursorBlockIndent then begin
|
if Indent<CursorBlockInnerIndent then begin
|
||||||
|
// for example:
|
||||||
|
// Code;
|
||||||
|
// |
|
||||||
|
// Code;
|
||||||
//DebugLn(['ReadStatements Indent=',Indent,' < CursorBlockIndent=',CursorBlockIndent]);
|
//DebugLn(['ReadStatements Indent=',Indent,' < CursorBlockIndent=',CursorBlockIndent]);
|
||||||
{$IFDEF ShowCompleteBlock}
|
{$IFDEF ShowCompleteBlock}
|
||||||
DebugLn(['ReadStatements NeedCompletion: at ',CleanPosToStr(CurPos.StartPos),' Indent=',Indent,' < CursorBlockIndent=',CursorBlockIndent]);
|
DebugLn(['ReadStatements NeedCompletion: at ',CleanPosToStr(CurPos.StartPos),' Indent=',Indent,' < CursorBlockInnerIndent=',CursorBlockInnerIndent]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
NeedCompletion:=true;
|
NeedCompletion:=true;
|
||||||
end;
|
end;
|
||||||
@ -5467,7 +5491,7 @@ var
|
|||||||
|
|
||||||
if NeedCompletion then begin
|
if NeedCompletion then begin
|
||||||
InsertPos:=CleanCursorPos;
|
InsertPos:=CleanCursorPos;
|
||||||
Indent:=CursorBlockIndent;
|
Indent:=CursorBlockInnerIndent;
|
||||||
NewCode:='';
|
NewCode:='';
|
||||||
FrontGap:=gtNewLine;
|
FrontGap:=gtNewLine;
|
||||||
AfterGap:=gtNewLine;
|
AfterGap:=gtNewLine;
|
||||||
|
Loading…
Reference in New Issue
Block a user