fix(quick add magic): don't replace the prefix in every occurrence when it is present in the matched part

This commit is contained in:
kolaente 2023-04-03 19:21:52 +02:00 committed by konrad
parent 11979cbee0
commit 0724776ccb
2 changed files with 13 additions and 3 deletions

View File

@ -691,6 +691,14 @@ describe('Parse Task Text', () => {
expect(result.assignees).toHaveLength(1) expect(result.assignees).toHaveLength(1)
expect(result.assignees[0]).toBe('today') expect(result.assignees[0]).toBe('today')
}) })
it('should recognize an email address', () => {
const text = 'Lorem Ipsum @email@example.com'
const result = parseTaskText(text)
expect(result.text).toBe('Lorem Ipsum @email@example.com')
expect(result.assignees).toHaveLength(1)
expect(result.assignees[0]).toBe('email@example.com')
})
}) })
describe('Recurring Dates', () => { describe('Recurring Dates', () => {

View File

@ -109,7 +109,9 @@ const getItemsFromPrefix = (text: string, prefix: string): string[] => {
return return
} }
p = p.replace(prefix, '') if (p.substring(0, 1) === prefix) {
p = p.substring(1)
}
let itemText let itemText
if (p.charAt(0) === '\'') { if (p.charAt(0) === '\'') {
@ -120,8 +122,8 @@ const getItemsFromPrefix = (text: string, prefix: string): string[] => {
// Only until the next space // Only until the next space
itemText = p.split(' ')[0] itemText = p.split(' ')[0]
} }
if(itemText !== '') { if (itemText !== '') {
items.push(itemText) items.push(itemText)
} }
}) })