Skip to content

Commit

Permalink
feat: encapsulate the quickAccessProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed May 26, 2021
1 parent aa25528 commit 223ea3c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/monaco/quickAccessProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
IQuickAccessRegistry,
Extensions,
} from 'monaco-editor/esm/vs/platform/quickinput/common/quickAccess';
import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform';

const QuickAccessRegistry = Registry.as<IQuickAccessRegistry>(
Extensions.Quickaccess
);

/**
* Register a quickAccessProvider, if it's exist, remove it first and register.
* @param providerDescriptor
*/
export function registerQuickAccessProvider(providerDescriptor) {
removeQuickAccessProvider(providerDescriptor.prefix);
QuickAccessRegistry.registerQuickAccessProvider(providerDescriptor);
}

export function removeQuickAccessProvider(prefix) {
const index = QuickAccessRegistry.providers.findIndex(
(item) => item.prefix === prefix
);
if (index > -1) {
QuickAccessRegistry.providers.splice(index, 1);
}
}

0 comments on commit 223ea3c

Please sign in to comment.