mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 01:25:37 -05:00
* Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c * remove files we don't want * fix hygiene * update distro * update distro * fix hygiene * fix strict nulls * distro * distro * fix tests * fix tests * add another edit * fix viewlet icon * fix azure dialog * fix some padding * fix more padding issues
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { JSONPath } from 'vs/base/common/json';
|
|
import { setProperty } from 'vs/base/common/jsonEdit';
|
|
import { FormattingOptions } from 'vs/base/common/jsonFormatter';
|
|
|
|
|
|
export function edit(content: string, originalPath: JSONPath, value: any, formattingOptions: FormattingOptions): string {
|
|
const edit = setProperty(content, originalPath, value, formattingOptions)[0];
|
|
if (edit) {
|
|
content = content.substring(0, edit.offset) + edit.content + content.substring(edit.offset + edit.length);
|
|
}
|
|
return content;
|
|
}
|
|
|
|
export function getLineStartOffset(content: string, eol: string, atOffset: number): number {
|
|
let lineStartingOffset = atOffset;
|
|
while (lineStartingOffset >= 0) {
|
|
if (content.charAt(lineStartingOffset) === eol.charAt(eol.length - 1)) {
|
|
if (eol.length === 1) {
|
|
return lineStartingOffset + 1;
|
|
}
|
|
}
|
|
lineStartingOffset--;
|
|
if (eol.length === 2) {
|
|
if (lineStartingOffset >= 0 && content.charAt(lineStartingOffset) === eol.charAt(0)) {
|
|
return lineStartingOffset + 2;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
export function getLineEndOffset(content: string, eol: string, atOffset: number): number {
|
|
let lineEndOffset = atOffset;
|
|
while (lineEndOffset >= 0) {
|
|
if (content.charAt(lineEndOffset) === eol.charAt(eol.length - 1)) {
|
|
if (eol.length === 1) {
|
|
return lineEndOffset;
|
|
}
|
|
}
|
|
lineEndOffset++;
|
|
if (eol.length === 2) {
|
|
if (lineEndOffset >= 0 && content.charAt(lineEndOffset) === eol.charAt(1)) {
|
|
return lineEndOffset;
|
|
}
|
|
}
|
|
}
|
|
return content.length - 1;
|
|
}
|