SynEdit: refactor, moved some undo/redo code to the lines object

git-svn-id: trunk@22672 -
This commit is contained in:
martin 2009-11-18 16:53:20 +00:00
parent dfd96cf12d
commit 7404b6ed0b
6 changed files with 122 additions and 74 deletions

View File

@ -454,7 +454,6 @@ type
function GetFoldState: String; function GetFoldState: String;
function GetPlugin(Index: Integer): TSynEditPlugin; function GetPlugin(Index: Integer): TSynEditPlugin;
function GetTextBetweenPoints(aStartPoint, aEndPoint: TPoint): String; function GetTextBetweenPoints(aStartPoint, aEndPoint: TPoint): String;
function GetUndoList: TSynEditUndoList;
function GetDividerDrawLevel: Integer; deprecated; function GetDividerDrawLevel: Integer; deprecated;
procedure SetDefSelectionMode(const AValue: TSynSelectionMode); procedure SetDefSelectionMode(const AValue: TSynSelectionMode);
procedure SetDividerDrawLevel(const AValue: Integer); deprecated; procedure SetDividerDrawLevel(const AValue: Integer); deprecated;
@ -654,7 +653,6 @@ type
AddToUndoList: Boolean = false); AddToUndoList: Boolean = false);
procedure ShowCaret; procedure ShowCaret;
procedure UndoItem(Item: TSynEditUndoItem); procedure UndoItem(Item: TSynEditUndoItem);
property UndoList: TSynEditUndoList read GetUndoList;
procedure UpdateCursor; procedure UpdateCursor;
protected protected
fGutterWidth: Integer; fGutterWidth: Integer;
@ -1178,7 +1176,7 @@ begin
if Result then if Result then
with TSynEdit(Caller) do begin with TSynEdit(Caller) do begin
FCaret.LineCharPos := FCaretPos; FCaret.LineCharPos := FCaretPos;
UndoList.AddChange(TSynEditUndoCaret.Create(FCaretPos)); FTheLinesView.CurUndoList.AddChange(TSynEditUndoCaret.Create(FCaretPos));
end; end;
end; end;
@ -1215,7 +1213,7 @@ begin
if Result then if Result then
with TSynEdit(Caller) do begin with TSynEdit(Caller) do begin
SetCaretAndSelection(FCaretPos, FBeginPos, FEndPos, FBlockMode); SetCaretAndSelection(FCaretPos, FBeginPos, FEndPos, FBlockMode);
UndoList.AddChange(TSynEditUndoSelCaret.Create(FCaretPos, FBeginPos, FTheLinesView.CurUndoList.AddChange(TSynEditUndoSelCaret.Create(FCaretPos, FBeginPos,
FEndPos, FBlockMode)); FEndPos, FBlockMode));
end; end;
end; end;
@ -1516,6 +1514,7 @@ begin
FCaret.Lines := FTheLinesView; FCaret.Lines := FTheLinesView;
FInternalCaret.Lines := FTheLinesView; FInternalCaret.Lines := FTheLinesView;
FFontDummy := TFont.Create;
with TSynEditStringList(fLines) do begin with TSynEditStringList(fLines) do begin
AddChangeHandler(senrLineCount, {$IFDEF FPC}@{$ENDIF}LineCountChanged); AddChangeHandler(senrLineCount, {$IFDEF FPC}@{$ENDIF}LineCountChanged);
@ -1523,28 +1522,19 @@ begin
AddNotifyHandler(senrBeginUpdate, {$IFDEF FPC}@{$ENDIF}LinesChanging); AddNotifyHandler(senrBeginUpdate, {$IFDEF FPC}@{$ENDIF}LinesChanging);
AddNotifyHandler(senrEndUpdate, {$IFDEF FPC}@{$ENDIF}LinesChanged); AddNotifyHandler(senrEndUpdate, {$IFDEF FPC}@{$ENDIF}LinesChanged);
AddNotifyHandler(senrCleared, {$IFDEF FPC}@{$ENDIF}ListCleared); AddNotifyHandler(senrCleared, {$IFDEF FPC}@{$ENDIF}ListCleared);
AddNotifyHandler(senrUndoRedoAdded, {$IFDEF FPC}@{$ENDIF}UndoRedoAdded);
end; end;
fFontDummy := TFont.Create; FUndoList := TSynEditStringList(fLines).UndoList;
fUndoList := TSynEditUndoList.Create; FRedoList := TSynEditStringList(fLines).RedoList;
fUndoList.OnAddedUndo := {$IFDEF FPC}@{$ENDIF}UndoRedoAdded; FUndoList.OnNeedCaretUndo := {$IFDEF FPC}@{$ENDIF}GetCaretUndo;
fUndoList.OnNeedCaretUndo := {$IFDEF FPC}@{$ENDIF}GetCaretUndo;
fRedoList := TSynEditUndoList.Create;
fRedoList.OnAddedUndo := {$IFDEF FPC}@{$ENDIF}UndoRedoAdded;
FIsUndoing := False;
FIsRedoing := False;
TSynEditStringList(FLines).UndoList := fUndoList;
TSynEditStringList(FLines).RedoList := fRedoList;
FBlockSelection := TSynEditSelection.Create(FTheLinesView, True); FBlockSelection := TSynEditSelection.Create(FTheLinesView, True);
FBlockSelection.Caret := FCaret; FBlockSelection.Caret := FCaret;
FBlockSelection.UndoList := fUndoList;
FBlockSelection.InvalidateLinesMethod := {$IFDEF FPC}@{$ENDIF}InvalidateLines; FBlockSelection.InvalidateLinesMethod := {$IFDEF FPC}@{$ENDIF}InvalidateLines;
FBlockSelection.AddChangeHandler({$IFDEF FPC}@{$ENDIF}DoBlockSelectionChanged); FBlockSelection.AddChangeHandler({$IFDEF FPC}@{$ENDIF}DoBlockSelectionChanged);
FInternalBlockSelection := TSynEditSelection.Create(FTheLinesView, False); FInternalBlockSelection := TSynEditSelection.Create(FTheLinesView, False);
FInternalBlockSelection.UndoList := fUndoList;
FInternalBlockSelection.InvalidateLinesMethod := {$IFDEF FPC}@{$ENDIF}InvalidateLines; FInternalBlockSelection.InvalidateLinesMethod := {$IFDEF FPC}@{$ENDIF}InvalidateLines;
// No need for caret, on interanl block // No need for caret, on interanl block
@ -1794,8 +1784,6 @@ begin
FreeAndNil(FMouseActionExecHandlerList); FreeAndNil(FMouseActionExecHandlerList);
FreeAndNil(FMouseActions); FreeAndNil(FMouseActions);
FreeAndNil(FMouseSelActions); FreeAndNil(FMouseSelActions);
FreeAndNil(fUndoList);
FreeAndNil(fRedoList);
FreeAndNil(fGutter); FreeAndNil(fGutter);
FreeAndNil(fTextDrawer); FreeAndNil(fTextDrawer);
FreeAndNil(fFontDummy); FreeAndNil(fFontDummy);
@ -4752,7 +4740,7 @@ begin
Group := fRedoList.PopItem; Group := fRedoList.PopItem;
if Group <> nil then begin; if Group <> nil then begin;
IncPaintLock; IncPaintLock;
FIsRedoing := True; FTheLinesView.IsRedoing := True;
Item := Group.Pop; Item := Group.Pop;
if Item <> nil then begin if Item <> nil then begin
BeginUndoBlock; BeginUndoBlock;
@ -4767,7 +4755,7 @@ begin
EndUndoBlock; EndUndoBlock;
end; end;
end; end;
FIsRedoing := False; FTheLinesView.IsRedoing := False;
Group.Free; Group.Free;
if fRedoList.IsTopMarkedAsUnmodified then if fRedoList.IsTopMarkedAsUnmodified then
fUndoList.MarkTopAsUnmodified; fUndoList.MarkTopAsUnmodified;
@ -4860,7 +4848,7 @@ begin
Group := fUndoList.PopItem; Group := fUndoList.PopItem;
if Group <> nil then begin; if Group <> nil then begin;
IncPaintLock; IncPaintLock;
FIsUndoing := True; FTheLinesView.IsUndoing := True;
Item := Group.Pop; Item := Group.Pop;
if Item <> nil then begin if Item <> nil then begin
BeginUndoBlock(fRedoList); BeginUndoBlock(fRedoList);
@ -4878,7 +4866,7 @@ begin
EndUndoBlock(fRedoList); EndUndoBlock(fRedoList);
end; end;
end; end;
FIsUndoing := False; FTheLinesView.IsUndoing := False;
Group.Free; Group.Free;
if fUndoList.IsTopMarkedAsUnmodified then if fUndoList.IsTopMarkedAsUnmodified then
fRedoList.MarkTopAsUnmodified; fRedoList.MarkTopAsUnmodified;
@ -4921,14 +4909,6 @@ begin
end; end;
end; end;
function TCustomSynEdit.GetUndoList: TSynEditUndoList;
begin
if FIsUndoing then
Result := fRedoList
else
Result := fUndoList;
end;
procedure TCustomSynEdit.SetDividerDrawLevel(const AValue: Integer); procedure TCustomSynEdit.SetDividerDrawLevel(const AValue: Integer);
begin begin
if assigned(fHighlighter) then if assigned(fHighlighter) then
@ -6208,6 +6188,7 @@ end;
procedure TCustomSynEdit.BeginUndoBlock(aList: TSynEditUndoList = nil); procedure TCustomSynEdit.BeginUndoBlock(aList: TSynEditUndoList = nil);
begin begin
if aList = nil then aList := fUndoList; if aList = nil then aList := fUndoList;
aList.OnNeedCaretUndo := {$IFDEF FPC}@{$ENDIF}GetCaretUndo;
aList.BeginBlock; aList.BeginBlock;
IncPaintLock; IncPaintLock;
FFoldedLinesView.Lock; FFoldedLinesView.Lock;

