Skip to content

Instantly share code, notes, and snippets.

@matt-curtis
Created January 27, 2019 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-curtis/c8380d4304d93bc8638801e473754050 to your computer and use it in GitHub Desktop.
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
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