Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/65 unexpected blur #73

Merged
merged 2 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill-magic-url",
"version": "4.1.3",
"version": "4.1.4",
"description": "Checks for URLs during typing and pasting and automatically converts them to links.",
"main": "dist/index.js",
"babel": {
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export default class MagicUrl {
return
}

const nextLetter = leaf.text[relevantLength]
// Do not proceed if we are in the middle of a word
if (nextLetter != null && nextLetter.match(/\S/)) {
return
}

const bailOutEndingRegex = triggeredByInlineWhitespace ? /\s\s$/ : /\s$/
if (text.match(bailOutEndingRegex)) {
return
Expand Down
23 changes: 23 additions & 0 deletions tests/e2e/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,29 @@ describe('quill-magic-url', () => {
})
})

describe('blur', () => {
it('does not convert when inside word', () => {
type('https://google.com {leftarrow}{leftarrow}')
cy.get('.ql-remove').click()
cy.get('@editor').blur()
shouldContain('<p>https://google.com </p>')
})

it('does not convert when inside word after clicking out', () => {
type(
'https://google.com test{leftarrow}{leftarrow}{leftarrow}{leftarrow}{leftarrow}{leftarrow}'
)
cy.get('.ql-remove').click()
cy.get('@editor').click('bottomRight')
cy.get('@editor').blur()
shouldContain('<p>https://google.com test</p>')
cy.get('@editor').click('bottomRight')
type('{leftarrow}{leftarrow}{leftarrow}{leftarrow}{leftarrow}{leftarrow}')
cy.get('@editor').blur()
shouldContain('<p>https://google.com test</p>')
})
})

describe('paste', () => {
it('for single url', () => {
paste('http://test.de')
Expand Down