示例#1
0
            public void SetText(SourceText sourceText)
            {
                if (sourceText == null)
                {
                    throw new ArgumentNullException(nameof(sourceText));
                }

                var e = new TextChangeEventArgs(_currentText, sourceText);

                _currentText = sourceText;

                TextChanged?.Invoke(this, e);
            }
示例#2
0
        void HandleTextChanging(object sender, TextChangeEventArgs e)
        {
            foreach (var segment in originalProjections)
            {
                if (segment.Contains(e.Offset))
                {
                    var projectedOffset = e.Offset - segment.Offset + segment.LinkedTo.Offset;
                    projectedEditor.ReplaceText(projectedOffset, e.RemovalLength, e.InsertedText);
                }
            }

            originalProjections.UpdateOnTextReplace(sender, e);
        }
 void HandleInfoDocumentTextEditorDataDocumentTextReplaced(object sender, TextChangeEventArgs e)
 {
     foreach (var data in localUpdate.ToArray())
     {
         data.Document.TextChanged -= HandleDataDocumentTextReplaced;
         foreach (var change in e.TextChanges.Reverse())
         {
             data.Replace(change.Offset, change.RemovalLength, change.InsertedText.Text);
         }
         data.Document.TextChanged += HandleDataDocumentTextReplaced;
         data.Document.CommitUpdateAll();
     }
 }
示例#4
0
        void HandleDataDocumentTextReplaced(object sender, TextChangeEventArgs e)
        {
            var data = dict [(TextDocument)sender];

            localUpdate.Remove(data);
            var editor = info.Document.ParentDocument.Editor;

            foreach (var change in e.TextChanges.Reverse())
            {
                editor.ReplaceText(change.Offset, change.RemovalLength, change.InsertedText);
            }
            localUpdate.Add(data);
            UpdateDiff();
        }
        void HandleDataDocumentTextReplaced(object sender, TextChangeEventArgs e)
        {
            var data = dict [(TextDocument)sender];

            localUpdate.Remove(data);
            var editor = info.Document.GetContent <ITextBuffer> ();

            foreach (var change in e.TextChanges.Reverse())
            {
                editor.Replace(new Microsoft.VisualStudio.Text.Span(change.Offset, change.RemovalLength), change.InsertedText.Text);
            }
            localUpdate.Add(data);
            UpdateDiff();
        }
示例#6
0
 private void OnTextBufferChanged(object sender, TextChangeEventArgs e)
 {
     if (!_changed && _tree.AstRoot != null)
     {
         var c = e.Change;
         if (c.OldText.IndexOf('-', 0) >= 0 || c.NewText.IndexOf('-', 0) >= 0)
         {
             if (_tree.AstRoot.Comments.GetItemContaining(c.Start) >= 0)
             {
                 _changed = true;
             }
         }
     }
 }
示例#7
0
        private void FireChanged(int start, int oldLength, int newLength)
        {
            var oldTextProvider = new TextStream(CurrentSnapshot.GetText());

            _version++;
            _currentSnapshot = new EditorBufferSnapshot(this, _content.ToString(), _version);

            var newTextProvider = new TextStream(_currentSnapshot.GetText());
            var change          = new TextChange(start, oldLength, newLength, oldTextProvider, newTextProvider);
            var args            = new TextChangeEventArgs(change);

            ChangedHighPriority?.Invoke(this, args);
            Changed?.Invoke(this, args);
        }
示例#8
0
 public void TextReplaced(object sender, TextChangeEventArgs args)
 {
     foreach (var change in args.TextChanges)
     {
         if (change.RemovalLength > 0)
         {
             TextRemove(change.Offset, change.RemovalLength);
         }
         if (change.InsertionLength > 0)
         {
             TextInsert(change.Offset, change.InsertedText.Text);
         }
     }
 }
        public static IEnumerable <TextDocumentContentChangeEvent> CreateTextDocumentContentChangeEvents(
            this TextChangeEventArgs e,
            TextEditor editor,
            bool fullContent)
        {
            if (fullContent)
            {
                return(CreateFullTextDocumentContentChangeEvents(editor));
            }

            return(e.TextChanges.Select(textChange => {
                return CreateIncrementalTextDocumentContentChangeEvent(textChange, editor);
            }));
        }
