Fixes #8811 Before this PR, even if you did not include text formatting features (such as BoldFeature, ItalicFeature, etc), it was possible to apply that formatting by (a) pasting content from the clipboard and (b) using keyboard shortcuts. This PR fixes that by requiring the formatting features to be registered so that they can be inserted in the editor.
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
'use client'
|
|
|
|
import { $isTableSelection } from '@lexical/table'
|
|
import { $isRangeSelection, FORMAT_TEXT_COMMAND } from 'lexical'
|
|
|
|
import type { ToolbarGroup } from '../../toolbars/types.js'
|
|
|
|
import { CodeIcon } from '../../../lexical/ui/icons/Code/index.js'
|
|
import { createClientFeature } from '../../../utilities/createClientFeature.js'
|
|
import { toolbarFormatGroupWithItems } from '../shared/toolbarFormatGroup.js'
|
|
import { INLINE_CODE } from './markdownTransformers.js'
|
|
|
|
const toolbarGroups: ToolbarGroup[] = [
|
|
toolbarFormatGroupWithItems([
|
|
{
|
|
ChildComponent: CodeIcon,
|
|
isActive: ({ selection }) => {
|
|
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
return selection.hasFormat('code')
|
|
}
|
|
return false
|
|
},
|
|
key: 'inlineCode',
|
|
onSelect: ({ editor }) => {
|
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code')
|
|
},
|
|
order: 7,
|
|
},
|
|
]),
|
|
]
|
|
|
|
export const InlineCodeFeatureClient = createClientFeature({
|
|
enableFormats: ['code'],
|
|
markdownTransformers: [INLINE_CODE],
|
|
toolbarFixed: {
|
|
groups: toolbarGroups,
|
|
},
|
|
toolbarInline: {
|
|
groups: toolbarGroups,
|
|
},
|
|
})
|