All files / src/web bpmnEditorRouting.ts

100% Statements 13/13
100% Branches 16/16
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39      1x     13x       3x 3x             6x 2x     4x 6x 3x     1x           4x 2x     2x  
import * as vscode from 'vscode';
import { BPMN_EDITOR_VIEW_TYPE } from './flowableBpmn';
 
const BPMN_FILE_PATTERN = /(?:\.bpmn20\.xml|\.bpmn2|\.bpmn)$/i;
 
export function isBpmnFileName(fileName: string): boolean {
	return BPMN_FILE_PATTERN.test(fileName);
}
 
export function getTabInputUri(input: unknown): vscode.Uri | undefined {
	const candidate = input as { uri?: vscode.Uri } | undefined;
	return candidate?.uri;
}
 
export function resolveActiveBpmnUri(
	activeTextEditor: { document: { fileName: string; uri: vscode.Uri } } | undefined = vscode.window.activeTextEditor,
	activeTab: { input: unknown } | undefined = vscode.window.tabGroups.activeTabGroup.activeTab,
): vscode.Uri | undefined {
	if (activeTextEditor && isBpmnFileName(activeTextEditor.document.fileName)) {
		return activeTextEditor.document.uri;
	}
 
	const input = activeTab?.input as { viewType?: string; uri?: vscode.Uri } | undefined;
	if (input?.uri && (input.viewType === BPMN_EDITOR_VIEW_TYPE || isBpmnFileName(input.uri.path))) {
		return input.uri;
	}
 
	return undefined;
}
 
export function getActiveBpmnTextDocument(
	activeTextEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor,
): vscode.TextDocument | undefined {
	if (activeTextEditor && isBpmnFileName(activeTextEditor.document.fileName)) {
		return activeTextEditor.document;
	}
 
	return undefined;
}