示例#10
0
 public void TextReplaced(object sender, TextChangeEventArgs args)
 {
     for (int i = 0; i < args.TextChanges.Count; ++i)
     {
         var change = args.TextChanges[i];
         if (change.RemovalLength > 0)
         {
             TextRemove(change.Offset, change.RemovalLength);
         }
         if (change.InsertionLength > 0)
         {
             TextInsert(change.Offset, change.InsertedText.Text);
         }
     }
 }
示例#11
0
        void onImlSourceChanged(Object sender, TextChangeEventArgs e)
        {
            Instantiator i;

            try {
                i = Instantiator.CreateFromImlFragment(e.Text);
            } catch (Exception ex) {
                Debug.WriteLine(ex);
                return;
            }
            lock (CrowInterface.UpdateMutex) {
                (CrowInterface.FindByName("crowContainer") as Container).SetChild
                    (i.CreateInstance(CrowInterface));
            }
        }
示例#12
0
        internal void UpdateCaretPosition(TextChangeEventArgs e)
        {
            //if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset) {
            //	offsetVersion = TextEditorData.Version;
            //	return;
            //}
            var curVersion = TextEditorData.Version;

            if (offsetVersion == null)
            {
                offsetVersion = curVersion;
                return;
            }
            var newOffset = offsetVersion.MoveOffsetTo(curVersion, caretOffset);

            offsetVersion = curVersion;
            if (newOffset == caretOffset || !AutoUpdatePosition)
            {
                return;
            }
            DocumentLocation old = Location;
            var newLocation      = TextEditorData.OffsetToLocation(newOffset);
            int newColumn        = newLocation.Column;

            var curLine = TextEditorData.GetLine(newLocation.Line);

            if (TextEditorData.HasIndentationTracker && TextEditorData.Options.IndentStyle == IndentStyle.Virtual && curLine.Length == 0)
            {
                var indentColumn = TextEditorData.GetVirtualIndentationColumn(newLocation);
                if (column == indentColumn)
                {
                    newColumn = indentColumn;
                }
            }
            if (AllowCaretBehindLineEnd)
            {
                if (curLine != null && column > curLine.Length)
                {
                    newColumn = column;
                }
            }
            line   = newLocation.Line;
            column = newColumn;

            SetDesiredColumn();
            UpdateCaretOffset();
            OnPositionChanged(new CaretLocationEventArgs(old, CaretChangeReason.BufferChange));
        }
        public void OverwriteCode(int start, int length, string newCode)
        {
            var changes = new List <(TextSpan span, string newText)>(1)
            {
                (new TextSpan(start, length), newCode)
            };

            var        allChanges = changes.Select(c => new TextChange(c.span, c.newText)).ToArray();
            SourceText newSource  = _source.WithChanges(allChanges);

            var textChangesEvent = new TextChangeEventArgs(_source, newSource, changes.Select(c => new TextChangeRange(c.span, c.newText.Length)).ToArray());

            TextChanged?.Invoke(this, textChangesEvent);

            _source = newSource;
        }
示例#14
0
        void UpdateLinksOnTextReplace(object sender, TextChangeEventArgs e)
        {
            wasReplaced = true;
            int offset = e.Offset - baseOffset;
            int delta  = e.ChangeDelta;

            if (!IsInUpdate && !links.Any(link => link.Links.Any(segment => segment.Contains(offset) ||
                                                                 segment.EndOffset == offset)))
            {
                SetCaretPosition = false;
                ExitTextLinkMode();
                return;
            }
            AdjustLinkOffsets(offset, delta);
            UpdateTextLinks();
        }
