From f1a7770f0795bf1e230c1addea68d3fe2051ee86 Mon Sep 17 00:00:00 2001 From: Corwin Marsh Date: Sat, 23 Aug 2025 19:44:06 -0700 Subject: [PATCH 1/2] fix: Manually add newlines for confirmation warning message for consistent display across platforms --- src/handlers/onDidSaveTextDocument.ts | 8 ++++++-- src/utils/pathUtils.ts | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/handlers/onDidSaveTextDocument.ts b/src/handlers/onDidSaveTextDocument.ts index 1c4176b..7007768 100644 --- a/src/handlers/onDidSaveTextDocument.ts +++ b/src/handlers/onDidSaveTextDocument.ts @@ -4,7 +4,11 @@ import * as path from "path"; import { OIL_SCHEME } from "../constants"; import { getOilState, getCurrentPath } from "../state/oilState"; import { determineChanges, positionCursorOnFile } from "../utils/oilUtils"; -import { formatPath, uriPathToDiskPath } from "../utils/pathUtils"; +import { + addNewlinesToLongLines, + formatPath, + uriPathToDiskPath, +} from "../utils/pathUtils"; import { getDirectoryListing, removeDirectoryRecursively, @@ -199,7 +203,7 @@ export async function onDidSaveTextDocument(document: vscode.TextDocument) { } // Show confirmation dialog const response = await vscode.window.showWarningMessage( - message, + addNewlinesToLongLines(message), { modal: true }, "Yes", "No" diff --git a/src/utils/pathUtils.ts b/src/utils/pathUtils.ts index d25edb3..0cdfd66 100644 --- a/src/utils/pathUtils.ts +++ b/src/utils/pathUtils.ts @@ -40,6 +40,27 @@ export function formatPath(path: string): string { return vscode.workspace.asRelativePath(path); } +const MAX_LINE_LENGTH = 80; + +export function addNewlinesToLongLines(text: string): string { + const initialLines = text.split('\n'); + const lines: string[] = []; + for (const line of initialLines) { + let currentLine = line; + + while (currentLine.length > MAX_LINE_LENGTH) { + lines.push(currentLine.substring(0, MAX_LINE_LENGTH)); + currentLine = currentLine.substring(MAX_LINE_LENGTH); + } + + if (currentLine.length > 0) { + lines.push(currentLine); + } + } + + return lines.join('\n'); +} + export function oilUriToDiskPath(uri: vscode.Uri): string { // Convert an Oil URI to a file system path if (!(uri.scheme === OIL_SCHEME || uri.scheme === OIL_PREVIEW_SCHEME)) { From 69d52919d59eae57b9f7a21bee239438876e75f6 Mon Sep 17 00:00:00 2001 From: Corwin Marsh <7642548+corwinm@users.noreply.github.com> Date: Thu, 28 Aug 2025 11:07:57 -0700 Subject: [PATCH 2/2] Only add newlines on windows --- src/utils/pathUtils.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/pathUtils.ts b/src/utils/pathUtils.ts index 0cdfd66..d7251d8 100644 --- a/src/utils/pathUtils.ts +++ b/src/utils/pathUtils.ts @@ -10,9 +10,13 @@ export function normalizePathToUri(path: string | undefined = ""): string { return `/${normalizedPath}`; } +export function isWindows(): boolean { + return process.platform === "win32"; +} + export function uriPathToDiskPath(path: string): string { // If Windows, convert URI path to disk path - if (process.platform === "win32") { + if (isWindows()) { return path.replace(/^\//, ""); } // For other platforms, return the path as is @@ -43,7 +47,10 @@ export function formatPath(path: string): string { const MAX_LINE_LENGTH = 80; export function addNewlinesToLongLines(text: string): string { - const initialLines = text.split('\n'); + if (!isWindows()) { + return text; + } + const initialLines = text.split("\n"); const lines: string[] = []; for (const line of initialLines) { let currentLine = line; @@ -58,7 +65,7 @@ export function addNewlinesToLongLines(text: string): string { } } - return lines.join('\n'); + return lines.join("\n"); } export function oilUriToDiskPath(uri: vscode.Uri): string {