Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/drafts/MarkdownEditor/_useListEditing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const calculateNextListItemStarter = ({leadingWhitespace = '', delimeter, taskBo
* 3. Task box (optional)
* 4. Everything following
*/
export const listItemRegex = /^(\s*)([*-]|(\d+)\.)\s(?:(\[[\sx]\])\s)?(.*)/i
export const listItemRegex = /^(\s*)([*-]|(\d+)\.)(\s{1,2})(?:(\[[\sx]\])\s)?(.*)/i
Copy link
Contributor

@iansan5653 iansan5653 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are tab characters valid here? Maybe more correct would be space only ( ). Not sure though. It's a minor thing though since that bug would've already been present before this change.

Suggested change
export const listItemRegex = /^(\s*)([*-]|(\d+)\.)(\s{1,2})(?:(\[[\sx]\])\s)?(.*)/i
export const listItemRegex = /^(\s*)([*-]|(\d+)\.)( {1,2})(?:(\[[\sx]\])\s)?(.*)/i

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\s is identifying tabs as well, i just checked


export type ListItem = {
leadingWhitespace: string
Expand All @@ -45,7 +45,7 @@ const isNumericListItem = (item: ListItem | null): item is NumericListItem => ty
export const parseListItem = (line: string): ListItem | null => {
const result = listItemRegex.exec(line)
if (!result) return null
const [, leadingWhitespace = '', fullDelimeter, itemNumberStr = '', taskBox = null, text] = result
const [, leadingWhitespace = '', fullDelimeter, itemNumberStr = '', , taskBox = null, text] = result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are skipping the capture group for the one or two spaces, meaning that the updated Markdown will always have only one space. Do we maybe want to preserve the number of spaces like we do with leadingWhitespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ad9c47f

const itemNumber = Number.parseInt(itemNumberStr, 10)
const delimeter = Number.isNaN(itemNumber) ? (fullDelimeter as '*' | '-') : itemNumber

Expand Down