mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-04 01:25:38 -05:00
Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c (#8525)
* 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
This commit is contained in:
53
src/vs/platform/userDataSync/common/content.ts
Normal file
53
src/vs/platform/userDataSync/common/content.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user