Applying attributes to a text layer that's being edited in Sketch
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
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