Ejemplo n.º 1
0
        public void UndoTransactionWithCaretPrimitive()
        {
            var textBuffer   = CreateTextBuffer("");
            var textView     = TextEditorFactoryService.CreateTextView(textBuffer);
            var weakTextView = new WeakReference(textView);

            DoWork(
                () =>
            {
                var undoManager = TextBufferUndoManagerProvider.GetTextBufferUndoManager(textBuffer);
                using (var transaction = undoManager.TextBufferUndoHistory.CreateTransaction("Test Edit"))
                {
                    var operations = EditorOperationsFactoryService.GetEditorOperations(textView);
                    operations.AddBeforeTextBufferChangePrimitive();
                    textBuffer.SetText("hello world");
                    transaction.Complete();
                }
            });

            textView.Close();
            textView = null;

            // The AddBeforeTextBufferChangePrimitive put the ITextView into the undo stack
            // so we need to clear it out here
            ClearUndoHistory(textBuffer);

            RunGarbageCollector();
            Assert.Null(weakTextView.Target);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Make sure that on tear down we don't have a current transaction.  Having one indicates
        /// we didn't close it and hence are killing undo in the ITextBuffer
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();

            var history = TextBufferUndoManagerProvider.GetTextBufferUndoManager(_textView.TextBuffer).TextBufferUndoHistory;

            Assert.Null(history.CurrentTransaction);
        }
Ejemplo n.º 3
0
        public void UndoTransactionSimple()
        {
            var textBuffer   = CreateTextBuffer("");
            var textView     = TextEditorFactoryService.CreateTextView(textBuffer);
            var weakTextView = new WeakReference(textView);

            DoWork(
                () =>
            {
                var undoManager = TextBufferUndoManagerProvider.GetTextBufferUndoManager(textBuffer);
                using (var transaction = undoManager.TextBufferUndoHistory.CreateTransaction("Test Edit"))
                {
                    textBuffer.SetText("hello world");
                    transaction.Complete();
                }
            });

            textView.Close();
            textView = null;
            RunGarbageCollector();
            Assert.Null(weakTextView.Target);
        }