How to get current cursor position when editing fabric.Textbox

Viewed 181

How to get current cursor position on text in fabric.Textbox

for example, the following should return = 6

enter image description here

1 Answers

I sort of figured it out. selectionStart and selectionEnd did the trick:

var activeObj = canvas.getActiveObject();
var caretPositionStart = activeObj.selectionStart;
var caretPositionEnd = activeObj.selectionEnd;
activeObj.enterEditing();
activeObj.insertChars("HI", null, caretPositionStart, caretPositionEnd);

        
Related