Eugene Vilder
Eugene Vilder

Reputation: 562

How to select text in 2nd line of Textbox element by using FabricJS?

I'm wondering if there is a way to select part of a text in Textbox element of FabricJS? Currently, I'm using

text.selectionStart = 0;
text.selectionEnd = 4;

but it selects text in the first line (makes sense why).

How to let fabric know that I need to select those from the second line?

Tnx

http://jsfiddle.net/redlive/4n4cLyvo/

Upvotes: 0

Views: 262

Answers (1)

user700284
user700284

Reputation: 13620

You can use the insertCharStyleObject method available in fabric.

Code snippet :

var selectionStart = 0;
var selectionEnd = 4;
var lineIndex = 1;

for (var i = selectionStart; i < selectionEnd; i++) {
  text.insertCharStyleObject(lineIndex, i, {
    textBackgroundColor: '#0F0'
  })
}

Updated fiddle - http://jsfiddle.net/4n4cLyvo/2/

Upvotes: 1

Related Questions