View File

@ -95,7 +95,6 @@ type
protected protected
FWordBreaker: TSynWordBreaker; FWordBreaker: TSynWordBreaker;
FBlockSelection: TSynEditSelection; FBlockSelection: TSynEditSelection;
FIsUndoing, FIsRedoing: Boolean;
function GetMarkupMgr: TObject; virtual; abstract; function GetMarkupMgr: TObject; virtual; abstract;
function GetLines: TStrings; virtual; abstract; function GetLines: TStrings; virtual; abstract;
function GetCaretObj: TSynEditCaret; virtual; abstract; function GetCaretObj: TSynEditCaret; virtual; abstract;
@ -387,7 +386,7 @@ end;
function TSynEditFriend.GetIsRedoing: Boolean; function TSynEditFriend.GetIsRedoing: Boolean;
begin begin
Result := FFriendEdit.FIsRedoing; Result := FFriendEdit.ViewedTextBuffer.IsRedoing;
end; end;
function TSynEditFriend.GetCaretObj: TSynEditCaret; function TSynEditFriend.GetCaretObj: TSynEditCaret;
@ -397,7 +396,7 @@ end;
function TSynEditFriend.GetIsUndoing: Boolean; function TSynEditFriend.GetIsUndoing: Boolean;
begin begin
Result := FFriendEdit.FIsUndoing; Result := FFriendEdit.ViewedTextBuffer.IsUndoing;
end; end;
{ TSynSelectedColor } { TSynSelectedColor }

