From 594c5696a93b85d4f5ce780faa666418aa71eb2b Mon Sep 17 00:00:00 2001 From: Zane Duffield Date: Thu, 24 Apr 2025 08:49:19 +1000 Subject: [PATCH] Skip formatting for unsupported file types --- CHANGELOG.md | 4 ++++ Pasfmt.FormatEditor.pas | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58e8fe5..c6824cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +* Ignore formatting requests for files without matching file extensions (pas, dpr, dpk, inc). + ## [0.2.0] - 2025-03-18 ### Added diff --git a/Pasfmt.FormatEditor.pas b/Pasfmt.FormatEditor.pas index 0495c3a..4d750a5 100644 --- a/Pasfmt.FormatEditor.pas +++ b/Pasfmt.FormatEditor.pas @@ -27,7 +27,8 @@ implementation Pasfmt.Log, System.StrUtils, Vcl.Dialogs, - System.UITypes; + System.UITypes, + System.IOUtils; //______________________________________________________________________________________________________________________ @@ -89,8 +90,14 @@ procedure TEditBufferFormatter.Format(Buffer: IOTAEditBuffer); SourceEditor: IOTAEditorContent; DebuggerServices: IOTADebuggerServices; Cursors: TCursors; + Extension: string; begin - if not Supports(Buffer, IOTAEditorContent, SourceEditor) then begin + Extension := TPath.GetExtension(Buffer.FileName); + if not MatchText(Extension, ['.pas', '.dpr', '.dpk', '.inc']) then begin + Log.Debug('Format request ignored: unsupported file extension "%s"', [Extension]); + Exit; + end + else if not Supports(Buffer, IOTAEditorContent, SourceEditor) then begin Log.Debug('Format request ignored: the editor is not formattable', [Buffer.FileName]); Exit; end