diff --git a/src/doc.js b/src/doc.js index f570f33..5b927c7 100644 --- a/src/doc.js +++ b/src/doc.js @@ -423,7 +423,7 @@ var prototype = node.derive({ return; } this.selection.start = Math.max(0, ordinal); - this.selection.end = Math.max( + this.selection.end = Math.min( typeof ordinalEnd === 'number' ? ordinalEnd : this.selection.start, this.frame.length - 1 ); @@ -438,6 +438,9 @@ var prototype = node.derive({ */ this.notifySelectionChanged(takeFocus); }, + selectFrom: function( start, takeFocus ){ + this.select( start, this.frame.length - 1, takeFocus ); + }, selectAll: function(){ this.select( 0, this.frame.length - 1, true ); }, diff --git a/test/doc.spec.js b/test/doc.spec.js index 7690269..2d33b71 100644 --- a/test/doc.spec.js +++ b/test/doc.spec.js @@ -49,8 +49,8 @@ test('save function should return the selected content with default styles appli ]); }); -test('select function should take end of text if end index is not specified', () => { - document.select( 3 ); +test('select function should take end of text if second param is `end` ', () => { + document.selectFrom( 3 ); expect( document.selectedRange().save()).toEqual([ { text: 'here', @@ -65,6 +65,8 @@ test('select function should take end of text if end index is not specified', () script: 'normal', }, ]); + }); +