diff --git a/spec/cursor.spec.js b/spec/cursor.spec.js index 2d78d6af..1a073bd3 100644 --- a/spec/cursor.spec.js +++ b/spec/cursor.spec.js @@ -47,9 +47,15 @@ describe('Cursor', function () { expect(this.range.endOffset).toEqual(1) }) + describe('isAtTextEnd()', () => { + it('returns true when at text end', () => { + expect(this.cursor.isAtEnd()).toBe(true) + }) + }) + describe('isAtEnd()', () => { it('is true', () => { - expect(this.cursor.isAtEnd()).toBe(true) + expect(this.cursor.isAtTextEnd()).toBe(true) }) }) @@ -66,6 +72,7 @@ describe('Cursor', function () { // move the cursor so we can check the restore method. this.cursor.moveAtBeginning() expect(this.cursor.isAtBeginning()).toBe(true) + expect(this.cursor.isAtTextEnd()).toBe(false) this.cursor.restore() expect(this.cursor.isAtEnd()).toBe(true) diff --git a/spec/dispatcher.spec.js b/spec/dispatcher.spec.js index d0b3e176..77bc1145 100644 --- a/spec/dispatcher.spec.js +++ b/spec/dispatcher.spec.js @@ -195,5 +195,18 @@ describe('Dispatcher', () => { $elem.trigger(event) }) }) + + describe('on newline', () => { + beforeEach(() => { + event = $.Event('keydown') + event.shiftKey = true + event.keyCode = 13 + }) + + it('fires newline when shift + enter is pressed', (done) => { + on('newline', done) + $elem.trigger(event) + }) + }) }) }) diff --git a/src/create-default-behavior.js b/src/create-default-behavior.js index 80e1e1f5..e4d6ff4c 100644 --- a/src/create-default-behavior.js +++ b/src/create-default-behavior.js @@ -48,19 +48,13 @@ export default function createDefaultBehavior (editable) { }, newline (element, cursor) { - cursor.insertBefore(document.createElement('br')) - if (cursor.isAtEnd()) { - log('at the end') - - const noWidthSpace = document.createTextNode('\u200B') - cursor.insertAfter(noWidthSpace) - - // var trailingBr = document.createElement('br') - // trailingBr.setAttribute('type', '-editablejs') - // cursor.insertAfter(trailingBr) + if (cursor.isAtTextEnd()) { + const trailingBr = document.createElement('br') + trailingBr.setAttribute('data-editable', 'remove') + cursor.insertBefore(trailingBr) } else { - log('not at the end') + cursor.insertBefore(document.createElement('br')) } cursor.setVisibleSelection()