mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 01:29:19 +02:00
Auto-Closing Brackets and Insert or Restore
This commit is contained in:
parent
ae81a69cb1
commit
54afa37d4d
@ -1281,7 +1281,7 @@ var
|
|||||||
Temp,Idx,Last,Count : Longint;
|
Temp,Idx,Last,Count : Longint;
|
||||||
StoredFlags : longint;
|
StoredFlags : longint;
|
||||||
UndoTime : longint;
|
UndoTime : longint;
|
||||||
WasInserting,IsGrouped,HadefNoIndent : boolean;
|
WasInserting,WasAutoBrackets,IsGrouped,HadefNoIndent : boolean;
|
||||||
MaxY,MinY : sw_integer;
|
MaxY,MinY : sw_integer;
|
||||||
Line : String;
|
Line : String;
|
||||||
|
|
||||||
@ -1341,9 +1341,12 @@ begin
|
|||||||
SetCurPtr(EndPos.X,EndPos.Y);
|
SetCurPtr(EndPos.X,EndPos.Y);
|
||||||
WasInserting:=GetInsertMode;
|
WasInserting:=GetInsertMode;
|
||||||
SetInsertMode(true);
|
SetInsertMode(true);
|
||||||
|
WasAutoBrackets:=GetAutoBrackets;
|
||||||
|
SetAutoBrackets(false);
|
||||||
if assigned(text) then
|
if assigned(text) then
|
||||||
for Temp := 1 to length(Text^) do
|
for Temp := 1 to length(Text^) do
|
||||||
AddChar(Text^[Temp]);
|
AddChar(Text^[Temp]);
|
||||||
|
SetAutoBrackets(WasAutoBrackets);
|
||||||
SetInsertMode(WasInserting);
|
SetInsertMode(WasInserting);
|
||||||
SetMinMax(EndPos.Y);
|
SetMinMax(EndPos.Y);
|
||||||
SetCurPtr(StartPos.X,StartPos.Y);
|
SetCurPtr(StartPos.X,StartPos.Y);
|
||||||
@ -1354,6 +1357,8 @@ begin
|
|||||||
Line:=GetDisplayText(StartPos.Y);
|
Line:=GetDisplayText(StartPos.Y);
|
||||||
WasInserting:=GetInsertMode;
|
WasInserting:=GetInsertMode;
|
||||||
SetInsertMode(false);
|
SetInsertMode(false);
|
||||||
|
WasAutoBrackets:=GetAutoBrackets;
|
||||||
|
SetAutoBrackets(false);
|
||||||
if assigned(text) then
|
if assigned(text) then
|
||||||
for Temp := 1 to length(Text^) do
|
for Temp := 1 to length(Text^) do
|
||||||
begin
|
begin
|
||||||
@ -1363,6 +1368,7 @@ begin
|
|||||||
else
|
else
|
||||||
Text^[Temp]:=Line[StartPos.X+Temp];
|
Text^[Temp]:=Line[StartPos.X+Temp];
|
||||||
end;
|
end;
|
||||||
|
SetAutoBrackets(WasAutoBrackets);
|
||||||
SetInsertMode(WasInserting);
|
SetInsertMode(WasInserting);
|
||||||
SetMinMax(EndPos.Y);
|
SetMinMax(EndPos.Y);
|
||||||
SetCurPtr(StartPos.X,StartPos.Y);
|
SetCurPtr(StartPos.X,StartPos.Y);
|
||||||
@ -1448,7 +1454,7 @@ procedure TCodeEditor.Redo;
|
|||||||
var
|
var
|
||||||
Temp,Idx,i,Last,Count : Longint;
|
Temp,Idx,i,Last,Count : Longint;
|
||||||
StoredFlags : longint;
|
StoredFlags : longint;
|
||||||
WasInserting,IsGrouped,ShouldInsertText : boolean;
|
WasInserting,WasAutoBrackets,IsGrouped,ShouldInsertText : boolean;
|
||||||
Line : String;
|
Line : String;
|
||||||
MaxY,MinY : sw_integer;
|
MaxY,MinY : sw_integer;
|
||||||
procedure SetMinMax(y : sw_integer);
|
procedure SetMinMax(y : sw_integer);
|
||||||
@ -1509,6 +1515,8 @@ begin
|
|||||||
Line:=GetDisplayText(StartPos.Y);
|
Line:=GetDisplayText(StartPos.Y);
|
||||||
WasInserting:=GetInsertMode;
|
WasInserting:=GetInsertMode;
|
||||||
SetInsertMode(false);
|
SetInsertMode(false);
|
||||||
|
WasAutoBrackets:=GetAutoBrackets;
|
||||||
|
SetAutoBrackets(false);
|
||||||
if assigned(text) then
|
if assigned(text) then
|
||||||
for Temp := 1 to length(Text^) do
|
for Temp := 1 to length(Text^) do
|
||||||
begin
|
begin
|
||||||
@ -1518,6 +1526,7 @@ begin
|
|||||||
else
|
else
|
||||||
Text^[Temp]:=Line[StartPos.X+Temp];
|
Text^[Temp]:=Line[StartPos.X+Temp];
|
||||||
end;
|
end;
|
||||||
|
SetAutoBrackets(WasAutoBrackets);
|
||||||
SetInsertMode(WasInserting);
|
SetInsertMode(WasInserting);
|
||||||
SetCurPtr(EndPos.X,EndPos.Y);
|
SetCurPtr(EndPos.X,EndPos.Y);
|
||||||
SetMinMax(StartPos.Y);
|
SetMinMax(StartPos.Y);
|
||||||
|
@ -503,6 +503,8 @@ type
|
|||||||
{a}procedure SetIndentSize(AIndentSize: integer); virtual;
|
{a}procedure SetIndentSize(AIndentSize: integer); virtual;
|
||||||
{a}function IsReadOnly: boolean; virtual;
|
{a}function IsReadOnly: boolean; virtual;
|
||||||
{a}function IsClipboard: Boolean; virtual;
|
{a}function IsClipboard: Boolean; virtual;
|
||||||
|
{a}function GetAutoBrackets: boolean; virtual;
|
||||||
|
{a}procedure SetAutoBrackets(AutoBrackets: boolean); virtual;
|
||||||
{a}function GetInsertMode: boolean; virtual;
|
{a}function GetInsertMode: boolean; virtual;
|
||||||
{a}procedure SetInsertMode(InsertMode: boolean); virtual;
|
{a}procedure SetInsertMode(InsertMode: boolean); virtual;
|
||||||
procedure SetCurPtr(X,Y: sw_integer); virtual;
|
procedure SetCurPtr(X,Y: sw_integer); virtual;
|
||||||
@ -3087,14 +3089,18 @@ function TCustomCodeEditor.InsertText(const S: string): Boolean;
|
|||||||
var I: sw_integer;
|
var I: sw_integer;
|
||||||
OldPos: TPoint;
|
OldPos: TPoint;
|
||||||
HoldUndo : boolean;
|
HoldUndo : boolean;
|
||||||
|
WasAutoBrackets : boolean;
|
||||||
begin
|
begin
|
||||||
Lock;
|
Lock;
|
||||||
OldPos:=CurPos;
|
OldPos:=CurPos;
|
||||||
HoldUndo:=GetStoreUndo;
|
HoldUndo:=GetStoreUndo;
|
||||||
|
WasAutoBrackets:=GetAutoBrackets;
|
||||||
|
SetAutoBrackets(false);
|
||||||
SetStoreUndo(false);
|
SetStoreUndo(false);
|
||||||
for I:=1 to length(S) do
|
for I:=1 to length(S) do
|
||||||
AddChar(S[I]);
|
AddChar(S[I]);
|
||||||
InsertText:=true;
|
InsertText:=true;
|
||||||
|
SetAutoBrackets(WasAutoBrackets);
|
||||||
SetStoreUndo(HoldUndo);
|
SetStoreUndo(HoldUndo);
|
||||||
AddAction(eaInsertText,OldPos,CurPos,S,GetFlags);
|
AddAction(eaInsertText,OldPos,CurPos,S,GetFlags);
|
||||||
UnLock;
|
UnLock;
|
||||||
@ -6490,6 +6496,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function TCustomCodeEditor.GetInsertMode: boolean;
|
||||||
begin
|
begin
|
||||||
GetInsertMode:=(GetFlags and efInsertMode)<>0;
|
GetInsertMode:=(GetFlags and efInsertMode)<>0;
|
||||||
|
Loading…
Reference in New Issue
Block a user