Advertisement
kopyl

Untitled

Aug 18th, 2021
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const revertResize = (currentlySelectedLayers) => {
  3.     for (let x=0; x<currentlySelectedLayers.length; x++) {
  4.         let currentlySelectedLayerWidth = currentlySelectedLayers[x].width
  5.         let currentlySelectedLayerHeight = currentlySelectedLayers[x].height
  6.         currentlySelectedLayers[x].resize(currentlySelectedLayerWidth+1, currentlySelectedLayerHeight)
  7.     }
  8.    
  9. }
  10.  
  11. const collapseParentOf = (currentlySelectedLayer) => {
  12.     let parent = currentlySelectedLayer.parent
  13.     figma.currentPage.selection = [parent]
  14.     parent.expanded = false
  15. }
  16.  
  17. const collapseCurrentLayer = () => {
  18.     let currentlySelectedLayer = figma.currentPage.selection[0]
  19.     currentlySelectedLayer.expanded = false
  20. }
  21.  
  22. const selectFirstLayerInGroup = () => {
  23.     let nodeToSelect = figma.currentPage.selection[0].children.slice(-1)[0] // last
  24.     figma.currentPage.selection = [nodeToSelect]
  25.     nodeToSelect.expanded = false
  26. }
  27.  
  28. const resetTextBoundBox = async() => {
  29.     textLayer = figma.currentPage.selection[0]
  30.     await figma.loadFontAsync(textLayer.fontName)
  31.     textLayer.textAutoResize = "WIDTH_AND_HEIGHT"
  32. }
  33.  
  34. document.addEventListener('keydown', function(event) {
  35.   if (event.ctrlKey && event.key === 'ArrowLeft') {
  36.     let currentlySelectedLayers = figma.currentPage.selection
  37.     revertResize(currentlySelectedLayers)
  38.     collapseParentOf(currentlySelectedLayers[0])
  39.   }
  40. });
  41.  
  42. document.addEventListener('keydown', function(event) {
  43.   if (event.shiftKey && event.key === 'C') {
  44.     collapseCurrentLayer()
  45.   }
  46. });
  47.  
  48. document.addEventListener('keydown', function(event) {
  49.   if (event.ctrlKey && event.key === 'Enter') {
  50.     selectFirstLayerInGroup()
  51.   }
  52. });
  53.  
  54. document.addEventListener('keydown', function(event) {
  55.   if (event.shiftKey && event.key === 'T') {
  56.     resetTextBoundBox()
  57.   }
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement