Ejemplo n.º 1
0
        /// <summary>
        /// Check and see if we should start an external edit operation
        /// </summary>
        private void CheckForExternalEditStart(CheckKind kind)
        {
            Contract.Assert(_buffer.ModeKind != ModeKind.ExternalEdit);

            var externalEditSpans = GetExternalEditSpans(kind);

            // If at some point all of the external edit spans dissapear then we 
            // don't need to track them anymore.  Very important to clear the cache 
            // here as the user could fire up an external edit at the exact same location
            // and we want that to register as an external edit
            if (externalEditSpans.Count == 0)
            {
                _ignoredExternalEditSpans.Clear();
                return;
            }

            // If we should ignore all of the spans then we've not entered an external 
            // edit
            if (externalEditSpans.All(ShouldIgnore))
            {
                return;
            }

            // Clear out the ignored markers.  Everything is fair game again when we restart
            // the external edit
            _ignoredExternalEditSpans.Clear();

            // Not in an external edit and there are edit markers we need to consider.  Time to enter
            // external edit mode
            _buffer.SwitchMode(ModeKind.ExternalEdit, ModeArgument.None);
        }
Ejemplo n.º 2
0
        private void CheckForExternalEdit()
        {
            // Only check for an external edit if there are visible lines.  In the middle of a nested layout
            // the set of visible lines will temporarily be unavalaible
            var range = _buffer.TextView.GetVisibleLineRange();

            if (range.IsError)
            {
                return;
            }

            var markers = GetExternalEditSpans(range.Value.ExtentIncludingLineBreak);

            MoveIgnoredMarkersToCurrentSnapshot();
            if (markers.All(ShouldIgnore))
            {
                if (markers.Count == 0)
                {
                    ClearIgnoreMarkers();

                    // If we're in an external edit and all of the markers leave then transition back to
                    // insert mode
                    if (_buffer.ModeKind == ModeKind.ExternalEdit)
                    {
                        _buffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
                    }
                }
            }
            else if (_buffer.ModeKind != ModeKind.ExternalEdit)
            {
                // Not in an external edit and there are edit markers we need to consider.  Time to enter
                // external edit mode
                _buffer.SwitchMode(ModeKind.ExternalEdit, ModeArgument.None);
            }
        }
Ejemplo n.º 3
0
 public void SwitchWhenDisabled()
 {
     _vimBuffer1.Process(GlobalSettings.DisableAllCommand);
     _vimBuffer1.SwitchMode(ModeKind.Normal, ModeArgument.None);
     Assert.True(Vim.IsDisabled);
     Assert.Equal(ModeKind.Disabled, _vimBuffer2.ModeKind);
 }
Ejemplo n.º 4
0
 public void TypeForwardShouldReplace()
 {
     Create("hello world");
     _buffer.SwitchMode(ModeKind.Replace, ModeArgument.None);
     _buffer.Process("again");
     Assert.AreEqual("again world", _textView.GetLine(0).GetText());
     Assert.AreEqual(5, _textView.GetCaretPoint().Position);
 }
Ejemplo n.º 5
0
 public void Timeout_Single()
 {
     _vimBuffer.Vim.GlobalKeyMap.AddKeyMapping("cat", "chase the cat", allowRemap: false, KeyRemapMode.Insert);
     _vimBuffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
     _vimBuffer.Process('c');
     Assert.Equal("", _vimBuffer.TextBuffer.GetLine(0).GetText());
     WaitForTimer();
     Assert.Equal("c", _vimBuffer.TextBuffer.GetLine(0).GetText());
 }
Ejemplo n.º 6
0
        public void Changed_RaiseOnSwitchMode()
        {
            Create();
            var didRaise = false;

            _taggerSource.Changed += delegate { didRaise = true; };
            _vimBuffer.SwitchMode(ModeKind.VisualBlock, ModeArgument.None);
            Assert.True(didRaise);
        }
Ejemplo n.º 7
0
 public void Timeout_Single()
 {
     _vimBuffer.Vim.KeyMap.MapWithNoRemap("cat", "chase the cat", KeyRemapMode.Insert);
     _vimBuffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
     _vimBuffer.Process('c');
     Assert.Equal("", _vimBuffer.TextBuffer.GetLine(0).GetText());
     WaitForTimer();
     Assert.Equal("c", _vimBuffer.TextBuffer.GetLine(0).GetText());
 }
