monaco-editor-core
Version:
A browser based code editor
31 lines (30 loc) • 1.3 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from '../../instantiation/common/instantiation.js';
export const IOpenerService = createDecorator('openerService');
/**
* file:///some/file.js#73
* file:///some/file.js#L73
* file:///some/file.js#73,84
* file:///some/file.js#L73,84
* file:///some/file.js#73-83
* file:///some/file.js#L73-L83
* file:///some/file.js#73,84-83,52
* file:///some/file.js#L73,84-L83,52
*/
export function extractSelection(uri) {
let selection = undefined;
const match = /^L?(\d+)(?:,(\d+))?(-L?(\d+)(?:,(\d+))?)?/.exec(uri.fragment);
if (match) {
selection = {
startLineNumber: parseInt(match[1]),
startColumn: match[2] ? parseInt(match[2]) : 1,
endLineNumber: match[4] ? parseInt(match[4]) : undefined,
endColumn: match[4] ? (match[5] ? parseInt(match[5]) : 1) : undefined
};
uri = uri.with({ fragment: '' });
}
return { selection, uri };
}