From d9aaca92f9a8df41e58c8ee5a5a500766d71565c Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 23 May 2016 22:11:24 +0200 Subject: [PATCH] [json formatter] add applyEdit --- src/vs/base/common/jsonFormatter.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/vs/base/common/jsonFormatter.ts b/src/vs/base/common/jsonFormatter.ts index 422ade29a07..686ecd48b0c 100644 --- a/src/vs/base/common/jsonFormatter.ts +++ b/src/vs/base/common/jsonFormatter.ts @@ -27,6 +27,17 @@ export interface Edit { content: string; } +export function applyEdit(text: string, edit: Edit) : string { + return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length); +} + +export function applyEdits(text: string, edits: Edit[]) : string { + for (let i = edits.length - 1; i >= 0; i--) { + text = applyEdit(text, edits[i]); + } + return text; +} + export function format(documentText: string, range: { offset: number, length: number}, options: FormattingOptions): Edit[] { let initialIndentLevel: number; let value: string; -- GitLab