Last active
May 28, 2019 03:35
-
-
Save KevinGutowski/9d6f5a0980393c12aca5243aae8947e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sketch = require('sketch') | |
var document = sketch.getSelectedDocument() | |
var text = document.selectedLayers.layers[0].sketchObject | |
let textView = text.editingDelegate().textView() | |
let selectedRange = textView.selectedRange() | |
let textStorage = textView.textStorage() | |
let settingsAttribute = getSettingsAttributeForKey_Value(kLowerCaseType, kLowerCaseSmallCapsSelector) | |
function getSettingsAttributeForKey_Value(key, value) { | |
let settingsAttribute = { | |
[NSFontFeatureSettingsAttribute]: [{ | |
[NSFontFeatureTypeIdentifierKey]: key, | |
[NSFontFeatureSelectorIdentifierKey]: value | |
}] | |
} | |
return settingsAttribute | |
} | |
let font = text.font() | |
let fontSize = font.pointSize() | |
let descriptor = font.fontDescriptor().fontDescriptorByAddingAttributes(settingsAttribute) | |
let newFont = NSFont.fontWithDescriptor_size(descriptor,fontSize) | |
let attrsDict = NSDictionary.dictionaryWithObject_forKey(newFont,NSFontAttributeName) | |
textStorage.addAttributes_range(attrsDict,selectedRange) | |
textView.didChangeText() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment