mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 17:40:17 +02:00
IDE: started block completion on char
git-svn-id: trunk@25556 -
This commit is contained in:
parent
b325a63d27
commit
331b05a147
@ -363,6 +363,7 @@ type
|
||||
function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer;
|
||||
out NewCode: TCodeBuffer;
|
||||
out NewX, NewY, NewTopLine: integer): boolean;
|
||||
function CompleteBlock(Code: TCodeBuffer; X,Y: integer): boolean;
|
||||
function CompleteBlock(Code: TCodeBuffer; X,Y: integer;
|
||||
out NewCode: TCodeBuffer;
|
||||
out NewX, NewY, NewTopLine: integer): boolean;
|
||||
@ -3111,6 +3112,16 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCodeToolManager.CompleteBlock(Code: TCodeBuffer; X, Y: integer
|
||||
): boolean;
|
||||
var
|
||||
NewCode: TCodeBuffer;
|
||||
NewX, NewY, NewTopLine: integer;
|
||||
begin
|
||||
Result:=CompleteBlock(Code,X,Y,NewCode,NewX,NewY,NewTopLine);
|
||||
if (NewCode=nil) and (NewX<0) and (NewY<0) and (NewTopLine<1) then ;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.CompleteBlock(Code: TCodeBuffer; X, Y: integer; out
|
||||
NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean;
|
||||
var
|
||||
|
@ -5598,7 +5598,7 @@ var
|
||||
Indent: Integer;
|
||||
CursorBlockInnerIndent, CursorBlockOuterIndent: LongInt;
|
||||
CursorBlock: TBlock;
|
||||
BehindCursorBlock: Boolean; // atom behind cursor block
|
||||
BehindCursorBlock: Boolean; // atom is behind cursor block
|
||||
InCursorBlock: Boolean;
|
||||
NeedCompletion: Boolean;
|
||||
InsertPos: LongInt;
|
||||
@ -5857,7 +5857,6 @@ var
|
||||
InCursorBlock:=(CursorBlockLvl>=0) and (CursorBlockLvl=Stack.Top)
|
||||
and (not BehindCursorBlock);
|
||||
if LineStart and InCursorBlock then begin
|
||||
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
||||
// atom is in same block as cursor (not sub block)
|
||||
// and first atom of a line
|
||||
// => check indent
|
||||
|
@ -40,9 +40,9 @@ uses
|
||||
{$IFDEF IDE_MEM_CHECK}
|
||||
MemCheck,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources, LCLIntf,
|
||||
FileUtil, Forms, ComCtrls, Dialogs, StdCtrls, Graphics,
|
||||
Translations, ClipBrd, types, Extctrls, Menus, HelpIntfs, LConvEncoding, LDockCtrl,
|
||||
Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources,
|
||||
LCLIntf, FileUtil, Forms, ComCtrls, Dialogs, StdCtrls, Graphics, Translations,
|
||||
ClipBrd, types, Extctrls, Menus, HelpIntfs, LConvEncoding, LDockCtrl,
|
||||
// codetools
|
||||
BasicCodeTools, CodeBeautifier, CodeToolManager, CodeCache, SourceLog,
|
||||
// synedit
|
||||
@ -284,6 +284,7 @@ type
|
||||
Category: TAutoCompleteOption): boolean;
|
||||
function AutoBlockCompleteChar(Char: TUTF8Char; var AddChar: boolean;
|
||||
Category: TAutoCompleteOption; aTextPos: TPoint; Line: string): boolean;
|
||||
function AutoBlockCompleteChar(Char: TUTF8Char): boolean;
|
||||
procedure AutoCompleteBlock;
|
||||
|
||||
procedure FocusEditor;// called by TSourceNotebook when the Notebook page
|
||||
@ -3015,6 +3016,12 @@ begin
|
||||
|
||||
ecNone: ;
|
||||
|
||||
ecChar:
|
||||
begin
|
||||
if AutoBlockCompleteChar(AChar) then
|
||||
Handled:=true;
|
||||
end;
|
||||
|
||||
else
|
||||
begin
|
||||
Handled:=false;
|
||||
@ -3778,6 +3785,36 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSourceEditor.AutoBlockCompleteChar(Char: TUTF8Char): boolean;
|
||||
var
|
||||
p: TPoint;
|
||||
x1: integer;
|
||||
x2: integer;
|
||||
Line: String;
|
||||
WordToken: String;
|
||||
begin
|
||||
Result:=false;
|
||||
if (not EditorOpts.AutoBlockCompletion)
|
||||
or (not (SyntaxHighlighterType in [lshFreePascal,lshDelphi])) then
|
||||
exit;
|
||||
if (Char='n') or (Char='N') then begin
|
||||
p:=GetCursorTextXY;
|
||||
FEditor.GetWordBoundsAtRowCol(p, x1, x2);
|
||||
Line:=GetLineText;
|
||||
WordToken := copy(Line, x1, x2-x1);
|
||||
if SysUtils.CompareText(WordToken,'begin')<>0 then exit;
|
||||
debugln(['TSourceEditor.AutoBlockCompleteChar ']);
|
||||
// user typed 'begin'
|
||||
if not LazarusIDE.SaveSourceEditorChangesToCodeCache(self) then exit;
|
||||
{FEditor.BeginUndoBlock;
|
||||
try
|
||||
if not CodeToolBoss.CompleteBlock(CodeBuffer,p.X,p.Y) then exit;
|
||||
finally
|
||||
FEditor.EndUndoBlock;
|
||||
end;}
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceEditor.AutoCompleteBlock;
|
||||
var
|
||||
XY: TPoint;
|
||||
|
Loading…
Reference in New Issue
Block a user