View File

@ -79,7 +79,6 @@ type
FCaret: TSynEditCaret; FCaret: TSynEditCaret;
FHide: Boolean; FHide: Boolean;
FInternalCaret: TSynEditCaret; FInternalCaret: TSynEditCaret;
fUndoList: TSynEditUndoList;
FInvalidateLinesMethod: TInvalidateLines; FInvalidateLinesMethod: TInvalidateLines;
FEnabled: Boolean; FEnabled: Boolean;
FHookedLines: Boolean; FHookedLines: Boolean;
@ -156,7 +155,6 @@ type
property LastLineBytePos: TPoint read GetLastLineBytePos; property LastLineBytePos: TPoint read GetLastLineBytePos;
property InvalidateLinesMethod : TInvalidateLines write FInvalidateLinesMethod; property InvalidateLinesMethod : TInvalidateLines write FInvalidateLinesMethod;
property Caret: TSynEditCaret read FCaret write SetCaret; property Caret: TSynEditCaret read FCaret write SetCaret;
property UndoList: TSynEditUndoList read fUndoList write fUndoList;
property Persistent: Boolean read FPersistent write SetPersistent; property Persistent: Boolean read FPersistent write SetPersistent;
// automatically Start/Exctend selection if caret moves // automatically Start/Exctend selection if caret moves
// (depends if caret was at block border or not) // (depends if caret was at block border or not)

View File

