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..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 @@ -40,6 +44,30 @@ export function formatPath(path: string): string { return vscode.workspace.asRelativePath(path); } +const MAX_LINE_LENGTH = 80; + +export function addNewlinesToLongLines(text: string): string { + if (!isWindows()) { + return text; + } + 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)) {