/// <summary> /// Handle the Comment Selection and Uncomment Selection editor commands. These commands comment/uncomment /// the currently selected lines. /// </summary> /// <param name="editorContext">The editor context</param> /// <param name="action">The requested command is Comment Selection, otherwise Uncomment Selection</param> /// <returns>True if the operation succeeds to comment/uncomment the selected lines, false otherwise</returns> public bool CommentOrUncommentSelection(GherkinEditorContext editorContext, CommentUncommentAction action) { var selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine(); var selectionEndLine = GetSelectionEndLine(selectionStartLine, editorContext.TextView); switch (action) { case CommentUncommentAction.Comment: CommentSelection(selectionStartLine, selectionEndLine); break; case CommentUncommentAction.Uncomment: UncommentSelection(selectionStartLine, selectionEndLine); break; case CommentUncommentAction.Toggle: if (IsCommented(selectionStartLine)) UncommentSelection(selectionStartLine, selectionEndLine); else CommentSelection(selectionStartLine, selectionEndLine); break; } // Select the entirety of the lines that were just commented or uncommented, have to update start/end lines due to snapshot changes selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine(); selectionEndLine = GetSelectionEndLine(selectionStartLine, editorContext.TextView); editorContext.TextView.Selection.Select(new SnapshotSpan(selectionStartLine.Start, selectionEndLine.End), false); return true; }
/// <summary> /// Handle the Comment Selection and Uncomment Selection editor commands. These commands comment/uncomment /// the currently selected lines. /// </summary> /// <param name="editorContext">The editor context</param> /// <param name="action">The requested command is Comment Selection, otherwise Uncomment Selection</param> /// <returns>True if the operation succeeds to comment/uncomment the selected lines, false otherwise</returns> public bool CommentOrUncommentSelection(GherkinEditorContext editorContext, CommentUncommentAction action) { var selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine(); var selectionEndLine = GetSelectionEndLine(selectionStartLine, editorContext.TextView); switch (action) { case CommentUncommentAction.Comment: CommentSelection(selectionStartLine, selectionEndLine); break; case CommentUncommentAction.Uncomment: UncommentSelection(selectionStartLine, selectionEndLine); break; case CommentUncommentAction.Toggle: if (IsCommented(selectionStartLine)) { UncommentSelection(selectionStartLine, selectionEndLine); } else { CommentSelection(selectionStartLine, selectionEndLine); } break; } // Select the entirety of the lines that were just commented or uncommented, have to update start/end lines due to snapshot changes selectionStartLine = editorContext.TextView.Selection.Start.Position.GetContainingLine(); selectionEndLine = GetSelectionEndLine(selectionStartLine, editorContext.TextView); editorContext.TextView.Selection.Select(new SnapshotSpan(selectionStartLine.Start, selectionEndLine.End), false); return(true); }