mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 10:39:30 +02:00
IDE: auto indent: using SynEdit.OnPaste event
git-svn-id: trunk@22452 -
This commit is contained in:
parent
c9f863d3a3
commit
166ccb9e94
@ -296,11 +296,13 @@ type
|
|||||||
procedure ParseSource(const Src: string; StartPos, EndPos: integer;
|
procedure ParseSource(const Src: string; StartPos, EndPos: integer;
|
||||||
NestedComments: boolean;
|
NestedComments: boolean;
|
||||||
Stack: TFABBlockStack; Policies: TFABPolicies;
|
Stack: TFABBlockStack; Policies: TFABPolicies;
|
||||||
out LastAtomStart, LastAtomEnd: integer // set if LastAtomStart<EndPos<LastAtomEnd
|
out LastAtomStart, LastAtomEnd: integer; // set if LastAtomStart<EndPos<LastAtomEnd
|
||||||
|
LearnFromFirstLine: boolean = true
|
||||||
);
|
);
|
||||||
procedure ParseSource(const Src: string; StartPos, EndPos: integer;
|
procedure ParseSource(const Src: string; StartPos, EndPos: integer;
|
||||||
NestedComments: boolean;
|
NestedComments: boolean;
|
||||||
Stack: TFABBlockStack; Policies: TFABPolicies);
|
Stack: TFABBlockStack; Policies: TFABPolicies;
|
||||||
|
LearnFromFirstLine: boolean = true);
|
||||||
function FindPolicyInExamples(StartCode: TCodeBuffer;
|
function FindPolicyInExamples(StartCode: TCodeBuffer;
|
||||||
ParentTyp, Typ: TFABBlockType): TFABPolicies;
|
ParentTyp, Typ: TFABBlockType): TFABPolicies;
|
||||||
function GetNestedCommentsForCode(Code: TCodeBuffer): boolean;
|
function GetNestedCommentsForCode(Code: TCodeBuffer): boolean;
|
||||||
@ -316,7 +318,8 @@ type
|
|||||||
function GetIndent(const Source: string; CleanPos: integer;
|
function GetIndent(const Source: string; CleanPos: integer;
|
||||||
NewNestedComments: boolean; UseLineStart: boolean;
|
NewNestedComments: boolean; UseLineStart: boolean;
|
||||||
out Indent: TFABIndentationPolicy;
|
out Indent: TFABIndentationPolicy;
|
||||||
ContextLearn: boolean = true // true = learn policies from Source
|
ContextLearn: boolean = true; // true = learn policies from Source
|
||||||
|
const InsertText: string = ''
|
||||||
): boolean;
|
): boolean;
|
||||||
function GetIndents(const Source: string; Positions: TFABPositionIndents;
|
function GetIndents(const Source: string; Positions: TFABPositionIndents;
|
||||||
NewNestedComments: boolean; UseLineStart: boolean;
|
NewNestedComments: boolean; UseLineStart: boolean;
|
||||||
@ -438,11 +441,13 @@ end;
|
|||||||
|
|
||||||
procedure TFullyAutomaticBeautifier.ParseSource(const Src: string;
|
procedure TFullyAutomaticBeautifier.ParseSource(const Src: string;
|
||||||
StartPos, EndPos: integer; NestedComments: boolean; Stack: TFABBlockStack;
|
StartPos, EndPos: integer; NestedComments: boolean; Stack: TFABBlockStack;
|
||||||
Policies: TFABPolicies; out LastAtomStart, LastAtomEnd: integer);
|
Policies: TFABPolicies; out LastAtomStart, LastAtomEnd: integer;
|
||||||
|
LearnFromFirstLine: boolean);
|
||||||
var
|
var
|
||||||
p: Integer;
|
p: Integer;
|
||||||
AtomStart: integer;
|
AtomStart: integer;
|
||||||
FirstAtomOnNewLine: Boolean;
|
FirstAtomOnNewLine: Boolean;
|
||||||
|
InFirstLine: boolean;
|
||||||
|
|
||||||
{$IFDEF ShowCodeBeautifierLearn}
|
{$IFDEF ShowCodeBeautifierLearn}
|
||||||
function PosToStr(p: integer): string;
|
function PosToStr(p: integer): string;
|
||||||
@ -484,6 +489,7 @@ var
|
|||||||
and (Policies<>nil) then begin
|
and (Policies<>nil) then begin
|
||||||
if Block^.InnerIdent<0 then UpdateBlockInnerIndent;
|
if Block^.InnerIdent<0 then UpdateBlockInnerIndent;
|
||||||
if Block^.InnerIdent>=0 then begin
|
if Block^.InnerIdent>=0 then begin
|
||||||
|
if LearnFromFirstLine or (not InFirstLine) then
|
||||||
Policies.AddIndent(Block^.Typ,Typ,p,Block^.InnerIdent);
|
Policies.AddIndent(Block^.Typ,Typ,p,Block^.InnerIdent);
|
||||||
{$IFDEF ShowCodeBeautifierLearn}
|
{$IFDEF ShowCodeBeautifierLearn}
|
||||||
DebugLn([GetIndentStr(Stack.Top*2),'nested indentation learned ',FABBlockTypeNames[Block^.Typ],'/',FABBlockTypeNames[Typ],': ',GetAtomString(@Src[AtomStart],NestedComments),' at ',PosToStr(p),' Indent=',Block^.InnerIdent]);
|
DebugLn([GetIndentStr(Stack.Top*2),'nested indentation learned ',FABBlockTypeNames[Block^.Typ],'/',FABBlockTypeNames[Typ],': ',GetAtomString(@Src[AtomStart],NestedComments),' at ',PosToStr(p),' Indent=',Block^.InnerIdent]);
|
||||||
@ -642,10 +648,13 @@ begin
|
|||||||
p:=StartPos;
|
p:=StartPos;
|
||||||
if EndPos>length(Src) then EndPos:=length(Src)+1;
|
if EndPos>length(Src) then EndPos:=length(Src)+1;
|
||||||
AtomStart:=p;
|
AtomStart:=p;
|
||||||
|
InFirstLine:=true;
|
||||||
repeat
|
repeat
|
||||||
LastAtomStart:=AtomStart;
|
LastAtomStart:=AtomStart;
|
||||||
LastAtomEnd:=p;
|
LastAtomEnd:=p;
|
||||||
ReadRawNextPascalAtom(Src,p,AtomStart,NestedComments);
|
ReadRawNextPascalAtom(Src,p,AtomStart,NestedComments);
|
||||||
|
if InFirstLine and (not PositionsInSameLine(Src,LastAtomEnd,AtomStart)) then
|
||||||
|
InFirstLine:=false;
|
||||||
//DebugLn(['TFullyAutomaticBeautifier.ParseSource Atom=',copy(Src,AtomStart,p-AtomStart)]);
|
//DebugLn(['TFullyAutomaticBeautifier.ParseSource Atom=',copy(Src,AtomStart,p-AtomStart)]);
|
||||||
if p>EndPos then begin
|
if p>EndPos then begin
|
||||||
if (AtomStart<EndPos) then begin
|
if (AtomStart<EndPos) then begin
|
||||||
@ -1037,7 +1046,8 @@ begin
|
|||||||
|
|
||||||
if FirstAtomOnNewLine then begin
|
if FirstAtomOnNewLine then begin
|
||||||
UpdateBlockInnerIndent;
|
UpdateBlockInnerIndent;
|
||||||
if Block^.InnerIdent>=0 then begin
|
if (Block^.InnerIdent>=0)
|
||||||
|
and (LearnFromFirstLine or (not InFirstLine)) then begin
|
||||||
Policies.AddIndent(Block^.Typ,bbtNone,p,Block^.InnerIdent);
|
Policies.AddIndent(Block^.Typ,bbtNone,p,Block^.InnerIdent);
|
||||||
{$IFDEF ShowCodeBeautifierLearn}
|
{$IFDEF ShowCodeBeautifierLearn}
|
||||||
DebugLn([GetIndentStr(Stack.Top*2),'Indentation learned for statements: ',FABBlockTypeNames[Block^.Typ],' Indent=',Block^.InnerIdent,' at ',PosToStr(p)]);
|
DebugLn([GetIndentStr(Stack.Top*2),'Indentation learned for statements: ',FABBlockTypeNames[Block^.Typ],' Indent=',Block^.InnerIdent,' at ',PosToStr(p)]);
|
||||||
@ -1049,12 +1059,12 @@ end;
|
|||||||
|
|
||||||
procedure TFullyAutomaticBeautifier.ParseSource(const Src: string; StartPos,
|
procedure TFullyAutomaticBeautifier.ParseSource(const Src: string; StartPos,
|
||||||
EndPos: integer; NestedComments: boolean; Stack: TFABBlockStack;
|
EndPos: integer; NestedComments: boolean; Stack: TFABBlockStack;
|
||||||
Policies: TFABPolicies);
|
Policies: TFABPolicies; LearnFromFirstLine: boolean);
|
||||||
var
|
var
|
||||||
LastAtomStart, LastAtomEnd: integer;
|
LastAtomStart, LastAtomEnd: integer;
|
||||||
begin
|
begin
|
||||||
ParseSource(Src,StartPos,EndPos,NestedComments,Stack,Policies,
|
ParseSource(Src,StartPos,EndPos,NestedComments,Stack,Policies,
|
||||||
LastAtomStart,LastAtomEnd);
|
LastAtomStart,LastAtomEnd,LearnFromFirstLine);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFullyAutomaticBeautifier.FindPolicyInExamples(StartCode: TCodeBuffer;
|
function TFullyAutomaticBeautifier.FindPolicyInExamples(StartCode: TCodeBuffer;
|
||||||
@ -1406,7 +1416,7 @@ end;
|
|||||||
function TFullyAutomaticBeautifier.GetIndent(const Source: string;
|
function TFullyAutomaticBeautifier.GetIndent(const Source: string;
|
||||||
CleanPos: integer; NewNestedComments: boolean;
|
CleanPos: integer; NewNestedComments: boolean;
|
||||||
UseLineStart: boolean; out Indent: TFABIndentationPolicy;
|
UseLineStart: boolean; out Indent: TFABIndentationPolicy;
|
||||||
ContextLearn: boolean): boolean;
|
ContextLearn: boolean; const InsertText: string): boolean;
|
||||||
var
|
var
|
||||||
Block: TBlock;
|
Block: TBlock;
|
||||||
|
|
||||||
@ -1444,7 +1454,7 @@ begin
|
|||||||
CleanPos:=FindStartOfAtom(Source,CleanPos);
|
CleanPos:=FindStartOfAtom(Source,CleanPos);
|
||||||
if CleanPos<1 then exit;
|
if CleanPos<1 then exit;
|
||||||
|
|
||||||
if UseLineStart then begin
|
if UseLineStart and (InsertText='') then begin
|
||||||
while (CleanPos<=length(Source)) and (Source[CleanPos] in [' ',#9]) do
|
while (CleanPos<=length(Source)) and (Source[CleanPos] in [' ',#9]) do
|
||||||
inc(CleanPos);
|
inc(CleanPos);
|
||||||
end;
|
end;
|
||||||
@ -1480,10 +1490,15 @@ begin
|
|||||||
if LastAtomStart>0 then CleanPos:=LastAtomStart;
|
if LastAtomStart>0 then CleanPos:=LastAtomStart;
|
||||||
|
|
||||||
StackIndex:=Stack.Top;
|
StackIndex:=Stack.Top;
|
||||||
if UseLineStart then
|
if UseLineStart then begin
|
||||||
|
if InsertText='' then begin
|
||||||
StackIndex:=FindStackPosForBlockCloseAtPos(Source,CleanPos,
|
StackIndex:=FindStackPosForBlockCloseAtPos(Source,CleanPos,
|
||||||
NewNestedComments,Stack);
|
NewNestedComments,Stack);
|
||||||
|
end else begin
|
||||||
|
StackIndex:=FindStackPosForBlockCloseAtPos(InsertText,1,
|
||||||
|
NewNestedComments,Stack);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
if (StackIndex<0) then begin
|
if (StackIndex<0) then begin
|
||||||
// no context
|
// no context
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
@ -1504,7 +1519,8 @@ begin
|
|||||||
|
|
||||||
if ContextLearn then begin
|
if ContextLearn then begin
|
||||||
// parse source behind
|
// parse source behind
|
||||||
ParseSource(Source,CleanPos,length(Source)+1,NewNestedComments,Stack,Policies);
|
ParseSource(Source,CleanPos,length(Source)+1,NewNestedComments,Stack,
|
||||||
|
Policies,false);
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed source behind']);
|
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed source behind']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -1660,7 +1676,8 @@ begin
|
|||||||
|
|
||||||
if Policies<>nil then begin
|
if Policies<>nil then begin
|
||||||
// parse source behind
|
// parse source behind
|
||||||
ParseSource(Source,Item^.CleanPos,length(Source)+1,NewNestedComments,Stack,Policies);
|
ParseSource(Source,Item^.CleanPos,length(Source)+1,NewNestedComments,
|
||||||
|
Stack,Policies,false);
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed source behind']);
|
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed source behind']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
@ -166,6 +166,9 @@ type
|
|||||||
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
||||||
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
|
procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
|
||||||
|
procedure EditorPaste(Sender: TObject; var AText: String;
|
||||||
|
var AMode: TSynSelectionMode; ALogStartPos: TPoint;
|
||||||
|
var AnAction: TSynCopyPasteAction);
|
||||||
procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer);
|
procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer);
|
||||||
function GetSource: TStrings;
|
function GetSource: TStrings;
|
||||||
procedure SetPageName(const AValue: string);
|
procedure SetPageName(const AValue: string);
|
||||||
@ -2565,6 +2568,7 @@ Begin
|
|||||||
OnClickLink := @EditorClickLink;
|
OnClickLink := @EditorClickLink;
|
||||||
OnMouseLink := @EditorMouseLink;
|
OnMouseLink := @EditorMouseLink;
|
||||||
OnKeyDown := @EditorKeyDown;
|
OnKeyDown := @EditorKeyDown;
|
||||||
|
OnPaste:=@EditorPaste;
|
||||||
// IMPORTANT: when you change above, don't forget updating UnbindEditor
|
// IMPORTANT: when you change above, don't forget updating UnbindEditor
|
||||||
end;
|
end;
|
||||||
if FCodeTemplates<>nil then
|
if FCodeTemplates<>nil then
|
||||||
@ -2956,6 +2960,52 @@ begin
|
|||||||
Result:=CodeBuffer;
|
Result:=CodeBuffer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSourceEditor.EditorPaste(Sender: TObject; var AText: String;
|
||||||
|
var AMode: TSynSelectionMode; ALogStartPos: TPoint;
|
||||||
|
var AnAction: TSynCopyPasteAction);
|
||||||
|
var
|
||||||
|
p: integer;
|
||||||
|
NestedComments: Boolean;
|
||||||
|
NewIndent: TFABIndentationPolicy;
|
||||||
|
Indent: LongInt;
|
||||||
|
NewSrc: string;
|
||||||
|
begin
|
||||||
|
if AMode<>smNormal then exit;
|
||||||
|
if SyncroEdit.Active then exit;
|
||||||
|
if TemplateEdit.Active then exit;
|
||||||
|
if not CodeToolsOpts.IndentOnPaste then exit;
|
||||||
|
{$IFDEF VerboseIndenter}
|
||||||
|
debugln(['TSourceEditor.EditorPaste LogCaret=',dbgs(ALogStartPos)]);
|
||||||
|
{$ENDIF}
|
||||||
|
if ALogStartPos.X>1 then exit;
|
||||||
|
UpdateCodeBuffer;
|
||||||
|
CodeBuffer.LineColToPosition(ALogStartPos.Y,ALogStartPos.X,p);
|
||||||
|
if p<1 then exit;
|
||||||
|
{$IFDEF VerboseIndenter}
|
||||||
|
if ALogStartPos.Y>0 then
|
||||||
|
DebugLn(['TSourceEditor.EditorPaste Y-1=',Lines[ALogStartPos.Y-2]]);
|
||||||
|
DebugLn(['TSourceEditor.EditorPaste Y+0=',Lines[ALogStartPos.Y-1]]);
|
||||||
|
if ALogStartPos.Y<LineCount then
|
||||||
|
DebugLn(['TSourceEditor.EditorPaste Y+1=',Lines[ALogStartPos.Y+0]]);
|
||||||
|
{$ENDIF}
|
||||||
|
NestedComments:=CodeToolBoss.GetNestedCommentsFlagForFile(CodeBuffer.Filename);
|
||||||
|
if not CodeToolBoss.Indenter.GetIndent(CodeBuffer.Source,p,NestedComments,
|
||||||
|
true,NewIndent,CodeToolsOpts.IndentContextSensitive,AText)
|
||||||
|
then exit;
|
||||||
|
if not NewIndent.IndentValid then exit;
|
||||||
|
Indent:=NewIndent.Indent-GetLineIndentWithTabs(AText,1,EditorComponent.TabWidth);
|
||||||
|
{$IFDEF VerboseIndenter}
|
||||||
|
debugln(AText);
|
||||||
|
DebugLn(['TSourceEditor.EditorPaste Indent=',Indent]);
|
||||||
|
{$ENDIF}
|
||||||
|
IndentText(AText,Indent,EditorComponent.TabWidth,NewSrc);
|
||||||
|
AText:=NewSrc;
|
||||||
|
{$IFDEF VerboseIndenter}
|
||||||
|
debugln(AText);
|
||||||
|
DebugLn(['TSourceEditor.EditorPaste END']);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
Procedure TSourceEditor.EditorMouseMoved(Sender: TObject;
|
Procedure TSourceEditor.EditorMouseMoved(Sender: TObject;
|
||||||
Shift: TShiftState; X,Y: Integer);
|
Shift: TShiftState; X,Y: Integer);
|
||||||
begin
|
begin
|
||||||
@ -6830,10 +6880,6 @@ var
|
|||||||
NewIndent: TFABIndentationPolicy;
|
NewIndent: TFABIndentationPolicy;
|
||||||
Indent: LongInt;
|
Indent: LongInt;
|
||||||
CodeBuf: TCodeBuffer;
|
CodeBuf: TCodeBuffer;
|
||||||
Line: string;
|
|
||||||
OldIndent: LongInt;
|
|
||||||
CurIndent: LongInt;
|
|
||||||
i: LongInt;
|
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
SrcEdit:=GetActiveSE;
|
SrcEdit:=GetActiveSE;
|
||||||
@ -6846,34 +6892,15 @@ begin
|
|||||||
if (SrcEdit.TemplateEdit<>nil) and SrcEdit.TemplateEdit.Active then exit;
|
if (SrcEdit.TemplateEdit<>nil) and SrcEdit.TemplateEdit.Active then exit;
|
||||||
if not (SrcEdit.SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then
|
if not (SrcEdit.SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then
|
||||||
exit;
|
exit;
|
||||||
case Reason of
|
if Reason<>ecLineBreak then exit;
|
||||||
ecLineBreak:
|
|
||||||
if not CodeToolsOpts.IndentOnLineBreak then exit;
|
if not CodeToolsOpts.IndentOnLineBreak then exit;
|
||||||
ecPaste:
|
|
||||||
begin
|
|
||||||
if not CodeToolsOpts.IndentOnPaste then exit;
|
|
||||||
if SrcEdit.EditorComponent.SelectionMode<>smNormal then exit;
|
|
||||||
if LogCaret.X>1 then
|
|
||||||
inc(FirstLinePos);
|
|
||||||
if LogCaret.Y=LastLinePos then
|
|
||||||
dec(LastLinePos);
|
|
||||||
if LastLinePos<FirstLinePos then exit; // not a whole line
|
|
||||||
end
|
|
||||||
else
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
debugln(['TSourceNotebook.EditorGetIndent LogCaret=',dbgs(LogCaret),' FirstLinePos=',FirstLinePos,' LastLinePos=',LastLinePos]);
|
debugln(['TSourceNotebook.EditorGetIndent LogCaret=',dbgs(LogCaret),' FirstLinePos=',FirstLinePos,' LastLinePos=',LastLinePos]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Result := True;
|
Result := True;
|
||||||
SrcEdit.UpdateCodeBuffer;
|
SrcEdit.UpdateCodeBuffer;
|
||||||
CodeBuf:=SrcEdit.CodeBuffer;
|
CodeBuf:=SrcEdit.CodeBuffer;
|
||||||
case Reason of
|
|
||||||
ecLineBreak,ecInsertLine:
|
|
||||||
CodeBuf.LineColToPosition(LogCaret.Y,LogCaret.X,p);
|
CodeBuf.LineColToPosition(LogCaret.Y,LogCaret.X,p);
|
||||||
ecPaste:
|
|
||||||
CodeBuf.LineColToPosition(FirstLinePos,1,p);
|
|
||||||
end;
|
|
||||||
if p<1 then exit;
|
if p<1 then exit;
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
if FirstLinePos>0 then
|
if FirstLinePos>0 then
|
||||||
@ -6884,52 +6911,19 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
NestedComments:=CodeToolBoss.GetNestedCommentsFlagForFile(CodeBuf.Filename);
|
NestedComments:=CodeToolBoss.GetNestedCommentsFlagForFile(CodeBuf.Filename);
|
||||||
if not CodeToolBoss.Indenter.GetIndent(CodeBuf.Source,p,NestedComments,
|
if not CodeToolBoss.Indenter.GetIndent(CodeBuf.Source,p,NestedComments,
|
||||||
true,NewIndent,CodeToolsOpts.IndentContextSensitive)
|
True,NewIndent,CodeToolsOpts.IndentContextSensitive)
|
||||||
then exit;
|
then exit;
|
||||||
if not NewIndent.IndentValid then exit;
|
if not NewIndent.IndentValid then exit;
|
||||||
Indent:=NewIndent.Indent;
|
Indent:=NewIndent.Indent;
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TSourceNotebook.EditorGetIndent Indent=',Indent]);
|
DebugLn(['TSourceNotebook.EditorGetIndent Indent=',Indent]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
case Reason of
|
|
||||||
ecLineBreak,ecInsertLine:
|
|
||||||
begin
|
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
DebugLn(['TSourceNotebook.EditorGetIndent Apply to FirstLinePos+1']);
|
DebugLn(['TSourceNotebook.EditorGetIndent Apply to FirstLinePos+1']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
SetIndentProc(LogCaret.Y, Indent, 0,' ');
|
SetIndentProc(LogCaret.Y, Indent, 0,' ');
|
||||||
SrcEdit.CursorScreenXY:=Point(Indent+1,SrcEdit.CursorScreenXY.Y);
|
SrcEdit.CursorScreenXY:=Point(Indent+1,SrcEdit.CursorScreenXY.Y);
|
||||||
end;
|
end;
|
||||||
ecPaste:
|
|
||||||
begin
|
|
||||||
{$IFDEF VerboseIndenter}
|
|
||||||
DebugLn(['TSourceNotebook.EditorGetIndent Apply to lines ',FirstLinePos,' .. ',LastLinePos]);
|
|
||||||
{$ENDIF}
|
|
||||||
Line:=SrcEdit.EditorComponent.Lines[FirstLinePos-1];
|
|
||||||
OldIndent:=GetLineIndentWithTabs(Line,1,SrcEdit.EditorComponent.TabWidth);
|
|
||||||
{$IFDEF VerboseIndenter}
|
|
||||||
DebugLn(['TSourceNotebook.EditorGetIndent OldIndent=',OldIndent,' Line=',dbgstr(Line)]);
|
|
||||||
{$ENDIF}
|
|
||||||
for i:=FirstLinePos to LastLinePos do begin
|
|
||||||
if i>=SrcEdit.EditorComponent.Lines.Count then break;
|
|
||||||
Line:=SrcEdit.EditorComponent.Lines[i-1];
|
|
||||||
CurIndent:=GetLineIndentWithTabs(Line,1,SrcEdit.EditorComponent.TabWidth);
|
|
||||||
{$IFDEF VerboseIndenter}
|
|
||||||
DebugLn(['TSourceNotebook.EditorGetIndent CurIndent=',CurIndent,' OldIndent=',OldIndent,' Indent=',Indent,' Line="',Line,'"']);
|
|
||||||
{$ENDIF}
|
|
||||||
CurIndent:=CurIndent-OldIndent+Indent;
|
|
||||||
if CurIndent<0 then begin
|
|
||||||
dec(Indent,CurIndent);
|
|
||||||
CurIndent:=0;
|
|
||||||
end;
|
|
||||||
{$IFDEF VerboseIndenter}
|
|
||||||
DebugLn(['TSourceNotebook.EditorGetIndent ']);
|
|
||||||
{$ENDIF}
|
|
||||||
SetIndentProc(i, CurIndent, 0,' ');
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Procedure TSourceNotebook.HintTimer(sender: TObject);
|
Procedure TSourceNotebook.HintTimer(sender: TObject);
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user