@ -33,14 +33,19 @@ type
TStringListLineCountEvent = procedure(Sender: TSynEditStrings; TStringListLineCountEvent = procedure(Sender: TSynEditStrings;
Index, Count: Integer) of object; Index, Count: Integer) of object;
TSynEditNotifyReason = (senrLineCount, senrLineChange, senrEditAction,
senrTextEdit, senrBeginUpdate, senrEndUpdate,
senrCleared);
TStringListLineEditEvent = procedure(Sender: TSynEditStrings; TStringListLineEditEvent = procedure(Sender: TSynEditStrings;
LinePos, BytePos, Count, LineBrkCnt: Integer; LinePos, BytePos, Count, LineBrkCnt: Integer;
Text: String) of object; Text: String) of object;
TSynEditNotifyReason = ( // TStringListLineCountEvent
senrLineCount, senrLineChange, senrEditAction,
// TStringListLineEditEvent
senrTextEdit,
// TNotifyEvent
senrBeginUpdate, senrEndUpdate, senrCleared,
senrUndoRedoAdded
);
TPhysicalCharWidths = Array of Shortint; TPhysicalCharWidths = Array of Shortint;
TSynEditUndoList = class; TSynEditUndoList = class;
@ -89,9 +94,13 @@ type
function GetLengthOfLongestLine: integer; virtual; abstract; function GetLengthOfLongestLine: integer; virtual; abstract;
procedure SetTextStr(const Value: string); override; procedure SetTextStr(const Value: string); override;
function GetRedoList: TSynEditUndoList; virtual; abstract;
function GetUndoList: TSynEditUndoList; virtual; abstract; function GetUndoList: TSynEditUndoList; virtual; abstract;
function GetRedoList: TSynEditUndoList; virtual; abstract;
function GetCurUndoList: TSynEditUndoList; virtual; abstract;
procedure SetIsUndoing(const AValue: Boolean); virtual; abstract; procedure SetIsUndoing(const AValue: Boolean); virtual; abstract;
function GetIsUndoing: Boolean; virtual; abstract;
procedure SetIsRedoing(const AValue: Boolean); virtual; abstract;
function GetIsRedoing: Boolean; virtual; abstract;
procedure SendNotification(AReason: TSynEditNotifyReason; procedure SendNotification(AReason: TSynEditNotifyReason;
ASender: TSynEditStrings; aIndex, aCount: Integer; ASender: TSynEditStrings; aIndex, aCount: Integer;
aBytePos: Integer = -1; aLen: Integer = 0; aBytePos: Integer = -1; aLen: Integer = 0;
@ -146,7 +155,9 @@ type
procedure EditRedo(Item: TSynEditUndoItem); virtual; abstract; procedure EditRedo(Item: TSynEditUndoItem); virtual; abstract;
property UndoList: TSynEditUndoList read GetUndoList; property UndoList: TSynEditUndoList read GetUndoList;
property RedoList: TSynEditUndoList read GetRedoList; property RedoList: TSynEditUndoList read GetRedoList;
property IsUndoing: Boolean write SetIsUndoing; property CurUndoList: TSynEditUndoList read GetCurUndoList; // Re or Undo (Redo while undoing)
property IsUndoing: Boolean read GetIsUndoing write SetIsUndoing;
property IsRedoing: Boolean read GetIsRedoing write SetIsRedoing;
procedure IncreaseTextChangeStamp; procedure IncreaseTextChangeStamp;
public public
property ExpandedStrings[Index: integer]: string read GetExpandedString; property ExpandedStrings[Index: integer]: string read GetExpandedString;
@ -180,9 +191,13 @@ type
aTxt: String = ''); override; aTxt: String = ''); override;
procedure IgnoreSendNotification(AReason: TSynEditNotifyReason; procedure IgnoreSendNotification(AReason: TSynEditNotifyReason;
IncIgnore: Boolean); override; IncIgnore: Boolean); override;
function GetRedoList: TSynEditUndoList; override;
function GetUndoList: TSynEditUndoList; override; function GetUndoList: TSynEditUndoList; override;
function GetRedoList: TSynEditUndoList; override;
function GetCurUndoList: TSynEditUndoList; override;
procedure SetIsUndoing(const AValue: Boolean); override; procedure SetIsUndoing(const AValue: Boolean); override;
function GetIsUndoing: Boolean; override;
procedure SetIsRedoing(const AValue: Boolean); override;
function GetIsRedoing: Boolean; override;
protected protected
function GetCount: integer; override; function GetCount: integer; override;
function GetCapacity: integer; function GetCapacity: integer;
@ -552,6 +567,21 @@ begin
fSynStrings.IsUndoing := AValue; fSynStrings.IsUndoing := AValue;
end; end;
function TSynEditStringsLinked.GetIsUndoing: Boolean;
begin
Result := fSynStrings.IsUndoing;
end;
procedure TSynEditStringsLinked.SetIsRedoing(const AValue: Boolean);
begin
fSynStrings.IsRedoing := AValue;
end;
function TSynEditStringsLinked.GetIsRedoing: Boolean;
begin
Result := fSynStrings.IsRedoing;
end;
function TSynEditStringsLinked.GetIsUtf8: Boolean; function TSynEditStringsLinked.GetIsUtf8: Boolean;
begin begin
Result := FSynStrings.IsUtf8; Result := FSynStrings.IsUtf8;
@ -604,6 +634,11 @@ begin
Result := fSynStrings.GetUndoList; Result := fSynStrings.GetUndoList;
end; end;
function TSynEditStringsLinked.GetCurUndoList: TSynEditUndoList;
begin
Result := fSynStrings.GetCurUndoList;
end;
procedure TSynEditStringsLinked.RegisterAttribute(const Index: TClass; const Size: Word); procedure TSynEditStringsLinked.RegisterAttribute(const Index: TClass; const Size: Word);
begin begin
fSynStrings.RegisterAttribute(Index, Size); fSynStrings.RegisterAttribute(Index, Size);

View File

