Text.layoutBox is set too slowly

When setting Text.layoutBox with the plugin API, XD tries to update the Inspector’s appearance each time. This is causing delays.

It can be avoided by emptying selection.items, but with commands.duplicate() and other operations that require selecting, we face this problem.

It would be appreciated if XD could stop the inspector from updating during the process, or automatically deselect and reselect to keep the speed fast.

Steps to Reproduce

Set Text.layoutBox with the item selected.

const startDate = new Date() ;

const { selection, Text } = require('scenegraph') ;
const commands = require('commands') ;

const srcTextFrame = selection.items[0] ;
for(let i = 0 ; i < 100 ; i++) {
  selection.items = [srcTextFrame] ;
  commands.duplicate() ;
  const currentTextFrame = selection.items[0] ;
  selection.items = [] ; // no effective
  currentTextFrame.text = i.toString() ;

  currentTextFrame.layoutBox = {
    type: Text.FIXED_HEIGHT, 
    width: 200, 
    height: 200
  } ;
}

console.log(new Date() - startDate) ; // 5212msec

Workaround

Set Text.layoutBox with the item deselected. Create the Text with new Text() instead of commands.duplicate().

const startDate = new Date() ;

const { selection, Text } = require('scenegraph') ;

const srcTextFrame = selection.items[0] ;
const { globalBounds: srcBounds, styleRanges } = srcTextFrame ;
selection.items = [] ;
for(let i = 0 ; i < 100 ; i++) {
  const currentTextFrame = new Text() ;
  currentTextFrame.text = i.toString() ;
  currentTextFrame.styleRanges = styleRanges ;
  const currentBounds = currentTextFrame.globalBounds ;
  currentTextFrame.moveInParentCoordinates(srcBounds.x - currentBounds.x, srcBounds.y - currentBounds.y) ;
  selection.insertionParent.addChild(currentTextFrame) ;

  currentTextFrame.layoutBox = {
    type: Text.FIXED_HEIGHT, 
    width: 200, 
    height: 200
  } ;
}

console.log(new Date() - startDate) ; // 97msec

Environment

• Adobe XD (51.0.12.6 arm64)
• macOS 11.6.5 (Apple Silicon)