SynEdit: improved handling of Lines.Add while updating(locked) // fixed some Indent issues

git-svn-id: trunk@25714 -
This commit is contained in:
martin 2010-05-27 21:27:53 +00:00
parent c350840ac0
commit e4f319754a
3 changed files with 17 additions and 2 deletions

View File

@ -165,6 +165,7 @@ type
constructor Create; constructor Create;
procedure BeginUpdate(Sender: TObject); overload; procedure BeginUpdate(Sender: TObject); overload;
procedure EndUpdate(Sender: TObject); overload; procedure EndUpdate(Sender: TObject); overload;
function IsUpdating: Boolean;
procedure DeleteLines(Index, NumLines: integer); virtual; abstract; procedure DeleteLines(Index, NumLines: integer); virtual; abstract;
procedure InsertLines(Index, NumLines: integer); virtual; abstract; procedure InsertLines(Index, NumLines: integer); virtual; abstract;
procedure InsertStrings(Index: integer; NewStrings: TStrings); virtual; abstract; procedure InsertStrings(Index: integer; NewStrings: TStrings); virtual; abstract;
@ -450,6 +451,11 @@ begin
SetUpdateState(False, Sender); SetUpdateState(False, Sender);
end; end;
function TSynEditStrings.IsUpdating: Boolean;
begin
Result := (FSenderUpdateCount > 0) or (UpdateCount > 0);
end;
procedure TSynEditStrings.AddChangeHandler(AReason: TSynEditNotifyReason; procedure TSynEditStrings.AddChangeHandler(AReason: TSynEditNotifyReason;
AHandler: TStringListLineCountEvent); AHandler: TStringListLineCountEvent);
begin begin

View File

@ -966,7 +966,7 @@ end;
procedure TSynEditStringList.SendCachedNotify; procedure TSynEditStringList.SendCachedNotify;
begin begin
//debugln(['--- send canched notify ', FCachedNotifyStart,' / ',FCachedNotifyCount]); //debugln(['--- send cached notify ', FCachedNotifyStart,' / ',FCachedNotifyCount]);
if FCachedNotifyCount <> 0 then; if FCachedNotifyCount <> 0 then;
TLineRangeNotificationList(FNotifyLists[senrLineCount]) TLineRangeNotificationList(FNotifyLists[senrLineCount])
.CallRangeNotifyEvents(FCachedNotifySender, FCachedNotifyStart, FCachedNotifyCount); .CallRangeNotifyEvents(FCachedNotifySender, FCachedNotifyStart, FCachedNotifyCount);
@ -1156,7 +1156,7 @@ procedure TSynEditStringList.SendNotification(AReason: TSynEditNotifyReason;
begin begin
if FIgnoreSendNotification[AReason] > 0 then exit; if FIgnoreSendNotification[AReason] > 0 then exit;
if UpdateCount > 0 then begin; if IsUpdating then begin;
if AReason = senrLineCount then begin if AReason = senrLineCount then begin
// maybe cache and combine // maybe cache and combine
if not FCachedNotify then begin if not FCachedNotify then begin

View File

@ -804,6 +804,7 @@ begin
exit; exit;
end; end;
FlushNotificationCache;
IgnoreSendNotification(senrEditAction, True); IgnoreSendNotification(senrEditAction, True);
SaveText := AText; SaveText := AText;
SaveLogX := LogX; SaveLogX := LogX;
@ -865,6 +866,7 @@ begin
exit; exit;
end; end;
FlushNotificationCache;
SaveByteLen := ByteLen; SaveByteLen := ByteLen;
Result := ''; Result := '';
t := fSynStrings[LogY - 1]; t := fSynStrings[LogY - 1];
@ -904,17 +906,20 @@ begin
exit; exit;
end; end;
FlushNotificationCache;
IgnoreSendNotification(senrEditAction, True); IgnoreSendNotification(senrEditAction, True);
s := Spaces(LogY - 1); s := Spaces(LogY - 1);
t := fSynStrings[LogY - 1]; t := fSynStrings[LogY - 1];
if LogX > length(t) then begin if LogX > length(t) then begin
fSynStrings.EditLineBreak(1 + length(t), LogY); fSynStrings.EditLineBreak(1 + length(t), LogY);
FlushNotificationCache; // senrEditaction is ignored, so we need to flush by hand
if s <> '' then if s <> '' then
s := EditDeleteTrim(LogX - length(t), LogY, length(s) - (LogX - 1 - length(t))); s := EditDeleteTrim(LogX - length(t), LogY, length(s) - (LogX - 1 - length(t)));
end end
else begin else begin
s := EditDeleteTrim(1, LogY, length(s)); s := EditDeleteTrim(1, LogY, length(s));
fSynStrings.EditLineBreak(LogX, LogY); fSynStrings.EditLineBreak(LogX, LogY);
FlushNotificationCache; // senrEditaction is ignored, so we need to flush by hand
end; end;
UpdateLineText(LogY + 1); UpdateLineText(LogY + 1);
EditInsertTrim(1, LogY + 1, s); EditInsertTrim(1, LogY + 1, s);
@ -937,11 +942,13 @@ begin
exit; exit;
end; end;
FlushNotificationCache;
EditMoveFromTrim(LogY, length(Spaces(LogY - 1))); EditMoveFromTrim(LogY, length(Spaces(LogY - 1)));
s := EditDeleteTrim(1, LogY + 1, length(Spaces(LogY))); // next line s := EditDeleteTrim(1, LogY + 1, length(Spaces(LogY))); // next line
//Todo: if FillText isSpacesOnly AND NextLineIsSpacesOnly => add direct to trailing //Todo: if FillText isSpacesOnly AND NextLineIsSpacesOnly => add direct to trailing
fSynStrings.EditLineJoin(LogY, FillText); fSynStrings.EditLineJoin(LogY, FillText);
FlushNotificationCache; // senrEditaction is ignored, so we need to flush by hand
UpdateLineText(LogY); UpdateLineText(LogY);
EditInsertTrim(1, LogY, s); EditInsertTrim(1, LogY, s);
@ -955,6 +962,7 @@ procedure TSynEditStringTrimmingList.EditLinesInsert(LogY, ACount: Integer;
var var
s: string; s: string;
begin begin
FlushNotificationCache;
fSynStrings.EditLinesInsert(LogY, ACount, AText); fSynStrings.EditLinesInsert(LogY, ACount, AText);
s := fSynStrings[LogY - 1]; s := fSynStrings[LogY - 1];
EditMoveToTrim(LogY, length(s) - LastNoneSpacePos(s)); EditMoveToTrim(LogY, length(s) - LastNoneSpacePos(s));
@ -964,6 +972,7 @@ procedure TSynEditStringTrimmingList.EditLinesDelete(LogY, ACount: Integer);
var var
i: Integer; i: Integer;
begin begin
FlushNotificationCache;
for i := LogY to LogY + ACount - 1 do for i := LogY to LogY + ACount - 1 do
EditMoveFromTrim(i, length(Spaces(i - 1))); EditMoveFromTrim(i, length(Spaces(i - 1)));
fSynStrings.EditLinesDelete(LogY, ACount); fSynStrings.EditLinesDelete(LogY, ACount);