@ -124,6 +124,7 @@ type
FLineRangeNotificationList: TLineRangeNotificationList; // LineCount FLineRangeNotificationList: TLineRangeNotificationList; // LineCount
FLineChangeNotificationList: TLineRangeNotificationList; // ContentChange (not called on add...) FLineChangeNotificationList: TLineRangeNotificationList; // ContentChange (not called on add...)
FLineEditNotificationList: TLineEditNotificationList; FLineEditNotificationList: TLineEditNotificationList;
FUndoRedoAddedNotificationList: TSynMethodList;
FOnChangeList: TSynMethodList; FOnChangeList: TSynMethodList;
FOnChangingList: TSynMethodList; FOnChangingList: TSynMethodList;
FOnClearedList: TSynMethodList; FOnClearedList: TSynMethodList;
@ -131,9 +132,9 @@ type
FIgnoreSendNotification: array [TSynEditNotifyReason] of Integer; FIgnoreSendNotification: array [TSynEditNotifyReason] of Integer;
fDosFileFormat: boolean; fDosFileFormat: boolean;
fIndexOfLongestLine: integer; fIndexOfLongestLine: integer;
fRedoList: TSynEditUndoList; FRedoList: TSynEditUndoList;
fUndoList: TSynEditUndoList; FUndoList: TSynEditUndoList;
FIsUndoing: Boolean; FIsUndoing, FIsRedoing: Boolean;
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
function GetFlags(Index: Integer): TSynEditStringFlags; function GetFlags(Index: Integer): TSynEditStringFlags;
@ -149,7 +150,12 @@ type
function GetRedoList: TSynEditUndoList; override; function GetRedoList: TSynEditUndoList; override;
function GetUndoList: TSynEditUndoList; override; function GetUndoList: TSynEditUndoList; override;
function GetCurUndoList: TSynEditUndoList; override;
procedure SetIsUndoing(const AValue: Boolean); override; procedure SetIsUndoing(const AValue: Boolean); override;
function GetIsUndoing: Boolean; override;
procedure SetIsRedoing(const AValue: Boolean); override;
function GetIsRedoing: Boolean; override;
procedure UndoRedoAdded(Sender: TObject);
procedure SendNotification(AReason: TSynEditNotifyReason; procedure SendNotification(AReason: TSynEditNotifyReason;
ASender: TSynEditStrings; aIndex, aCount: Integer; ASender: TSynEditStrings; aIndex, aCount: Integer;
aBytePos: Integer = -1; aLen: Integer = 0; aTxt: String = ''); override; aBytePos: Integer = -1; aLen: Integer = 0; aTxt: String = ''); override;
@ -402,9 +408,18 @@ var
r: TSynEditNotifyReason; r: TSynEditNotifyReason;
begin begin
fList := TSynEditStringMemory.Create; fList := TSynEditStringMemory.Create;
FUndoList := TSynEditUndoList.Create;
fUndoList.OnAddedUndo := {$IFDEF FPC}@{$ENDIF}UndoRedoAdded;
FRedoList := TSynEditUndoList.Create;
fRedoList.OnAddedUndo := {$IFDEF FPC}@{$ENDIF}UndoRedoAdded;
FIsUndoing := False;
FIsRedoing := False;
FLineRangeNotificationList := TLineRangeNotificationList.Create; FLineRangeNotificationList := TLineRangeNotificationList.Create;
FLineChangeNotificationList := TLineRangeNotificationList.Create; FLineChangeNotificationList := TLineRangeNotificationList.Create;
FLineEditNotificationList := TLineEditNotificationList.Create; FLineEditNotificationList := TLineEditNotificationList.Create;
FUndoRedoAddedNotificationList := TLineEditNotificationList.Create;
FOnChangeList := TSynMethodList.Create; FOnChangeList := TSynMethodList.Create;
FOnChangingList := TSynMethodList.Create; FOnChangingList := TSynMethodList.Create;
FOnClearedList := TSynMethodList.Create; FOnClearedList := TSynMethodList.Create;
@ -429,9 +444,12 @@ begin
FreeAndNil(FLineRangeNotificationList); FreeAndNil(FLineRangeNotificationList);
FreeAndNil(FLineChangeNotificationList); FreeAndNil(FLineChangeNotificationList);
FreeAndNil(FLineEditNotificationList); FreeAndNil(FLineEditNotificationList);
FreeAndNil(FUndoRedoAddedNotificationList);
FreeAndNil(FOnChangeList); FreeAndNil(FOnChangeList);
FreeAndNil(FOnChangingList); FreeAndNil(FOnChangingList);
FreeAndNil(FOnClearedList); FreeAndNil(FOnClearedList);
FreeAndNil(FUndoList);
FreeAndNil(FRedoList);
FreeAndNil(fList); FreeAndNil(fList);
end; end;
@ -599,6 +617,11 @@ begin
end; end;
function TSynEditStringList.GetUndoList: TSynEditUndoList; function TSynEditStringList.GetUndoList: TSynEditUndoList;
begin
Result := fUndoList;
end;
function TSynEditStringList.GetCurUndoList: TSynEditUndoList;
begin begin
if FIsUndoing then if FIsUndoing then
Result := fRedoList Result := fRedoList
@ -611,6 +634,26 @@ begin
FIsUndoing := AValue; FIsUndoing := AValue;
end; end;
function TSynEditStringList.GetIsUndoing: Boolean;
begin
Result := FIsUndoing;
end;
procedure TSynEditStringList.SetIsRedoing(const AValue: Boolean);
begin
FIsRedoing := AValue;
end;
function TSynEditStringList.GetIsRedoing: Boolean;
begin
Result := FIsRedoing;
end;
procedure TSynEditStringList.UndoRedoAdded(Sender: TObject);
begin
FUndoRedoAddedNotificationList.CallNotifyEvents(Sender);
end;
// Maps the Physical Width (ScreenCells) to each character // Maps the Physical Width (ScreenCells) to each character
// Multibyte Chars have thw width on the first byte, and a 0 Width for all other bytes // Multibyte Chars have thw width on the first byte, and a 0 Width for all other bytes
function TSynEditStringList.GetPhysicalCharWidths(const Line: String; Index: Integer): TPhysicalCharWidths; function TSynEditStringList.GetPhysicalCharWidths(const Line: String; Index: Integer): TPhysicalCharWidths;
@ -872,6 +915,7 @@ begin
senrBeginUpdate : FOnChangingList.Add(AHandler); senrBeginUpdate : FOnChangingList.Add(AHandler);
senrEndUpdate : FOnChangeList.Add(AHandler); senrEndUpdate : FOnChangeList.Add(AHandler);
senrCleared : FOnClearedList.Add(AHandler); senrCleared : FOnClearedList.Add(AHandler);
senrUndoRedoAdded : FUndoRedoAddedNotificationList.Add(AHandler);
end; end;
end; end;
@ -884,6 +928,7 @@ begin
senrBeginUpdate : FOnChangingList.Remove(AHandler); senrBeginUpdate : FOnChangingList.Remove(AHandler);
senrEndUpdate : FOnChangeList.Remove(AHandler); senrEndUpdate : FOnChangeList.Remove(AHandler);
senrCleared : FOnClearedList.Remove(AHandler); senrCleared : FOnClearedList.Remove(AHandler);
senrUndoRedoAdded : FUndoRedoAddedNotificationList.Remove(AHandler);
end; end;
end; end;
@ -913,7 +958,7 @@ begin
LogX := Length(s) + 1; LogX := Length(s) + 1;
end; end;
Strings[LogY - 1] := copy(s,1, LogX - 1) + AText + copy(s, LogX, length(s)); Strings[LogY - 1] := copy(s,1, LogX - 1) + AText + copy(s, LogX, length(s));
UndoList.AddChange(TSynEditUndoTxtInsert.Create(LogX, LogY, Length(AText))); CurUndoList.AddChange(TSynEditUndoTxtInsert.Create(LogX, LogY, Length(AText)));
MarkModified(LogY, LogY); MarkModified(LogY, LogY);
SendNotification(senrEditAction, self, LogY, 0, LogX, length(AText), AText); SendNotification(senrEditAction, self, LogY, 0, LogX, length(AText), AText);
end; end;
@ -927,7 +972,7 @@ begin
exit; exit;
Result := copy(s, LogX, ByteLen); Result := copy(s, LogX, ByteLen);
Strings[LogY - 1] := copy(s,1, LogX - 1) + copy(s, LogX + ByteLen, length(s)); Strings[LogY - 1] := copy(s,1, LogX - 1) + copy(s, LogX + ByteLen, length(s));
UndoList.AddChange(TSynEditUndoTxtDelete.Create(LogX, LogY, Result)); CurUndoList.AddChange(TSynEditUndoTxtDelete.Create(LogX, LogY, Result));
MarkModified(LogY, LogY); MarkModified(LogY, LogY);
SendNotification(senrEditAction, self, LogY, 0, LogX, -ByteLen, ''); SendNotification(senrEditAction, self, LogY, 0, LogX, -ByteLen, '');
end; end;
@ -940,7 +985,7 @@ begin
if LogX - 1 < length(s) then if LogX - 1 < length(s) then
Strings[LogY - 1] := copy(s, 1, LogX - 1); Strings[LogY - 1] := copy(s, 1, LogX - 1);
Insert(LogY, copy(s, LogX, length(s))); Insert(LogY, copy(s, LogX, length(s)));
UndoList.AddChange(TSynEditUndoTxtLineBreak.Create(LogY)); CurUndoList.AddChange(TSynEditUndoTxtLineBreak.Create(LogY));
MarkModified(LogY, LogY + 1); MarkModified(LogY, LogY + 1);
SendNotification(senrEditAction, self, LogY, 1, LogX, 0, ''); SendNotification(senrEditAction, self, LogY, 1, LogX, 0, '');
end; end;
@ -952,7 +997,7 @@ begin
t := Strings[LogY - 1]; t := Strings[LogY - 1];
if FillText <> '' then if FillText <> '' then
EditInsert(1 + Length(t), LogY, FillText); EditInsert(1 + Length(t), LogY, FillText);
UndoList.AddChange(TSynEditUndoTxtLineJoin.Create(1 + Length(Strings[LogY-1]), CurUndoList.AddChange(TSynEditUndoTxtLineJoin.Create(1 + Length(Strings[LogY-1]),
LogY)); LogY));
t := t + FillText; t := t + FillText;
Strings[LogY - 1] := t + Strings[LogY] ; Strings[LogY - 1] := t + Strings[LogY] ;
@ -965,7 +1010,7 @@ procedure TSynEditStringList.EditLinesInsert(LogY, ACount: Integer;
AText: String = ''); AText: String = '');
begin begin
InsertLines(LogY - 1, ACount); InsertLines(LogY - 1, ACount);
UndoList.AddChange(TSynEditUndoTxtLinesIns.Create(LogY, ACount)); CurUndoList.AddChange(TSynEditUndoTxtLinesIns.Create(LogY, ACount));
SendNotification(senrEditAction, self, LogY, ACount, 1, 0, ''); SendNotification(senrEditAction, self, LogY, ACount, 1, 0, '');
if AText <> '' then if AText <> '' then
EditInsert(1, LogY, AText); EditInsert(1, LogY, AText);
@ -979,23 +1024,18 @@ begin
for i := LogY to LogY + ACount - 1 do for i := LogY to LogY + ACount - 1 do
EditDelete(1, i, length(Strings[i-1])); EditDelete(1, i, length(Strings[i-1]));
DeleteLines(LogY - 1, ACount); DeleteLines(LogY - 1, ACount);
UndoList.AddChange(TSynEditUndoTxtLinesDel.Create(LogY, ACount)); CurUndoList.AddChange(TSynEditUndoTxtLinesDel.Create(LogY, ACount));
SendNotification(senrEditAction, self, LogY, -ACount, 1, 0, ''); SendNotification(senrEditAction, self, LogY, -ACount, 1, 0, '');
end; end;
procedure TSynEditStringList.EditUndo(Item: TSynEditUndoItem); procedure TSynEditStringList.EditUndo(Item: TSynEditUndoItem);
begin begin
IsUndoing := True; EditRedo(Item);
try
EditRedo(Item);
finally
IsUndoing := False;
end;
end; end;
procedure TSynEditStringList.UndoEditLinesDelete(LogY, ACount: Integer); procedure TSynEditStringList.UndoEditLinesDelete(LogY, ACount: Integer);
begin begin
UndoList.AddChange(TSynEditUndoTxtLinesDel.Create(LogY, ACount)); CurUndoList.AddChange(TSynEditUndoTxtLinesDel.Create(LogY, ACount));
DeleteLines(LogY - 1, ACount); DeleteLines(LogY - 1, ACount);
SendNotification(senrEditAction, self, LogY, -ACount, 1, 0, ''); SendNotification(senrEditAction, self, LogY, -ACount, 1, 0, '');
end; end;

