{"size": 1459, "ext": "js", "max_stars_repo_path": "Sketch Mate.sketchplugin/Contents/Sketch/Misc/Set Line Height.js", "max_stars_repo_name": "Mario-Kart-Felix/Sketch-Mate", "max_stars_repo_stars_event_min_datetime": "2015-01-08T14:21:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-02T16:41:09.000Z", "max_issues_repo_path": "Sketch Mate.sketchplugin/Contents/Sketch/Misc/Set Line Height.js", "max_issues_repo_name": "Mario-Kart-Felix/Sketch-Mate", "max_issues_repo_issues_event_min_datetime": "2015-01-23T22:28:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-20T09:12:18.000Z", "max_forks_repo_path": "Sketch Mate.sketchplugin/Contents/Sketch/Misc/Set Line Height.js", "max_forks_repo_name": "Mario-Kart-Felix/Sketch-Mate", "max_forks_repo_forks_event_min_datetime": "2015-02-25T23:15:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-04T02:19:14.000Z"}
{"max_stars_count": 523, "max_issues_count": 62, "max_forks_count": 44, "avg_line_length": 25.5964912281, "max_line_length": 102, "alphanum_fraction": 0.6449623029}
var onRun = function (context) {
  var doc = context.document;
  var selection = context.selection;

  // Sets the line height as multiple of the font size (cmd l)

  var textLayers = [];

  if (selection.count() > 0) {

  	// Loop through selected layers
  	for (var i = 0; i < selection.count(); i++) {

  		var s = selection[i];

  		// Check if the layer is a text layer
  		if (s.className() == "MSTextLayer"){
  			textLayers.push(s);
  	  	}
  	}

  	if (textLayers.length > 0) {

  		// get first text layer
  		var firstTextLayer = textLayers[0];

  		// Calculate initial line height
  		var fontSize = firstTextLayer.fontSize();
  		var lineHeight = firstTextLayer.lineHeight();

      // Sketch returns 0 as a value when line height is set to "auto"
      if (!lineHeight) lineHeight = fontSize;

  		var multiple = (lineHeight / fontSize).toFixed(1);

  		// Show a dialog, asking for the line height multiple
  		var lineSpacing = parseFloat([doc askForUserInput:"Line Height Multiple:" initialValue:multiple]);

  		for (var j = 0; j < textLayers.length; j++) {

  			var textLayer = textLayers[j];

  			// Calculate the line height based on the font size and multiple
  			var fontSize = textLayer.fontSize();
  			var lineHeight = fontSize * lineSpacing;
  			textLayer.setLineHeight(lineHeight);
  		}

  	} else {
  		doc.showMessage("Please select a text layer.");
  	}
  } else {
  	doc.showMessage("Please select a text layer.")
  }

}
