Added try finally to some UndoBlock (editor)

git-svn-id: trunk@34977 -
This commit is contained in:
martin 2012-01-27 15:13:52 +00:00
parent c25543b689
commit d503d615c5
6 changed files with 107 additions and 80 deletions

View File

@ -1593,46 +1593,49 @@ begin
with TCustomSynEdit(F.CurrentEditor) do begin
BeginUndoBlock;
BeginUpdate;
LogCaret := LogicalCaretXY;
NewBlockBegin:=LogCaret;
CurLine:=Lines[NewBlockBegin.Y - 1];
while (NewBlockBegin.X>1) and (NewBlockBegin.X-1<=length(CurLine))
and (CurLine[NewBlockBegin.X-1] in ['a'..'z','A'..'Z','0'..'9','_']) do
dec(NewBlockBegin.X);
//BlockBegin:=NewBlockBegin;
if ssShift in Shift then begin
// replace only prefix
NewBlockEnd := LogCaret;
end else begin
// replace the whole word
NewBlockEnd := LogCaret;
CurLine:=Lines[NewBlockEnd.Y - 1];
while (NewBlockEnd.X<=length(CurLine))
and (CurLine[NewBlockEnd.X] in ['a'..'z','A'..'Z','0'..'9','_']) do
inc(NewBlockEnd.X);
end;
//debugln('TSynCompletion.Validate B Position=',dbgs(Position));
if Position>=0 then begin
if Assigned(FOnCodeCompletion) then
begin
Value := ItemList[Position];
FOnCodeCompletion(Value, TextBetweenPoints[NewBlockBegin, NewBlockEnd],
NewBlockBegin, NewBlockEnd, KeyChar, Shift);
if (CompareCarets(NewBlockBegin, NewBlockEnd) <> 0) or (Value <> '') then
try
LogCaret := LogicalCaretXY;
NewBlockBegin:=LogCaret;
CurLine:=Lines[NewBlockBegin.Y - 1];
while (NewBlockBegin.X>1) and (NewBlockBegin.X-1<=length(CurLine))
and (CurLine[NewBlockBegin.X-1] in ['a'..'z','A'..'Z','0'..'9','_']) do
dec(NewBlockBegin.X);
//BlockBegin:=NewBlockBegin;
if ssShift in Shift then begin
// replace only prefix
NewBlockEnd := LogCaret;
end else begin
// replace the whole word
NewBlockEnd := LogCaret;
CurLine:=Lines[NewBlockEnd.Y - 1];
while (NewBlockEnd.X<=length(CurLine))
and (CurLine[NewBlockEnd.X] in ['a'..'z','A'..'Z','0'..'9','_']) do
inc(NewBlockEnd.X);
end;
//debugln('TSynCompletion.Validate B Position=',dbgs(Position));
if Position>=0 then begin
if Assigned(FOnCodeCompletion) then
begin
TextBetweenPointsEx[NewBlockBegin, NewBlockEnd, scamEnd] := Value;
Value := ItemList[Position];
FOnCodeCompletion(Value, TextBetweenPoints[NewBlockBegin, NewBlockEnd],
NewBlockBegin, NewBlockEnd, KeyChar, Shift);
if (CompareCarets(NewBlockBegin, NewBlockEnd) <> 0) or (Value <> '') then
begin
TextBetweenPointsEx[NewBlockBegin, NewBlockEnd, scamEnd] := Value;
TCustomSynEdit(F.CurrentEditor).SetFocus;
end;
end else begin
TextBetweenPointsEx[NewBlockBegin, NewBlockEnd, scamEnd] := ItemList[Position];
TCustomSynEdit(F.CurrentEditor).SetFocus;
end;
end else begin
TextBetweenPointsEx[NewBlockBegin, NewBlockEnd, scamEnd] := ItemList[Position];
TCustomSynEdit(F.CurrentEditor).SetFocus;
end;
end
else
if (ItemList.Count = 0) then
Cancel(Sender);
EndUpdate;
EndUndoBlock;
end
else
if (ItemList.Count = 0) then
Cancel(Sender);
finally
EndUpdate;
EndUndoBlock;
end;
end;
end;

View File

@ -6192,9 +6192,12 @@ end;
procedure TCustomSynEdit.ClearAll;
begin
InternalBeginUndoBlock;
SelectAll;
SelText:='';
InternalEndUndoBlock;
try
SelectAll;
SelText:='';
finally
InternalEndUndoBlock;
end;
end;
procedure TCustomSynEdit.ClearSelection;

View File

@ -979,12 +979,15 @@ procedure TCodeContextFrm.CompleteParameters(DeclCode: string);
end;
// insert
ASynEdit.BeginUndoBlock;
XY:=Point(X,Y);
ASynEdit.BlockBegin:=XY;
ASynEdit.BlockEnd:=XY;
ASynEdit.LogicalCaretXY:=XY;
ASynEdit.SelText:=NewCode;
ASynEdit.EndUndoBlock;
try
XY:=Point(X,Y);
ASynEdit.BlockBegin:=XY;
ASynEdit.BlockEnd:=XY;
ASynEdit.LogicalCaretXY:=XY;
ASynEdit.SelText:=NewCode;
finally
ASynEdit.EndUndoBlock;
end;
end;
var

