Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/handlers/onDidSaveTextDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
30 changes: 29 additions & 1 deletion src/utils/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
Loading