Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7604dc3

Browse files
committedMar 7, 2025·
Confirm with user when formatting in a debug session
Formatting a file while debugging causes the highlighting of the source code from the debugger to disappear and there's no way (that I've found) to get it back. With this change, we confirm with the user via a dialog whether they really want to format while debugging.
1 parent 30dd0d7 commit 7604dc3

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
* Support for updating breakpoints and bookmarks after the buffer rewrite.
13+
* Confirmation prompt for formatting while debugging.
1314

1415
## [0.1.0] - 2025-02-20
1516

‎Pasfmt.FormatEditor.pas

+20-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ implementation
2525
Winapi.ActiveX,
2626
Vcl.AxCtrls,
2727
Pasfmt.Log,
28-
System.StrUtils;
28+
System.StrUtils,
29+
Vcl.Dialogs,
30+
System.UITypes;
2931

3032
//______________________________________________________________________________________________________________________
3133

@@ -73,9 +75,19 @@ procedure SetBufferViewMessages(Buffer: IOTAEditBuffer; Msg: string);
7375

7476
//______________________________________________________________________________________________________________________
7577

78+
function ConfirmFormatWhileDebugging: Boolean;
79+
begin
80+
Result :=
81+
MessageDlg('Formatting will disrupt debugging in this file. Continue?', mtWarning, [mbOK, mbCancel], 0, mbCancel)
82+
= mrOK;
83+
end;
84+
85+
//______________________________________________________________________________________________________________________
86+
7687
procedure TEditBufferFormatter.Format(Buffer: IOTAEditBuffer);
7788
var
7889
SourceEditor: IOTAEditorContent;
90+
DebuggerServices: IOTADebuggerServices;
7991
Cursors: TCursors;
8092
begin
8193
if not Supports(Buffer, IOTAEditorContent, SourceEditor) then begin
@@ -85,6 +97,13 @@ procedure TEditBufferFormatter.Format(Buffer: IOTAEditBuffer);
8597
else if Buffer.IsReadOnly then begin
8698
Log.Debug('Format request ignored: "%s" is read-only', [Buffer.FileName]);
8799
Exit;
100+
end
101+
else if Supports(BorlandIDEServices, IOTADebuggerServices, DebuggerServices)
102+
and Assigned(DebuggerServices.CurrentProcess)
103+
and not ConfirmFormatWhileDebugging then
104+
begin
105+
Log.Debug('Format request ignored: debugger is running and user has cancelled');
106+
Exit;
88107
end;
89108

90109
SetBufferViewMessages(Buffer, 'Formatting...');

‎Pasfmt.Main.pas

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ procedure TPlugin.OnFormatKeyPress(
207207
var BindingResult: TKeyBindingResult
208208
);
209209
begin
210+
BindingResult := krHandled;
210211
Format;
211212
end;
212213

0 commit comments

Comments
 (0)
Please sign in to comment.