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

View File

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

View File

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

View File

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

View File

@ -3404,21 +3404,24 @@ var
begin begin
if ReadOnly then exit; if ReadOnly then exit;
FEditor.BeginUndoBlock; FEditor.BeginUndoBlock;
if not EditorComponent.SelAvail then begin try
P.Y := FEditor.CaretY; if not EditorComponent.SelAvail then begin
P.X := 1; P.Y := FEditor.CaretY;
FEditor.BlockBegin := P; P.X := 1;
Inc(P.Y); FEditor.BlockBegin := P;
FEditor.BlockEnd := 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; 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; end;
procedure TSourceEditor.SortSelection; procedure TSourceEditor.SortSelection;
@ -3443,10 +3446,13 @@ begin
FEditor.BeginUpdate; FEditor.BeginUpdate;
FEditor.BeginUndoBlock; FEditor.BeginUndoBlock;
// ToDo: replace step by step to keep bookmarks and breakpoints // ToDo: replace step by step to keep bookmarks and breakpoints
OldSelection:=EditorComponent.SelText; try
FEditor.SelText:=BreakLinesInText(OldSelection,FEditor.RightEdge); OldSelection:=EditorComponent.SelText;
FEditor.EndUndoBlock; FEditor.SelText:=BreakLinesInText(OldSelection,FEditor.RightEdge);
FEditor.EndUpdate; finally
FEditor.EndUndoBlock;
FEditor.EndUpdate;
end;
end; end;
procedure TSourceEditor.InvertAssignment; procedure TSourceEditor.InvertAssignment;
@ -3455,10 +3461,13 @@ begin
if not EditorComponent.SelAvail then exit; if not EditorComponent.SelAvail then exit;
FEditor.BeginUpdate; FEditor.BeginUpdate;
FEditor.BeginUndoBlock; FEditor.BeginUndoBlock;
// ToDo: replace step by step to keep bookmarks and breakpoints try
FEditor.SelText := InvertAssignTool.InvertAssignment(FEditor.SelText); // ToDo: replace step by step to keep bookmarks and breakpoints
FEditor.EndUndoBlock; FEditor.SelText := InvertAssignTool.InvertAssignment(FEditor.SelText);
FEditor.EndUpdate; finally
FEditor.EndUndoBlock;
FEditor.EndUpdate;
end;
end; end;
procedure TSourceEditor.SelectToBrace; procedure TSourceEditor.SelectToBrace;
@ -3882,9 +3891,12 @@ begin
if not (Line[x2] in [' ',#9]) then if not (Line[x2] in [' ',#9]) then
s:=s+' '; s:=s+' ';
FEditor.BeginUndoBlock; FEditor.BeginUndoBlock;
FEditor.InsertTextAtCaret(s); try
FEditor.LogicalCaretXY:=aTextPos; FEditor.InsertTextAtCaret(s);
FEditor.EndUndoBlock; FEditor.LogicalCaretXY:=aTextPos;
finally
FEditor.EndUndoBlock;
end;
end; end;
end; end;
end; end;

View File

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