View File

@ -325,10 +325,13 @@ begin
TxtXY:=CondSynEdit.LogicalCaretXY;
CondSynEdit.GetWordBoundsAtRowCol(TxtXY,TxtStartX,TxtEndX);
CondSynEdit.BeginUndoBlock();
CondSynEdit.BlockBegin:=Point(TxtStartX,TxtXY.Y);
CondSynEdit.BlockEnd:=Point(TxtEndX,TxtXY.Y);
CondSynEdit.SelText:=s;
CondSynEdit.EndUndoBlock();
try
CondSynEdit.BlockBegin:=Point(TxtStartX,TxtXY.Y);
CondSynEdit.BlockEnd:=Point(TxtEndX,TxtXY.Y);
CondSynEdit.SelText:=s;
finally
CondSynEdit.EndUndoBlock();
end;
FCompletionHistory.Insert(0,s);
if FCompletionHistory.Count>100 then
FCompletionHistory.Delete(FCompletionHistory.Count-1);

View File

@ -3404,21 +3404,24 @@ var
begin
if ReadOnly then exit;
FEditor.BeginUndoBlock;
if not EditorComponent.SelAvail then begin
P.Y := FEditor.CaretY;
P.X := 1;
FEditor.BlockBegin := P;
Inc(P.Y);
FEditor.BlockEnd := P;
try
if not EditorComponent.SelAvail then begin
P.Y := FEditor.CaretY;
P.X := 1;
FEditor.BlockBegin := P;
Inc(P.Y);
FEditor.BlockEnd := P;
end;
// ToDo: replace step by step to keep bookmarks and breakpoints
IsPascal := True;
i:=EditorOpts.HighlighterList.FindByHighlighter(FEditor.Highlighter);
if i>=0 then
IsPascal := EditorOpts.HighlighterList[i].DefaultCommentType <> comtCPP;
// will show modal dialog - must not be in Editor.BeginUpdate block, or painting will not work
FEditor.SelText:=AddConditional(EditorComponent.SelText,IsPascal);
finally
FEditor.EndUndoBlock;
end;
// ToDo: replace step by step to keep bookmarks and breakpoints
IsPascal := True;
i:=EditorOpts.HighlighterList.FindByHighlighter(FEditor.Highlighter);
if i>=0 then
IsPascal := EditorOpts.HighlighterList[i].DefaultCommentType <> comtCPP;
// will show modal dialog - must not be in Editor.BeginUpdate block, or painting will not work
FEditor.SelText:=AddConditional(EditorComponent.SelText,IsPascal);
FEditor.EndUndoBlock;
end;
procedure TSourceEditor.SortSelection;
@ -3443,10 +3446,13 @@ begin
FEditor.BeginUpdate;
FEditor.BeginUndoBlock;
// ToDo: replace step by step to keep bookmarks and breakpoints
OldSelection:=EditorComponent.SelText;
FEditor.SelText:=BreakLinesInText(OldSelection,FEditor.RightEdge);
FEditor.EndUndoBlock;
FEditor.EndUpdate;
try
OldSelection:=EditorComponent.SelText;
FEditor.SelText:=BreakLinesInText(OldSelection,FEditor.RightEdge);
finally
FEditor.EndUndoBlock;
FEditor.EndUpdate;
end;
end;
procedure TSourceEditor.InvertAssignment;
@ -3455,10 +3461,13 @@ begin
if not EditorComponent.SelAvail then exit;
FEditor.BeginUpdate;
FEditor.BeginUndoBlock;
// ToDo: replace step by step to keep bookmarks and breakpoints
FEditor.SelText := InvertAssignTool.InvertAssignment(FEditor.SelText);
FEditor.EndUndoBlock;
FEditor.EndUpdate;
try
// ToDo: replace step by step to keep bookmarks and breakpoints
FEditor.SelText := InvertAssignTool.InvertAssignment(FEditor.SelText);
finally
FEditor.EndUndoBlock;
FEditor.EndUpdate;
end;
end;
procedure TSourceEditor.SelectToBrace;
@ -3882,9 +3891,12 @@ begin
if not (Line[x2] in [' ',#9]) then
s:=s+' ';
FEditor.BeginUndoBlock;
FEditor.InsertTextAtCaret(s);
FEditor.LogicalCaretXY:=aTextPos;
FEditor.EndUndoBlock;
try
FEditor.InsertTextAtCaret(s);
FEditor.LogicalCaretXY:=aTextPos;
finally
FEditor.EndUndoBlock;
end;
end;
end;
end;

View File

@ -534,11 +534,14 @@ procedure TSourceEditorInterface.ReplaceText(const StartPos, EndPos: TPoint;
begin
BeginUpdate;
BeginUndoBlock;
SelectText(StartPos,EndPos);
CursorTextXY:=StartPos;
Selection:=NewText;
EndUndoBlock;
EndUpdate;
try
SelectText(StartPos,EndPos);
CursorTextXY:=StartPos;
Selection:=NewText;
finally
EndUndoBlock;
EndUpdate;
end;
end;
{ TIDECodeMacro }