import * as React from 'react'; import { ICommand, TextState, TextApi } from './'; import { selectWord } from '../utils/markdownUtils'; export const image: ICommand = { name: 'image', keyCommand: 'image', shortcuts: 'ctrlcmd+i', buttonProps: { 'aria-label': 'Add image', title: 'Add image' }, icon: ( ), execute: (state: TextState, api: TextApi) => { // Select everything const newSelectionRange = selectWord({ text: state.text, selection: state.selection }); const state1 = api.setSelectionRange(newSelectionRange); // Replaces the current selection with the image const imageTemplate = state1.selectedText || 'https://example.com/your-image.png'; api.replaceSelection(`![](${imageTemplate})`); // Adjust the selection to not contain the ** api.setSelectionRange({ start: 4 + state1.selection.start, end: 4 + state1.selection.start + imageTemplate.length, }); }, };