Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Applying attributes to a text layer that's being edited in Sketch
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