import { data } from "../commands/editor/main" ; import { on } from "../utils/events" ; import { writeToNode } from "../utils/textNode" ; const editorTextChangeListener = ( ) => on ( "EDITOR_TEXT_CHANGE" , async ( { value , id } ) => { let characters = value ; let selectedTextNodes = data . getData ( ) . selectedTextNodes . filter ( node => ! id || node . id === id ) ; let selectedTextsForBatchEdit = data . getData ( ) . selectedTextsForBatchEdit ; let calculatedData ; if ( data . getData ( ) . activeTab === "batch-editor" && ! id && selectedTextsForBatchEdit ) { selectedTextNodes = selectedTextsForBatchEdit ; } for ( const nodeData of selectedTextNodes ) { let node = figma . getNodeById ( nodeData . id ) as TextNode ; if ( node . textAutoResize === "WIDTH_AND_HEIGHT" ) { if ( calculatedData ) { await writeToNode ( { node , characters : calculatedData } ) ; } else { calculatedData = await writeToNode ( { node , characters : characters } ) ; } } else { await writeToNode ( { node , characters : characters } ) ; } } } ) ; export default editorTextChangeListener ;