Replace all instead of just replace
This commit is contained in:
parent
9c3dedad76
commit
f11c8db6d2
5 changed files with 29 additions and 7 deletions
|
|
@ -114,14 +114,14 @@ export class FileOperations {
|
|||
`Performing a 3-way merge for ${path} with the expected content`
|
||||
);
|
||||
|
||||
text = text.replace(this.nativeLineEndings, "\n");
|
||||
text = text.replaceAll(this.nativeLineEndings, "\n");
|
||||
const merged = reconcile(
|
||||
expectedText,
|
||||
{ text, cursors },
|
||||
newText
|
||||
);
|
||||
|
||||
const resultText = merged.text.replace(
|
||||
const resultText = merged.text.replaceAll(
|
||||
"\n",
|
||||
this.nativeLineEndings
|
||||
);
|
||||
|
|
@ -197,7 +197,7 @@ export class FileOperations {
|
|||
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
let text = decoder.decode(content);
|
||||
text = text.replace(this.nativeLineEndings, "\n");
|
||||
text = text.replaceAll(this.nativeLineEndings, "\n");
|
||||
return new TextEncoder().encode(text);
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ export class FileOperations {
|
|||
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
let text = decoder.decode(content);
|
||||
text = text.replace("\n", this.nativeLineEndings);
|
||||
text = text.replaceAll("\n", this.nativeLineEndings);
|
||||
return new TextEncoder().encode(text);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ export class SyncService {
|
|||
|
||||
private getUrl(path: string): string {
|
||||
const { vaultName, remoteUri } = this.settings.getSettings();
|
||||
const safeRemoteUri = remoteUri.replace(/\/+$/, "");
|
||||
const safeRemoteUri = remoteUri.replace(/\/+$/g, "");
|
||||
return `${safeRemoteUri}/vaults/${vaultName}${path}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export function lineAndColumnToPosition(
|
|||
line: number,
|
||||
column: number
|
||||
): number {
|
||||
const lines = text.replace("\r", "").split("\n");
|
||||
const lines = text.replaceAll("\r", "").split("\n");
|
||||
|
||||
if (line >= lines.length) {
|
||||
throw new Error(`Line number ${line} is out of range.`);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,28 @@ describe("positionToLineAndColumn", () => {
|
|||
});
|
||||
});
|
||||
|
||||
test("with multiple carriage returns", () => {
|
||||
// Test that all \r characters are removed, not just the first one
|
||||
const text = "line1\r\nline2\r\nline3\r\n";
|
||||
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 0), {
|
||||
line: 0,
|
||||
column: 0
|
||||
});
|
||||
|
||||
// Position 6 = start of 'line2' after all \r removed
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 6), {
|
||||
line: 1,
|
||||
column: 0
|
||||
});
|
||||
|
||||
// Position 12 = start of 'line3' after all \r removed
|
||||
assert.deepStrictEqual(positionToLineAndColumn(text, 12), {
|
||||
line: 2,
|
||||
column: 0
|
||||
});
|
||||
});
|
||||
|
||||
test("handles empty input", () => {
|
||||
assert.deepStrictEqual(positionToLineAndColumn("", 0), {
|
||||
line: 0,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export function positionToLineAndColumn(
|
|||
throw new Error("Position cannot be negative");
|
||||
}
|
||||
|
||||
text = text.replace("\r", "");
|
||||
text = text.replaceAll("\r", "");
|
||||
|
||||
if (
|
||||
position >
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue