Select text of IText on FabricJS

1k views Asked by At

I want set the text selection by code in FabricJS like the image. When I create the IText object I need to select all text to facilitate the editing.

I check the documentation, but no success.

enter image description here

1

There are 1 answers

3
Oro On BEST ANSWER

I've found it in documentation. And prepared use example for you

import "./styles.css";
import { fabric } from "fabric";

const canvas = new fabric.Canvas("c", { width: 600, height: 600 });

const iText = new fabric.IText("Hello world!");

canvas.setActiveObject(iText);
iText.enterEditing();
iText.selectAll();
canvas.add(iText);

https://codesandbox.io/s/fabricjs-playground-forked-jl0ui?file=/src/index.js