示例#15
0
        public void TestTextChanging()
        {
            var textDoc = CreateTextDocument("12345");
            TextChangeEventArgs changeArgs = null;

            textDoc.TextChanging += delegate(object sender, TextChangeEventArgs e) {
                changeArgs = e;
                Assert.AreEqual(textDoc.Text, "12345");
                var ca = changeArgs.TextChanges.First();
                Assert.AreEqual(ca.Offset, 2);
                Assert.AreEqual(ca.RemovalLength, 2);
                Assert.AreEqual(ca.RemovedText.Text, "34");
                Assert.AreEqual(ca.InsertionLength, "Hello".Length);
                Assert.AreEqual(ca.InsertedText.Text, "Hello");
            };
            textDoc.ReplaceText(2, 2, "Hello");
        }
		void Editor_TextChanged (object sender, TextChangeEventArgs e)
		{
			foreach (var change in e.TextChanges) {
				var startLine = Editor.GetLineByOffset (change.NewOffset);
				int startLineOffset = startLine.Offset;

				var segments = scannedSegmentTree.GetSegmentsOverlapping (change.NewOffset, change.RemovalLength).ToList ();
				foreach (var seg in segments) {
					foreach (var u in seg.UrlTextMarker) {
						Editor.RemoveMarker (u);
					}
					scannedSegmentTree.Remove (seg);
				}
			}

			scannedSegmentTree.UpdateOnTextReplace (sender, e);
		}
