Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2019 02:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Applying attributes to a text layer that's being edited in Sketch
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