Ejemplo n.º 8
0
        public void SwitchModeShouldRaiseTagsChanged()
        {
            Create();
            var didRaise = false;

            _tagger.TagsChanged += delegate { didRaise = true; };
            _buffer.SwitchMode(ModeKind.VisualBlock, ModeArgument.None);
            Assert.IsTrue(didRaise);
        }
Ejemplo n.º 9
0
 public void QueryStatus_IgnoreEscapeIfCantProcess()
 {
     _buffer.SwitchMode(ModeKind.Disabled, ModeArgument.None);
     Assert.IsFalse(_buffer.CanProcess(KeyInputUtil.EscapeKey));
     _nextTarget.SetupQueryStatus().Verifiable();
     RunQueryStatus(KeyInputUtil.EscapeKey);
     _factory.Verify();
 }
Ejemplo n.º 10
0
 private void Create(params string[] lines)
 {
     _textView = EditorUtil.CreateView(lines);
     _buffer   = EditorUtil.FactoryService.Vim.CreateBuffer(_textView);
     _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     ((MockVimHost)_buffer.Vim.VimHost).FocusedTextView = _textView;
 }
Ejemplo n.º 11
0
        private void CheckForExternalEdit()
        {
            if (_buffer.ModeKind == ModeKind.ExternalEdit)
            {
                return;
            }

            var range = _buffer.TextView.GetVisibleLineRange();

            if (range.IsError)
            {
                return;
            }

            var markers = GetExternalEditMarkers(range.Value.ExtentIncludingLineBreak);

            MoveIgnoredMarkersToCurrentSnapshot();
            if (markers.All(x => ShouldIgnore(x)))
            {
                if (markers.Count == 0)
                {
                    ClearIgnoreMarkers();
                }
                return;
            }

            // Not in an external edit and there are edit markers we need to consider.  Time to enter
            // external edit mode
            _buffer.SwitchMode(ModeKind.ExternalEdit, ModeArgument.None);
            _inExternalEdit = true;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Check and see if we should start an external edit operation
        /// </summary>
        private void CheckForExternalEditStart(CheckKind kind)
        {
            Contract.Assert(_vimBuffer.ModeKind != ModeKind.ExternalEdit);

            if (IsExternalEditStart(kind))
            {
                // Clear out the ignored markers.  Everything is fair game again when we restart
                // the external edit
                _ignoredExternalEditSpans.Clear();

                // Not in an external edit and there are edit markers we need to consider.  Time to enter
                // external edit mode
                _controlExternalEdit = true;
                _vimBuffer.SwitchMode(ModeKind.ExternalEdit, ModeArgument.None);
            }
        }
Ejemplo n.º 13
0
 public void CreateBuffer(params string[] lines)
 {
     var tuple = EditorUtil.CreateViewAndOperations(lines);
     _textView = tuple.Item1;
     var service = EditorUtil.FactoryService;
     _buffer = service.vim.CreateBuffer(_textView);
     _buffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
 }
Ejemplo n.º 14
0
 protected void Create(params string[] lines)
 {
     _textView  = CreateTextView(lines);
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     _globalSettings         = _vimBuffer.LocalSettings.GlobalSettings;
     VimHost.FocusedTextView = _textView;
 }
Ejemplo n.º 15
0
 protected void Create(params string[] lines)
 {
     _textView = CreateTextView(lines);
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     _globalSettings = _vimBuffer.LocalSettings.GlobalSettings;
     VimHost.FocusedTextView = _textView;
 }
Ejemplo n.º 16
0
 public void Setup()
 {
     _textView = CreateTextView("here we go");
     _textView.MoveCaretTo(0);
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Command, ModeArgument.None);
     _keyMap       = _vimBuffer.Vim.KeyMap;
     _vimBufferRaw = (VimBuffer)_vimBuffer;
     _factory      = new MockRepository(MockBehavior.Strict);
 }
Ejemplo n.º 17
0
 protected void Create(ModeArgument argument, params string[] lines)
 {
     _textView = CreateTextView(lines);
     _textBuffer = _textView.TextBuffer;
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Insert, argument);
     _register = Vim.RegisterMap.GetRegister('c');
     _globalSettings = Vim.GlobalSettings;
     _localSettings = _vimBuffer.LocalSettings;
 }
Ejemplo n.º 18
0
 public VimBufferTest()
 {
     _textView = CreateTextView("here we go");
     _textView.MoveCaretTo(0);
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Command, ModeArgument.None);
     _keyMap = _vimBuffer.Vim.KeyMap;
     _vimBufferRaw = (VimBuffer)_vimBuffer;
     _factory = new MockRepository(MockBehavior.Strict);
 }
