Add chaining to iText selection methods (#4178)

This commit is contained in:
Nick Swider 2017-08-09 03:05:40 -04:00 committed by Andrea Bogazzi
parent ddb9896455
commit da27ef57c4
2 changed files with 10 additions and 0 deletions

View file

@ -169,12 +169,15 @@
/**
* Selects entire text
* @return {fabric.IText} thisArg
* @chainable
*/
selectAll: function() {
this.selectionStart = 0;
this.selectionEnd = this._text.length;
this._fireSelectionChanged();
this._updateTextarea();
return this;
},
/**
@ -303,6 +306,8 @@
/**
* Selects a line based on the index
* @param {Number} selectionStart Index of a character
* @return {fabric.IText} thisArg
* @chainable
*/
selectLine: function(selectionStart) {
selectionStart = selectionStart || this.selectionStart;
@ -313,6 +318,7 @@
this.selectionEnd = newSelectionEnd;
this._fireSelectionChanged();
this._updateTextarea();
return this;
},
/**

View file

@ -243,6 +243,8 @@
iText.selectAll();
equal(iText.selectionStart, 0);
equal(iText.selectionEnd, 4);
equal(iText.selectAll(), iText, 'should be chainable');
});
test('getSelectedText', function() {
@ -506,6 +508,8 @@
iText.selectLine(18);
equal(iText.selectionStart, 17); // |qux|
equal(iText.selectionEnd, 20);
equal(iText.selectLine(0), iText, 'should be chainable');
});
test('findWordBoundaryLeft', function() {