示例#17
0
文件: Showcase.cs 项目: slagusev/Crow
        void Tb_TextChanged(object sender, TextChangeEventArgs e)
        {
            GraphicObject g = null;

            try {
                lock (this.ifaceControl [0].CrowInterface.UpdateMutex) {
                    Instantiator inst = null;
                    using (MemoryStream ms = new MemoryStream(System.Text.Encoding.Unicode.GetBytes(e.Text))){
                        inst = new Instantiator(ms);
                    }
                    g = inst.CreateInstance(this.ifaceControl [0].CrowInterface);
                    crowContainer.SetChild(g);
                }
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            g.DataSource = this;
        }
示例#18
0
        /// <summary>
        /// Find first change in project structure. Determines which method is changed etc. .
        /// </summary>
        /// <param name="change">Additional info about change in source code text.</param>
        /// <param name="doc">Document, that was changed.</param>
        /// <returns>Instance of BodyChange, containing info about change in structure.</returns>
        private BodyChange findBodyChanges(TextChangeEventArgs change, IDocument doc)
        {
            IDocumentLine line = doc.GetLineForOffset(change.Offset);

            int row    = line.LineNumber;
            int column = change.Offset - line.Offset;

            bool       found  = false;
            BodyChange entity = null;

            foreach (IClass classEl in ParserService.CurrentProjectContent.Classes)
            {
                if (classEl is CompoundClass)
                {
                    CompoundClass compClass = classEl as CompoundClass;
                    foreach (IClass compPart in compClass.Parts)
                    {
                        if (compPart.BodyRegion.IsInside(row, column) && FileUtility.IsEqualFileName(classEl.CompilationUnit.FileName, changingFilename))
                        {
                            entity = findBodyChangesClass(compPart, row, column);
                            if (entity != null)
                            {
                                found = true;
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                if (classEl.BodyRegion.IsInside(row, column) && FileUtility.IsEqualFileName(classEl.CompilationUnit.FileName, changingFilename))
                {
                    entity = findBodyChangesClass(classEl, row, column);
                    if (entity != null)
                    {
                        found = true;
                        break;
                    }
                }
            }
            return(entity);
        }
示例#19
0
        public void TestTextChanged()
        {
            var textDoc = CreateTextDocument("12345");
            TextChangeEventArgs changeArgs = null;
            string text = null;

            textDoc.TextChanged += delegate(object sender, TextChangeEventArgs e) {
                changeArgs = e;
                text       = textDoc.Text;
            };
            textDoc.ReplaceText(2, 2, "Hello");
            Assert.AreEqual(textDoc.Text, "12Hello5");
            Assert.AreEqual(text, "12Hello5");
            Assert.AreEqual(changeArgs.Offset, 2);
            Assert.AreEqual(changeArgs.RemovalLength, 2);
            Assert.AreEqual(changeArgs.RemovedText.Text, "34");
            Assert.AreEqual(changeArgs.InsertionLength, "Hello".Length);
            Assert.AreEqual(changeArgs.InsertedText.Text, "Hello");
        }
            void Document_TextChanged(object sender, TextChangeEventArgs e)
            {
                int i = 0;

                foreach (var change in e.TextChanges)
                {
                    if (i >= lines.Count)
                    {
                        break;                         // should never happen
                    }
                    var oldHighlightedLine = lines [i++];
                    var curLine            = textEditor.GetLineByOffset(change.Offset);
                    var curLayout          = textEditor.TextViewMargin.GetLayout(curLine);
                    if (!UpdateLineHighlight(curLine.LineNumber, oldHighlightedLine, curLayout.HighlightedLine))
                    {
                        break;
                    }
                }
                lines.Clear();
            }
        public void InitializeOpenedInsightWindow_SingleCharacterAddedToDocumentAfterOpenParenthesis_InsightWindowIsNotClosed()
        {
            CreatePythonInsightWindowHandler();
            fakeTextEditor.FakeDocument.Text = "method(";
            fakeTextEditor.FakeCaret.Offset  = 7;
            fakeInsightWindow.StartOffset    = 7;
            InitializePythonInsightWindowHandler();

            int newCaretOffset = 8;

            fakeTextEditor.FakeCaret.Offset  = newCaretOffset;
            fakeTextEditor.FakeDocument.Text = "method(a";
            TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, "a");

            fakeInsightWindow.FireDocumentChangedEvent(e);

            bool closed = fakeInsightWindow.IsClosed;

            Assert.IsFalse(closed);
        }
        public void InitializeOpenedInsightWindow_CharacterAddedToDocumentBeforeStartOfInsightWindow_InsightWindowClosed()
        {
            CreatePythonInsightWindowHandler();
            fakeTextEditor.FakeDocument.Text = "method(";
            fakeTextEditor.FakeCaret.Offset  = 7;
            fakeInsightWindow.StartOffset    = 7;
            InitializePythonInsightWindowHandler();

            int newCaretOffset = 1;

            fakeTextEditor.FakeCaret.Offset  = newCaretOffset;
            fakeTextEditor.FakeDocument.Text = "aethod(";
            TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, "a");

            fakeInsightWindow.FireDocumentChangedEvent(e);

            bool closed = fakeInsightWindow.IsClosed;

            Assert.IsTrue(closed);
        }
        public void InitializeOpenedInsightWindow_MethodCallInsideMethodCallAndCloseParenthesisCharacterAddedToDocument_InsightWindowIsNotClosed()
        {
            CreatePythonInsightWindowHandler();
            fakeTextEditor.FakeDocument.Text = "method(a(";
            fakeTextEditor.FakeCaret.Offset  = 9;
            fakeInsightWindow.StartOffset    = 7;
            InitializePythonInsightWindowHandler();

            int newCaretOffset = 10;

            fakeTextEditor.FakeCaret.Offset  = newCaretOffset;
            fakeTextEditor.FakeDocument.Text = "method(a()";
            TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, ")");

            fakeInsightWindow.FireDocumentChangedEvent(e);

            bool closed = fakeInsightWindow.IsClosed;

            Assert.IsFalse(closed);
        }
示例#24
0
        void HandleTextChanging(object sender, TextChangeEventArgs e)
        {
            for (int i = 0; i < e.TextChanges.Count; ++i)
            {
                var change = e.TextChanges[i];
                foreach (var segment in originalProjections)
                {
                    if (segment.Contains(change.Offset))
                    {
                        var projectedOffset = change.Offset - segment.Offset + segment.LinkedTo.Offset;
                        try {
                            projectedEditor.ReplaceText(projectedOffset, change.RemovalLength, change.InsertedText);
                        } catch (Exception ex) {
                            LoggingService.LogError($"Error while replacing in projected editor at {projectedOffset} with length {projectedEditor.Length} change: {change}", ex);
                        }
                    }
                }
            }

            originalProjections.UpdateOnTextReplace(sender, e);
        }
示例#25
0
        /// <summary>
        /// Tells document that massive change to text buffer is complete. Document will perform full parse,
        /// resume tracking of text buffer changes and classification (colorization).
        /// </summary>
        /// <returns>True if changes were made to the text buffer since call to BeginMassiveChange</returns>
        public bool EndMassiveChange()
        {
            bool changed = _editorTree.TreeUpdateTask.TextBufferChangedSinceSuspend;

            if (_inMassiveChange == 1)
            {
                RClassifier colorizer = ServiceManager.GetService <RClassifier>(TextBuffer);
                if (colorizer != null)
                {
                    colorizer.Resume();
                }

                if (changed)
                {
                    TextChangeEventArgs textChange = new TextChangeEventArgs(0, 0, TextBuffer.CurrentSnapshot.Length, 0,
                                                                             new TextProvider(_editorTree.TextSnapshot, partial: true), new TextStream(string.Empty));

                    List <TextChangeEventArgs> textChanges = new List <TextChangeEventArgs>();
                    textChanges.Add(textChange);
                    _editorTree.FireOnUpdatesPending(textChanges);

                    _editorTree.FireOnUpdateBegin();
                    _editorTree.FireOnUpdateCompleted(TreeUpdateType.NewTree);
                }

                _editorTree.TreeUpdateTask.Resume();

                if (MassiveChangeEnded != null)
                {
                    MassiveChangeEnded(this, EventArgs.Empty);
                }
            }

            if (_inMassiveChange > 0)
            {
                _inMassiveChange--;
            }

            return(changed);
        }
示例#26
0
        /// <summary>
        /// Text buffer change event handler. Performs analysis of the change.
        /// If change is trivial, such as change in whitespace (excluding line
        /// breaks that in R may be sensistive), simply applies the changes
        /// by shifting tree elements. If some elements get deleted or otherwise
        /// damaged, removes them from the tree right away. Non-trivial changes
        /// are queued for background parsing which starts on next on idle.
        /// Methond must be called on a main thread only, typically from an event
        /// handler that receives text buffer change events.
        /// </summary>
        internal void OnTextChange(TextChangeEventArgs e)
        {
            Check.InvalidOperation(() => Thread.CurrentThread.ManagedThreadId == _ownerThreadId, _threadCheckMessage);

            _editorTree.FireOnUpdatesPending();
            if (UpdatesSuspended)
            {
                TextBufferChangedSinceSuspend = true;
                Changes.FullParseRequired     = true;
            }
            else
            {
                _lastChangeTime = DateTime.UtcNow;
                var context = new TextChangeContext(_editorTree, new TreeTextChange(e.Change), Changes);

                // No need to analyze changes if full parse is already pending
                if (!Changes.FullParseRequired)
                {
                    TextChangeAnalyzer.DetermineChangeType(context);
                }

                ProcessChange(context);
            }
        }
示例#27
0
        // Handles text modifications in hidden document
        void UnderlyingDocument_TextReplacing(object sender, TextChangeEventArgs e)
        {
            if (razorDocument == null)
            {
                return;
            }

            EnsureUnderlyingDocumentSet();
            int off = CalculateCaretPosition(e.Offset);

            if (e.RemovalLength > 0)
            {
                int removalLength = e.RemovalLength;
                if (off + removalLength > HiddenDoc.Editor.Length)
                {
                    removalLength = HiddenDoc.Editor.Length - off;
                }
                HiddenDoc.Editor.RemoveText(off, removalLength);
            }
            if (e.InsertionLength > 0)
            {
                if (isInCSharpContext)
                {
                    HiddenDoc.Editor.InsertText(off, e.InsertedText.Text);
                    HiddenDoc.HiddenAnalysisDocument = HiddenDoc.HiddenAnalysisDocument.WithText(Microsoft.CodeAnalysis.Text.SourceText.From(HiddenDoc.Editor.Text));
                }
                else                   // Insert spaces to correctly calculate offsets until next reparse
                {
                    HiddenDoc.Editor.InsertText(off, new String(' ', e.InsertionLength));
                }
            }
            if (codeFragment != null)
            {
                codeFragment.EndOffset += (e.InsertionLength - e.RemovalLength);
            }
        }
示例#28
0
		void DocumentChanged(object source, TextChangeEventArgs e)
		{
			documentHasChangedSinceLastFoldUpdate = true;
		}
 protected virtual void OnCommandChange(TextChangeEventArgs e)
 {
     e.Raise(this, ref CommandChanged);
 }
 void HandleTextEditorDataDocumentTextReplaced(object sender, TextChangeEventArgs e)
 {
     RemoveMarkers();
 }
示例#31
0
        void label_message_settext(object sender, TextChangeEventArgs e)
        {
            Label c = sender as Label;
            if(c != null)
            {
                if(c.InvokeRequired)
                {
                    c.Invoke(new TextChangeEventHandler(label_message_settext), sender, e);
                } else
                {
                    c.Text = e.Text;
                }

            }
        }
示例#32
0
 private void OnTextChanged(object sender, TextChangeEventArgs e)
 {
     // ok, the version changed.  Report that we've got an edit so that we can analyze
     // this source file and update anything accordingly.
     onChangedHandler(this.workspace, this.documentId, e.NewText, PreservationMode.PreserveIdentity);
 }
示例#33
0
		public void RaiseChangedEvent()
		{
			TextChangeEventArgs e = new TextChangeEventArgs(0, "", "a");
			if (TextChanged != null) {
				TextChanged(this, e);
			}
		}
示例#34
0
        void output_textbox_settext(object sender,TextChangeEventArgs  e)
        {
            TextBox c = sender as TextBox;
            if(c != null)
            {
                if(c.InvokeRequired)
                {
                    c.Invoke(new TextChangeEventHandler(output_textbox_settext),sender,  e);
                } else
                {
                    c.Text = e.Text;
                }

            }
        }
示例#35
0
		/// <summary>
		/// Updates the start and end offsets of all segments stored in this collection.
		/// </summary>
		/// <param name="e">TextChangeEventArgs instance describing the change to the document.</param>
		public void UpdateOffsets(TextChangeEventArgs e)
		{
			if (e == null)
				throw new ArgumentNullException("e");
			UpdateOffsets(e.GetNewOffset);
		}
        public void Replace(int offset, int length, string text)
        {
            if (offset < 0 || offset > TextLength)
                throw new ArgumentOutOfRangeException(nameof(offset));
            if (length < 0 || offset + length > TextLength)
                throw new ArgumentOutOfRangeException(nameof(length));
            if (text == null)
                throw new ArgumentNullException(nameof(text));

            var eventArgs = new TextChangeEventArgs(offset, GetText(offset, length), text);
            OnTextChanging(eventArgs);

            _cachedSnapshot = null;
            Builder.Remove(offset, length);
            Builder.Insert(offset, text);

            OnTextChanged(eventArgs);
        }
 protected virtual void OnTextChanging(TextChangeEventArgs e)
 {
     TextChanging?.Invoke(this, e);
 }
 private void OnTextChanged(object sender, TextChangeEventArgs e)
 {
     // ok, the version changed.  Report that we've got an edit so that we can analyze
     // this source file and update anything accordingly.
     _onChangedHandler(_workspace, _documentId, e.NewText);
 }
示例#39
0
 void o_OnMessage(object sender, RegexRun.MessageEventArgs e)
 {
     if(e.messagetype == "output")
     {
         //output_textbox.Text = e.message;
         TextChangeEventArgs te = new TextChangeEventArgs(); te.Text = e.message;
         output_textbox_settext(output_textbox, te);
     }
     if(e.messagetype == "label")
     {
         TextChangeEventArgs te = new TextChangeEventArgs(); te.Text = e.message;
         //label_message.Text = e.message;
         label_message_settext(label_message, te);
     }
     return;
 }