Ejemplo n.º 19
0
 protected void Create(ModeArgument argument, params string[] lines)
 {
     _textView   = CreateTextView(lines);
     _textBuffer = _textView.TextBuffer;
     _vimBuffer  = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Insert, argument);
     _register       = Vim.RegisterMap.GetRegister('c');
     _globalSettings = Vim.GlobalSettings;
     _localSettings  = _vimBuffer.LocalSettings;
 }
Ejemplo n.º 20
0
 public void Create(params string[] lines)
 {
     _context = new TestableSynchronizationContext();
     SynchronizationContext.SetSynchronizationContext(_context);
     var tuple = EditorUtil.CreateViewAndOperations(lines);
     _textView = tuple.Item1;
     var service = EditorUtil.FactoryService;
     _buffer = service.Vim.CreateBuffer(_textView);
     _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     Assert.IsTrue(_context.IsEmpty);
 }
Ejemplo n.º 21
0
 public void Repeat_NoChange_DontLinkWithNormalCommand()
 {
     Create("cat dog");
     _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     _textView.MoveCaretTo(0);
     _vimBuffer.Process("dwi");
     _vimBuffer.Process(VimKey.Escape);
     Assert.AreEqual("dog", _textView.GetLine(0).GetText());
     _textView.MoveCaretTo(1);
     _vimBuffer.Process('.');
     Assert.AreEqual(0, _textView.GetCaretPoint().Position);
 }
Ejemplo n.º 22
0
        public void Create(params string[] lines)
        {
            _context = new TestableSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(_context);
            var tuple = EditorUtil.CreateViewAndOperations(lines);

            _textView = tuple.Item1;
            var service = EditorUtil.FactoryService;

            _buffer = service.Vim.CreateBuffer(_textView);
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            Assert.IsTrue(_context.IsEmpty);
        }
Ejemplo n.º 23
0
 public void Insert_SanityCheck()
 {
     Create("hello world");
     _textView.MoveCaretTo(0);
     _vimBuffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
     _simulation.Run('x');
     Assert.Equal("xhello world", _textView.GetLine(0).GetText());
 }
Ejemplo n.º 24
0
        public void SwitchMode_NoActionOutsideExternalEdit()
        {
            Create("cat", "tree", "dog");
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);

            CreateTags(_textBuffer.GetLine(0).Extent);
            _adapter.Setup(x => x.IsExternalEditTag(It.IsAny <ITag>())).Returns(true);
            Assert.Equal(1, _monitor.GetExternalEditSpans(ExternalEditMonitor.CheckKind.Tags).Count);

            _buffer.SwitchMode(ModeKind.Command, ModeArgument.None);
            Assert.Equal(0, _monitor.IgnoredExternalEditSpans.Count());
        }
Ejemplo n.º 25
0
        private void Create(ModeArgument argument, params string[] lines)
        {
            var tuple = EditorUtil.CreateTextViewAndEditorOperations(lines);

            _textView   = tuple.Item1;
            _textBuffer = _textView.TextBuffer;
            var service = EditorUtil.FactoryService;

            _vimBuffer = service.Vim.CreateVimBuffer(_textView);
            _vimBuffer.SwitchMode(ModeKind.Insert, argument);
            _register       = Vim.RegisterMap.GetRegister('c');
            _globalSettings = Vim.GlobalSettings;
            _localSettings  = _vimBuffer.LocalSettings;
        }
Ejemplo n.º 26
0
        public void Record_CustomProcess()
        {
            Create("");
            _vimBuffer.Process("qc");
            _vimBuffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
            _vimBuffer.Process("ab");
            _vimBuffer.InsertMode.CustomProcess(KeyInputUtil.CharToKeyInput('c'), () => true);
            _vimBuffer.Process(VimKey.Escape);
            _vimBuffer.Process("q");

            // Tricky comparing the values since it embeds an <Esc> into the string.  Just
            // compare the printable items and assert the length is correct
            Assert.AreEqual("abc", TestRegister.StringValue.Substring(0, 3));
            Assert.AreEqual(4, TestRegister.StringValue.Length);
        }
