-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from marp-team/quick-pick
Add toolbar button for quick pick of Marp commands
- Loading branch information
Showing
8 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { commands, window, QuickPickItem } from 'vscode' | ||
import showQuickPick from './show-quick-pick' | ||
|
||
jest.mock('vscode') | ||
|
||
describe('showQuickPick command', () => { | ||
it('shows quick pick for Marp command', async () => { | ||
const expectedItem: QuickPickItem = { | ||
label: expect.any(String), | ||
description: expect.stringMatching(/^markdown\.marp/), | ||
} | ||
|
||
await showQuickPick() | ||
expect(window.showQuickPick).toBeCalledWith( | ||
expect.arrayContaining([expectedItem]), | ||
expect.anything() | ||
) | ||
}) | ||
|
||
it('executes command if selected item has description', async () => { | ||
jest.spyOn(window, 'showQuickPick').mockResolvedValue({ | ||
label: 'Example command', | ||
description: 'example.command', | ||
}) | ||
|
||
await showQuickPick() | ||
expect(commands.executeCommand).toBeCalledWith('example.command') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { commands, QuickPickItem, window } from 'vscode' | ||
import { contributes } from '../../package.json' | ||
|
||
const availableCommands: QuickPickItem[] = [] | ||
|
||
for (const command of contributes.commands) { | ||
if (command.command === 'markdown.marp.showQuickPick') continue | ||
|
||
availableCommands.push({ | ||
label: command.title, | ||
description: command.command, | ||
}) | ||
} | ||
|
||
export default async function showQuickPick() { | ||
const command = await window.showQuickPick(availableCommands, { | ||
matchOnDescription: true, | ||
placeHolder: 'Select available command in Marp for VS Code...', | ||
}) | ||
|
||
if (command && command.description) { | ||
await commands.executeCommand(command.description) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters