From 69a92e02d281fa94f7113c42f49e6fb3c90922c6 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 26 Sep 2025 08:56:33 +0200 Subject: [PATCH] Validates text selection before processing Refactors text validation to ensure that the cleanup process only proceeds with valid text selections. Removes the insertion position logic as it is no longer needed. --- commands/cleanupCommand.ts | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/commands/cleanupCommand.ts b/commands/cleanupCommand.ts index e8e3c03..85fffc9 100644 --- a/commands/cleanupCommand.ts +++ b/commands/cleanupCommand.ts @@ -24,10 +24,10 @@ export class CleanupCommand { return; } - // Validate text length before proceeding - const limits = CleanupService.isWithinLimits(selectedText); - if (!limits.withinCharacterLimit) { - new Notice(`Selected text is too long (${limits.characterCount} characters). Maximum: 680,000 characters.`); + // Validate text selection before proceeding + const validation = this.validateSelection(selectedText); + if (!validation.isValid) { + new Notice(validation.error || 'Invalid text selection'); return; } @@ -87,19 +87,6 @@ export class CleanupCommand { // MARK: - Helper Methods - private getInsertionPosition(editor: Editor): { line: number; ch: number } { - const selection = editor.listSelections()[0]; - if (selection) { - // Insert after the selection - return { - line: selection.head.line, - ch: editor.getLine(selection.head.line).length - }; - } - - // Fallback to current cursor position - return editor.getCursor(); - } private formatSelectedTextInfo(text: string): string { const characterCount = text.length;