src/index.js
function(selection, mainTemplate, suggestionsTemplate) {

  selection = defaults({}, selection, {
    isMisspelled: false,
    spellingSuggestions: []
  });

  var template = getTemplate(mainTemplate, DEFAULT_MAIN_TPL);
  var suggestionsTpl = getTemplate(suggestionsTemplate, DEFAULT_SUGGESTIONS_TPL);

  if (selection.isMisspelled) {
    var suggestions = selection.spellingSuggestions;
    if (isEmpty(suggestions)) {
      template.unshift.apply(template, suggestionsTpl);
    } else {
      template.unshift.apply(template, suggestions.map(function(suggestion) {
        return {
          label: suggestion,
          click: function() {
            BrowserWindow.getFocusedWindow().webContents.replaceMisspelling(suggestion);
          }
        };
      }).concat({
        type: 'separator'
      }));
    }
  }

  return Menu.buildFromTemplate(template);
}
function(selection, mainTemplate, suggestionsTemplate) {

  selection = defaults({}, selection, {
    isMisspelled: false,
    spellingSuggestions: []
  });

  var template = getTemplate(mainTemplate, DEFAULT_MAIN_TPL);
  var suggestionsTpl = getTemplate(suggestionsTemplate, DEFAULT_SUGGESTIONS_TPL);

  if (selection.isMisspelled) {
    var suggestions = selection.spellingSuggestions;
    if (isEmpty(suggestions)) {
      template.unshift.apply(template, suggestionsTpl);
    } else {
      template.unshift.apply(template, suggestions.map(function(suggestion) {
        return {
          label: suggestion,
          click: function() {
            BrowserWindow.getFocusedWindow().webContents.replaceMisspelling(suggestion);
          }
        };
      }).concat({
        type: 'separator'
      }));
    }
  }

  return Menu.buildFromTemplate(template);
}
function ( selection , mainTemplate , suggestionsTemplate ) { selection = defaults ( { } , selection , { isMisspelled : false , spellingSuggestions : [ ] } ) ; var template = getTemplate ( mainTemplate , DEFAULT_MAIN_TPL ) ; var suggestionsTpl = getTemplate ( suggestionsTemplate , DEFAULT_SUGGESTIONS_TPL ) ; if ( selection . isMisspelled ) { var suggestions = selection . spellingSuggestions ; if ( isEmpty ( suggestions ) ) { template . unshift . apply ( template , suggestionsTpl ) ; } else { template . unshift . apply ( template , suggestions . map ( function ( suggestion ) { return { label : suggestion , click : function ( ) { BrowserWindow . getFocusedWindow ( ) . webContents . replaceMisspelling ( suggestion ) ; } } ; } ) . concat ( { type : 'separator' } ) ) ; } } return Menu . buildFromTemplate ( template ) ; }
Builds a context menu suitable for showing in a text editor.

@param {Object=} selection - An object describing the current text selection.
@property {Boolean=false} isMisspelled - `true` if the selection is
misspelled, `false` if it is spelled correctly or is not text.
@property {Array<String>=[]} spellingSuggestions - An array of suggestions
to show to correct the misspelling. Ignored if `isMisspelled` is `false`.
@param {Function|Array} mainTemplate - Optional. If it's an array, use as is.
If it's a function, used to customize the template of always-present menu items.
Receives the default template as a parameter. Should return a template.
@param {Function|Array} suggestionsTemplate - Optional. If it's an array, use as is.
If it's a function, used to customize the template of spelling suggestion items.
Receives the default suggestions template as a parameter. Should return a template.
@return {Menu}
Builds a context menu suitable for showing in a text editor .