Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected getOpenChangesOptions(widget?: Widget): GitOpenChangesOptions | undefined {
const provider = this.repositoryProvider.selectedScmProvider;
if (!provider) {
return undefined;
}
const ref = widget ? widget : this.editorManager.currentEditor;
if (ref instanceof EditorWidget && !DiffUris.isDiffUri(ref.editor.uri)) {
const uri = ref.editor.uri;
const change = provider.findChange(uri);
if (change && provider.getUriToOpen(change).toString() !== uri.toString()) {
const selection = ref.editor.selection;
return { change, options: { selection, widgetOptions: { ref } } };
}
}
return undefined;
}
protected getOpenFileOptions(widget?: Widget): GitOpenFileOptions | undefined {
const ref = widget ? widget : this.editorManager.currentEditor;
if (ref instanceof EditorWidget && DiffUris.isDiffUri(ref.editor.uri)) {
const [, right] = DiffUris.decode(ref.editor.uri);
const uri = right.withScheme('file');
const selection = ref.editor.selection;
return { uri, options: { selection, widgetOptions: { ref } } };
}
return undefined;
}
protected getOpenChangesOptions(widget?: Widget): GitOpenChangesOptions | undefined {
const view = this.tryGetWidget();
if (!view) {
return undefined;
}
const ref = widget ? widget : this.editorManager.currentEditor;
if (ref instanceof EditorWidget && !DiffUris.isDiffUri(ref.editor.uri)) {
const uri = ref.editor.uri;
const change = view.findChange(uri);
if (change && view.getUriToOpen(change).toString() !== uri.toString()) {
const selection = ref.editor.selection;
return { change, options: { selection, widgetOptions: { ref } } };
}
}
return undefined;
}
textCompareEditorVisible.set(widgets.some(widget => DiffUris.isDiffUri(widget.editor.uri)));
};
protected decorateEditor(node: SearchInWorkspaceFileNode | undefined, editorWidget: EditorWidget): void {
if (!DiffUris.isDiffUri(editorWidget.editor.uri)) {
const key = `${editorWidget.editor.uri.toString()}#search-in-workspace-matches`;
const oldDecorations = this.appliedDecorations.get(key) || [];
const newDecorations = this.createEditorDecorations(node);
const appliedDecorations = editorWidget.editor.deltaDecorations({
newDecorations,
oldDecorations,
});
this.appliedDecorations.set(key, appliedDecorations);
}
}
static async findEditorByUri(editorManager: EditorManager, uri: string): Promise {
const editorWidget = await editorManager.getByUri(new URI(uri));
if (editorWidget) {
const editorUri = editorWidget.editor.uri;
const openedInEditor = editorUri.toString() === uri;
const openedInDiffEditor = DiffUris.isDiffUri(editorUri) && DiffUris.decode(editorUri).some(u => u.toString() === uri);
if (openedInEditor || openedInDiffEditor) {
return editorWidget.editor;
}
}
return undefined;
}
protected getOpenFileOptions(widget?: Widget): GitOpenFileOptions | undefined {
const ref = widget ? widget : this.editorManager.currentEditor;
if (ref instanceof EditorWidget && DiffUris.isDiffUri(ref.editor.uri)) {
const [, right] = DiffUris.decode(ref.editor.uri);
const uri = right.withScheme('file');
const selection = ref.editor.selection;
return { uri, options: { selection, widgetOptions: { ref } } };
}
return undefined;
}
selection: {
start: {
line: node.line - 1,
character: node.character - 1
},
end: {
line: node.line - 1,
character: node.character - 1 + node.length
}
},
mode: 'reveal'
} : undefined;
const editorWidget = await this.editorManager.open(fileUri, opts);
if (!DiffUris.isDiffUri(fileUri)) {
this.decorateEditor(resultNode, editorWidget);
}
return editorWidget;
}