mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-19 14:49:29 +02:00
Added try finally to some UndoBlock (editor)
git-svn-id: trunk@34977 -
This commit is contained in:
parent
c25543b689
commit
d503d615c5
@ -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;
|
||||
|
||||
|
@ -6192,9 +6192,12 @@ end;
|
||||
procedure TCustomSynEdit.ClearAll;
|
||||
begin
|
||||
InternalBeginUndoBlock;
|
||||
SelectAll;
|
||||
SelText:='';
|
||||
InternalEndUndoBlock;
|
||||
try
|
||||
SelectAll;
|
||||
SelText:='';
|
||||
finally
|
||||
InternalEndUndoBlock;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomSynEdit.ClearSelection;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 }
|
||||
|
Loading…
Reference in New Issue
Block a user