Exemplo n.º 1
0
        /// <summary>
        /// Uncomment the currently selected spans.
        /// </summary>
        /// <remarks>
        /// The base implementation calls <see cref="ICommenter.UncommentSpans"/> to perform
        /// the uncommenting operation and update the currently selected spans. It then
        /// updates the selection in the editor to match the result of the operation.
        /// </remarks>
        protected virtual void UncommentSelection()
        {
            var undoHistory = TextUndoHistoryRegistry.RegisterHistory(TextView.TextBuffer);

            using (var transaction = undoHistory.CreateTransaction("Uncomment Selection"))
            {
                EditorOperations.AddBeforeTextBufferChangePrimitive();

                bool reversed     = TextView.Selection.IsReversed;
                var  newSelection = Commenter.UncommentSpans(TextView.Selection.VirtualSelectedSpans);
                // TODO: detect rectangle selection if present
                if (newSelection.Count > 0)
                {
                    VirtualSnapshotPoint anchorPoint = reversed ? newSelection[0].End : newSelection[0].Start;
                    VirtualSnapshotPoint activePoint = reversed ? newSelection[0].Start : newSelection[0].End;
                    TextView.Selection.Select(anchorPoint, activePoint);
                }

                EditorOperations.AddAfterTextBufferChangePrimitive();
                transaction.Complete();
            }
        }
Exemplo n.º 2
0
 public void AddBeforeTextBufferChangePrimitive() => EditorOperations.AddBeforeTextBufferChangePrimitive();