Skip to content

Commit 856de22

Browse files
authored
fix: Manually add newlines for confirmation warning message for consistent display across platforms (#47)
1 parent 9840d29 commit 856de22

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/handlers/onDidSaveTextDocument.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as path from "path";
44
import { OIL_SCHEME } from "../constants";
55
import { getOilState, getCurrentPath } from "../state/oilState";
66
import { determineChanges, positionCursorOnFile } from "../utils/oilUtils";
7-
import { formatPath, uriPathToDiskPath } from "../utils/pathUtils";
7+
import {
8+
addNewlinesToLongLines,
9+
formatPath,
10+
uriPathToDiskPath,
11+
} from "../utils/pathUtils";
812
import {
913
getDirectoryListing,
1014
removeDirectoryRecursively,
@@ -199,7 +203,7 @@ export async function onDidSaveTextDocument(document: vscode.TextDocument) {
199203
}
200204
// Show confirmation dialog
201205
const response = await vscode.window.showWarningMessage(
202-
message,
206+
addNewlinesToLongLines(message),
203207
{ modal: true },
204208
"Yes",
205209
"No"

src/utils/pathUtils.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export function normalizePathToUri(path: string | undefined = ""): string {
1010
return `/${normalizedPath}`;
1111
}
1212

13+
export function isWindows(): boolean {
14+
return process.platform === "win32";
15+
}
16+
1317
export function uriPathToDiskPath(path: string): string {
1418
// If Windows, convert URI path to disk path
15-
if (process.platform === "win32") {
19+
if (isWindows()) {
1620
return path.replace(/^\//, "");
1721
}
1822
// For other platforms, return the path as is
@@ -40,6 +44,30 @@ export function formatPath(path: string): string {
4044
return vscode.workspace.asRelativePath(path);
4145
}
4246

47+
const MAX_LINE_LENGTH = 80;
48+
49+
export function addNewlinesToLongLines(text: string): string {
50+
if (!isWindows()) {
51+
return text;
52+
}
53+
const initialLines = text.split("\n");
54+
const lines: string[] = [];
55+
for (const line of initialLines) {
56+
let currentLine = line;
57+
58+
while (currentLine.length > MAX_LINE_LENGTH) {
59+
lines.push(currentLine.substring(0, MAX_LINE_LENGTH));
60+
currentLine = currentLine.substring(MAX_LINE_LENGTH);
61+
}
62+
63+
if (currentLine.length > 0) {
64+
lines.push(currentLine);
65+
}
66+
}
67+
68+
return lines.join("\n");
69+
}
70+
4371
export function oilUriToDiskPath(uri: vscode.Uri): string {
4472
// Convert an Oil URI to a file system path
4573
if (!(uri.scheme === OIL_SCHEME || uri.scheme === OIL_PREVIEW_SCHEME)) {

0 commit comments

Comments
 (0)