View File

@ -294,9 +294,9 @@ begin
Result := Caller is TSynEditStringTrimmingList; Result := Caller is TSynEditStringTrimmingList;
if Result then if Result then
with TSynEditStringTrimmingList(Caller) do begin with TSynEditStringTrimmingList(Caller) do begin
UndoList.Lock; CurUndoList.Lock;
EditInsertTrim(1, FPosY, FText); EditInsertTrim(1, FPosY, FText);
UndoList.Unlock; CurUndoList.Unlock;
SendNotification(senrLineChange, TSynEditStringTrimmingList(Caller), SendNotification(senrLineChange, TSynEditStringTrimmingList(Caller),
FPosY - 1, 1); FPosY - 1, 1);
SendNotification(senrEditAction, TSynEditStringTrimmingList(Caller), SendNotification(senrEditAction, TSynEditStringTrimmingList(Caller),
@ -366,7 +366,7 @@ begin
if (fLineIndex <> TSynEditCaret(Sender).LinePos - 1) or if (fLineIndex <> TSynEditCaret(Sender).LinePos - 1) or
(FTrimType = settIgnoreAll) then (FTrimType = settIgnoreAll) then
begin begin
UndoList.AppendToLastChange(TSynEditUndoTrimForget.Create(FLineIndex+1, FSpaces)); CurUndoList.AppendToLastChange(TSynEditUndoTrimForget.Create(FLineIndex+1, FSpaces));
i := length(FSpaces); i := length(FSpaces);
fSpaces := ''; fSpaces := '';
SendNotification(senrEditAction, self, FLineIndex+1, 0, SendNotification(senrEditAction, self, FLineIndex+1, 0,
@ -382,7 +382,7 @@ begin
s := copy(FSpaces, j + 1, MaxInt); s := copy(FSpaces, j + 1, MaxInt);
FSpaces := copy(FSpaces, 1, j); FSpaces := copy(FSpaces, 1, j);
i := length(s); i := length(s);
UndoList.AppendToLastChange(TSynEditUndoTrimForget.Create(FLineIndex+1, s)); CurUndoList.AppendToLastChange(TSynEditUndoTrimForget.Create(FLineIndex+1, s));
SendNotification(senrEditAction, self, FLineIndex+1, 0, SendNotification(senrEditAction, self, FLineIndex+1, 0,
1+length(fSynStrings[FLineIndex]) + length(FSpaces), -i, ''); 1+length(fSynStrings[FLineIndex]) + length(FSpaces), -i, '');
end; end;
@ -561,7 +561,7 @@ begin
if (slen > 0) and (index >= 0) and (index < fSynStrings.Count) then begin if (slen > 0) and (index >= 0) and (index < fSynStrings.Count) then begin
ltext := fSynStrings[index]; ltext := fSynStrings[index];
fSynStrings[index] := ltext; // trigger OnPutted, so the line gets repainted fSynStrings[index] := ltext; // trigger OnPutted, so the line gets repainted
UndoList.AppendToLastChange(TSynEditUndoTrimForget.Create(Index+1, fLockList[i])); CurUndoList.AppendToLastChange(TSynEditUndoTrimForget.Create(Index+1, fLockList[i]));
end; end;
end; end;
FIsTrimming := False; FIsTrimming := False;
@ -699,7 +699,7 @@ begin
StoreSpacesForLine(LogY - 1, StoreSpacesForLine(LogY - 1,
copy(s,1, LogX - 1) + AText + copy(s, LogX, length(s)), copy(s,1, LogX - 1) + AText + copy(s, LogX, length(s)),
fSynStrings.Strings[LogY - 1]); fSynStrings.Strings[LogY - 1]);
UndoList.AddChange(TSynEditUndoTrimInsert.Create(LogX, LogY, Length(AText))); CurUndoList.AddChange(TSynEditUndoTrimInsert.Create(LogX, LogY, Length(AText)));
end; end;
function TSynEditStringTrimmingList.EditDeleteTrim(LogX, LogY, ByteLen: function TSynEditStringTrimmingList.EditDeleteTrim(LogX, LogY, ByteLen:
@ -715,7 +715,7 @@ begin
copy(s,1, LogX - 1) + copy(s, LogX + ByteLen, length(s)), copy(s,1, LogX - 1) + copy(s, LogX + ByteLen, length(s)),
fSynStrings.Strings[LogY - 1]); fSynStrings.Strings[LogY - 1]);
if Result <> '' then if Result <> '' then
UndoList.AddChange(TSynEditUndoTrimDelete.Create(LogX, LogY, Result)); CurUndoList.AddChange(TSynEditUndoTrimDelete.Create(LogX, LogY, Result));
end; end;
procedure TSynEditStringTrimmingList.EditMoveToTrim(LogY, Len: Integer); procedure TSynEditStringTrimmingList.EditMoveToTrim(LogY, Len: Integer);
@ -729,7 +729,7 @@ begin
t := copy(t, 1, length(t) - Len); t := copy(t, 1, length(t) - Len);
StoreSpacesForLine(LogY - 1, s, t); StoreSpacesForLine(LogY - 1, s, t);
fSynStrings[LogY - 1] := t; fSynStrings[LogY - 1] := t;
UndoList.AddChange(TSynEditUndoTrimMoveTo.Create(LogY, Len)); CurUndoList.AddChange(TSynEditUndoTrimMoveTo.Create(LogY, Len));
end; end;
procedure TSynEditStringTrimmingList.EditMoveFromTrim(LogY, Len: Integer); procedure TSynEditStringTrimmingList.EditMoveFromTrim(LogY, Len: Integer);
@ -743,7 +743,7 @@ begin
s := copy(s, 1 + Len, Len); s := copy(s, 1 + Len, Len);
StoreSpacesForLine(LogY - 1, s, t); StoreSpacesForLine(LogY - 1, s, t);
fSynStrings[LogY - 1] := t; fSynStrings[LogY - 1] := t;
UndoList.AddChange(TSynEditUndoTrimMoveFrom.Create(LogY, Len)); CurUndoList.AddChange(TSynEditUndoTrimMoveFrom.Create(LogY, Len));
end; end;
procedure TSynEditStringTrimmingList.UpdateLineText(LogY: Integer); procedure TSynEditStringTrimmingList.UpdateLineText(LogY: Integer);
@ -931,12 +931,7 @@ end;
procedure TSynEditStringTrimmingList.EditUndo(Item: TSynEditUndoItem); procedure TSynEditStringTrimmingList.EditUndo(Item: TSynEditUndoItem);
begin begin
IsUndoing := True; EditRedo(Item);
try
EditRedo(Item);
finally
IsUndoing := False;
end;
end; end;
procedure TSynEditStringTrimmingList.EditRedo(Item: TSynEditUndoItem); procedure TSynEditStringTrimmingList.EditRedo(Item: TSynEditUndoItem);