Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion spec/cursor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions spec/dispatcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
16 changes: 5 additions & 11 deletions src/create-default-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down