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 backspace-at-index-0 behavior by ignoring negative start indices #270

Merged
merged 1 commit into from
Dec 4, 2014

Conversation

thomsbg
Copy link
Contributor

@thomsbg thomsbg commented Dec 3, 2014

Reproducible on quilljs.com by placing cursor before first letter and hitting the 'Backspace' key.

Expected behavior: nothing happens.
Observed behavior: the first character is deleted.

@jhchen
Copy link
Member

jhchen commented Dec 3, 2014

Cool thanks for the catch on the bug. I think I was being too clever in setting start's value in the line above and the code might be more clear if that part was just a normal if/else block. Can you make the change and squash the commits?

@thomsbg
Copy link
Contributor Author

thomsbg commented Dec 4, 2014

Do you mean like this?

if hotkey.key == dom.KEYS.BACKSPACE
  start = range.start - 1
else
  start = range.start
@quill.deleteText(start, start + 1, Quill.sources.USER) if start >= 0

Or perhaps this would be better?

start = range.start
start -= 1 if hotkey.key == dom.KEYS.BACKSPACE
@quill.deleteText(start, start + 1, Quill.sources.USER) if start >= 0

@jhchen
Copy link
Member

jhchen commented Dec 4, 2014

Actually thinking about it more I think the commit is fine. I was thinking something else but I realized there was another issue with it.

jhchen added a commit that referenced this pull request Dec 4, 2014
Fix backspace-at-index-0 behavior by ignoring negative start indices
@jhchen jhchen merged commit 44364b5 into slab:develop Dec 4, 2014
@thomsbg thomsbg deleted the backspace-first-char branch October 7, 2015 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants