-
Notifications
You must be signed in to change notification settings - Fork 806
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 #4138 from udecode/fix/skip-mark
Fix mention plugin conflict with skip mark plugin
- Loading branch information
Showing
3 changed files
with
212 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@udecode/plate-basic-marks': patch | ||
--- | ||
|
||
Fix mention plugin conflict with skip mark plugin |
168 changes: 168 additions & 0 deletions
168
packages/basic-marks/src/lib/BaseSkipMarkPlugin.spec.tsx
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,168 @@ | ||
/** @jsx jsxt */ | ||
|
||
import type { SlateEditor } from '@udecode/plate'; | ||
|
||
import { BaseParagraphPlugin, createSlateEditor } from '@udecode/plate'; | ||
import { jsxt } from '@udecode/plate-test-utils'; | ||
|
||
import { BaseBoldPlugin } from './BaseBoldPlugin'; | ||
import { BaseCodePlugin } from './BaseCodePlugin'; | ||
import { BaseItalicPlugin } from './BaseItalicPlugin'; | ||
import { BaseSkipMarkPlugin } from './BaseSkipMarkPlugin'; | ||
|
||
jsxt; | ||
|
||
const skipMarkPlugin = BaseSkipMarkPlugin.configure({ | ||
options: { | ||
query: { | ||
allow: [BaseCodePlugin.key], | ||
}, | ||
}, | ||
}); | ||
const plugins = [ | ||
BaseParagraphPlugin, | ||
BaseBoldPlugin, | ||
BaseCodePlugin, | ||
BaseItalicPlugin, | ||
skipMarkPlugin, | ||
]; | ||
|
||
describe('BaseSkipMarkPlugin', () => { | ||
describe('insertText', () => { | ||
describe('when cursor is not in a mark', () => { | ||
it('should insert text normally', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
test | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
testinserted | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
}); | ||
|
||
describe('when cursor is at the end of a mark', () => { | ||
it('should remove marks when inserting text', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<htext>inserted</htext> | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
|
||
it('should not remove marks when between same marks', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<cursor /> | ||
<htext bold code> | ||
more | ||
</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext code>testinserted</htext> | ||
<cursor /> | ||
<htext bold code> | ||
more | ||
</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
}); | ||
|
||
describe('when different mark types are adjacent', () => { | ||
it('should remove marks when inserting text', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<cursor /> | ||
<htext italic>more</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<htext>inserted</htext> | ||
<cursor /> | ||
<htext italic>more</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
}); | ||
}); | ||
}); |
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