Ejemplo n.º 27
0
        public void Create(params string[] lines)
        {
            _context = new TestableSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(_context);
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vimBuffer = Vim.CreateVimBuffer(_textView);
            _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _vimTextBuffer = _vimBuffer.VimTextBuffer;
            _registerMap = _vimBuffer.RegisterMap;
            _globalSettings = _vimBuffer.LocalSettings.GlobalSettings;
            Assert.IsTrue(_context.IsEmpty);

            // Need to make sure it's focused so macro recording will work
            ((MockVimHost)_vimBuffer.Vim.VimHost).FocusedTextView = _textView;
        }
Ejemplo n.º 28
0
        public void Create(params string[] lines)
        {
            _context = new TestableSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(_context);
            var tuple = EditorUtil.CreateTextViewAndEditorOperations(lines);

            _textView   = tuple.Item1;
            _textBuffer = _textView.TextBuffer;
            var service = EditorUtil.FactoryService;

            _buffer = service.Vim.CreateVimBuffer(_textView);
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _vimTextBuffer  = _buffer.VimTextBuffer;
            _registerMap    = _buffer.RegisterMap;
            _globalSettings = _buffer.LocalSettings.GlobalSettings;
            Assert.IsTrue(_context.IsEmpty);

            // Need to make sure it's focused so macro recording will work
            ((MockVimHost)_buffer.Vim.VimHost).FocusedTextView = _textView;
        }
Ejemplo n.º 29
0
 private void Create(params string[] lines)
 {
     _textView = EditorUtil.CreateTextView(lines);
     _buffer = EditorUtil.FactoryService.Vim.CreateBuffer(_textView);
     _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     _globalSettings = _buffer.LocalSettings.GlobalSettings;
     ((MockVimHost)_buffer.Vim.VimHost).FocusedTextView = _textView;
 }
Ejemplo n.º 30
0
 public void CloseInInsertMode()
 {
     Create("foo", "bar");
     _buffer.SwitchMode(ModeKind.Insert, ModeArgument.None);
     _textView.Close();
 }
Ejemplo n.º 31
0
        public void Create(params string[] lines)
        {
            _context = new TestableSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(_context);
            var tuple = EditorUtil.CreateTextViewAndEditorOperations(lines);
            _textView = tuple.Item1;
            _textBuffer = _textView.TextBuffer;
            var service = EditorUtil.FactoryService;
            _buffer = service.Vim.CreateVimBuffer(_textView);
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _vimTextBuffer = _buffer.VimTextBuffer;
            _registerMap = _buffer.RegisterMap;
            _globalSettings = _buffer.LocalSettings.GlobalSettings;
            Assert.IsTrue(_context.IsEmpty);

            // Need to make sure it's focused so macro recording will work
            ((MockVimHost)_buffer.Vim.VimHost).FocusedTextView = _textView;
        }
Ejemplo n.º 32
0
        public void SwitchedMode_Event()
        {
            var ran = false;

            _vimBuffer.SwitchedMode += (s, m) => { ran = true; };
            _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            Assert.IsTrue(ran);
        }
Ejemplo n.º 33
0
 public void Setup()
 {
     _textView = EditorUtil.CreateView("here we go");
     _textView.MoveCaretTo(0);
     _buffer = EditorUtil.FactoryService.Vim.CreateBuffer(_textView);
     _buffer.SwitchMode(ModeKind.Command, ModeArgument.None);
     _keyMap = _buffer.Vim.KeyMap;
     _bufferRaw = (VimBuffer)_buffer;
     _factory = new MockRepository(MockBehavior.Strict);
 }
Ejemplo n.º 34
0
 private void EnterMode(ModeKind kind, SnapshotSpan span, TextSelectionMode mode = TextSelectionMode.Stream)
 {
     EnterMode(span, mode);
     _buffer.SwitchMode(kind, ModeArgument.None);
 }
Ejemplo n.º 35
0
 private void Create(ModeArgument argument, params string[] lines)
 {
     var tuple = EditorUtil.CreateTextViewAndEditorOperations(lines);
     _textView = tuple.Item1;
     _textBuffer = _textView.TextBuffer;
     var service = EditorUtil.FactoryService;
     _vimBuffer = service.Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Insert, argument);
     _register = Vim.RegisterMap.GetRegister('c');
     _globalSettings = Vim.GlobalSettings;
     _localSettings = _vimBuffer.LocalSettings;
 }
Ejemplo n.º 36
0
 private void EnterMode(ModeKind kind, SnapshotSpan span)
 {
     EnterMode(span);
     _buffer.SwitchMode(kind, ModeArgument.None);
 }