/// <summary> /// Gets the editor actions associated with the given TextSpan. /// </summary> /// <param name="block">The block.</param> /// <param name="textSpan">The text span.</param> /// <returns> /// A list of editor actions associated with this span. /// </returns> /// <remarks> /// This will be called within a read-only lock. /// </remarks> public IList<IEditorAction> GetEditorActions( Block block, TextSpan textSpan) { // We only get to this point if we have a misspelled word. string word = textSpan.GetText(block.Text); // Get the suggestions for the word. IList<SpellingSuggestion> suggestions = GetSuggestions(word); // Go through the suggestions and create an editor action for each one. // These will already be ordered coming out of the GetSuggestions() // method. BlockCommandSupervisor commands = block.Project.Commands; var actions = new List<IEditorAction>(suggestions.Count); foreach (SpellingSuggestion suggestion in suggestions) { // Figure out the operation we'll be using to implement the change. var command = new ReplaceTextCommand( new BlockPosition(block.BlockKey, textSpan.StartTextIndex), textSpan.Length, suggestion.Suggestion); // Create the suggestion action, along with the replacement command. var action = new EditorAction( string.Format("Change to \"{0}\"", suggestion.Suggestion), new HierarchicalPath("/Plugins/Spelling/Change"), context => commands.Do(command, context)); actions.Add(action); } // Add the additional editor actions from the plugins. foreach (ISpellingProjectPlugin controller in SpellingControllers) { IEnumerable<IEditorAction> additionalActions = controller.GetAdditionalEditorActions(word); actions.AddRange(additionalActions); } // Return all the change actions. return actions; }
public IEnumerable<IEditorAction> GetAdditionalEditorActions(string word) { // We have two additional editor actions. var addSensitiveAction = new EditorAction( "Add case-sensitive local words", new HierarchicalPath("/Plugins/Local Words/Add to Sensitive"), context => AddToSensitiveList(context, word)); var addInsensitiveAction = new EditorAction( "Add case-insensitive local words", new HierarchicalPath("/Plugins/Local Words/Add to Insensitive"), context => AddToInsensitiveList(context, word)); // Return the resutling list. var results = new IEditorAction[] { addSensitiveAction, addInsensitiveAction }; return results; }