Created
January 27, 2019 02:56
-
-
Save matt-curtis/c8380d4304d93bc8638801e473754050 to your computer and use it in GitHub Desktop.
Applying attributes to a text layer that's being edited in Sketch
This file contains hidden or 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
framework("CoreText"); | |
const DOM = require("sketch/dom"); | |
const textLayer = DOM.getSelectedDocument().pages[0].selectedLayers.layers[0]; | |
const textView = textLayer.sketchObject.editingDelegate().textView(); | |
// [NSTextView selectedRanges] returns an NSArray of NSValues: | |
const selectedRange = textView.selectedRanges()[0].rangeValue(); | |
const textStorage = textView.textStorage(); | |
textStorage.applyFontTraits_range(NSBoldFontMask, selectedRange); | |
textView.didChangeText(); // key for getting the NSTextView to redraw/update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment