Skip to content

Commit

Permalink
Mobile,Desktop: Fixes laurent22#11135: Fix incorrect list switching b…
Browse files Browse the repository at this point in the history
…ehavior (laurent22#11137)
  • Loading branch information
personalizedrefrigerator authored Sep 27, 2024
1 parent eda2c69 commit 948ca60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,19 @@ describe('markdownCommands.toggleList', () => {
);
expect(editor.state.selection.main.from).toBe(preSubListText.length);
});

it('should not treat a list of IP addresses as a numbered list', async () => {
const initialDocText = '192.168.1.1. This\n127.0.0.1. is\n0.0.0.0. a list';

const editor = await createTestEditor(
initialDocText,
EditorSelection.range(0, initialDocText.length),
[],
);

toggleList(ListType.UnorderedList)(editor);
expect(editor.state.doc.toString()).toBe(
'- 192.168.1.1. This\n- 127.0.0.1. is\n- 0.0.0.0. a list',
);
});
});
6 changes: 3 additions & 3 deletions packages/editor/CodeMirror/markdown/markdownCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export const toggleList = (listType: ListType): Command => {
// RegExps for different list types. The regular expressions MUST
// be mutually exclusive.
// `(?!\[[ xX]+\])` means "not followed by [x] or [ ]".
const bulletedRegex = /^\s*([-*])\s(?!\[[ xX]+\])/;
const checklistRegex = /^\s*[-*]\s\[[ xX]+\]\s?/;
const numberedRegex = /^\s*\d+\.\s?/;
const bulletedRegex = /^\s*([-*])\s(?!\[[ xX]+\]\s)/;
const checklistRegex = /^\s*[-*]\s\[[ xX]+\]\s/;
const numberedRegex = /^\s*\d+\.\s/;

const listRegexes: Record<ListType, RegExp> = {
[ListType.OrderedList]: numberedRegex,
Expand Down

0 comments on commit 948ca60

Please sign in to comment.