Auto-Closing Brackets and Insert or Restore

This commit is contained in:
Margers 2024-09-01 20:10:39 +00:00 committed by Michael Van Canneyt
parent ae81a69cb1
commit 54afa37d4d
2 changed files with 30 additions and 2 deletions

View File

@ -1281,7 +1281,7 @@ var
Temp,Idx,Last,Count : Longint;
StoredFlags : longint;
UndoTime : longint;
WasInserting,IsGrouped,HadefNoIndent : boolean;
WasInserting,WasAutoBrackets,IsGrouped,HadefNoIndent : boolean;
MaxY,MinY : sw_integer;
Line : String;
@ -1341,9 +1341,12 @@ begin
SetCurPtr(EndPos.X,EndPos.Y);
WasInserting:=GetInsertMode;
SetInsertMode(true);
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
if assigned(text) then
for Temp := 1 to length(Text^) do
AddChar(Text^[Temp]);
SetAutoBrackets(WasAutoBrackets);
SetInsertMode(WasInserting);
SetMinMax(EndPos.Y);
SetCurPtr(StartPos.X,StartPos.Y);
@ -1354,6 +1357,8 @@ begin
Line:=GetDisplayText(StartPos.Y);
WasInserting:=GetInsertMode;
SetInsertMode(false);
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
if assigned(text) then
for Temp := 1 to length(Text^) do
begin
@ -1363,6 +1368,7 @@ begin
else
Text^[Temp]:=Line[StartPos.X+Temp];
end;
SetAutoBrackets(WasAutoBrackets);
SetInsertMode(WasInserting);
SetMinMax(EndPos.Y);
SetCurPtr(StartPos.X,StartPos.Y);
@ -1448,7 +1454,7 @@ procedure TCodeEditor.Redo;
var
Temp,Idx,i,Last,Count : Longint;
StoredFlags : longint;
WasInserting,IsGrouped,ShouldInsertText : boolean;
WasInserting,WasAutoBrackets,IsGrouped,ShouldInsertText : boolean;
Line : String;
MaxY,MinY : sw_integer;
procedure SetMinMax(y : sw_integer);
@ -1509,6 +1515,8 @@ begin
Line:=GetDisplayText(StartPos.Y);
WasInserting:=GetInsertMode;
SetInsertMode(false);
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
if assigned(text) then
for Temp := 1 to length(Text^) do
begin
@ -1518,6 +1526,7 @@ begin
else
Text^[Temp]:=Line[StartPos.X+Temp];
end;
SetAutoBrackets(WasAutoBrackets);
SetInsertMode(WasInserting);
SetCurPtr(EndPos.X,EndPos.Y);
SetMinMax(StartPos.Y);

View File

@ -503,6 +503,8 @@ type
{a}procedure SetIndentSize(AIndentSize: integer); virtual;
{a}function IsReadOnly: boolean; virtual;
{a}function IsClipboard: Boolean; virtual;
{a}function GetAutoBrackets: boolean; virtual;
{a}procedure SetAutoBrackets(AutoBrackets: boolean); virtual;
{a}function GetInsertMode: boolean; virtual;
{a}procedure SetInsertMode(InsertMode: boolean); virtual;
procedure SetCurPtr(X,Y: sw_integer); virtual;
@ -3087,14 +3089,18 @@ function TCustomCodeEditor.InsertText(const S: string): Boolean;
var I: sw_integer;
OldPos: TPoint;
HoldUndo : boolean;
WasAutoBrackets : boolean;
begin
Lock;
OldPos:=CurPos;
HoldUndo:=GetStoreUndo;
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
SetStoreUndo(false);
for I:=1 to length(S) do
AddChar(S[I]);
InsertText:=true;
SetAutoBrackets(WasAutoBrackets);
SetStoreUndo(HoldUndo);
AddAction(eaInsertText,OldPos,CurPos,S,GetFlags);
UnLock;
@ -6490,6 +6496,19 @@ begin
end;
end;
function TCustomCodeEditor.GetAutoBrackets: boolean;
begin
GetAutoBrackets:=(GetFlags and efAutoBrackets)<>0;
end;
procedure TCustomCodeEditor.SetAutoBrackets(AutoBrackets: boolean);
begin
if AutoBrackets then
SetFlags(GetFlags or efAutoBrackets)
else
SetFlags(GetFlags and (not efAutoBrackets));
end;
function TCustomCodeEditor.GetInsertMode: boolean;
begin
GetInsertMode:=(GetFlags and efInsertMode)<>0;