3

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

for example, the following should return = 6

enter image description here

jquery404
  • 653
  • 1
  • 12
  • 26
  • Does this answer your question? [Get cursor position (in characters) within a text Input field](https://stackoverflow.com/questions/2897155/get-cursor-position-in-characters-within-a-text-input-field) – jacobkim Aug 20 '21 at 02:46
  • its does logicwise, but i'm more keen on any existing fabricjs solution on this – jquery404 Aug 20 '21 at 02:58

1 Answers1

0

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);

        
jquery404
  • 653
  • 1
  • 12
  • 26