コード例 #1
0
 protected virtual void OnTextReplacing(DocumentChangeEventArgs args)
 {
     if (TextReplacing != null)
     {
         TextReplacing(this, args);
     }
 }
コード例 #2
0
 public void TextReplaced(object sender, DocumentChangeEventArgs args)
 {
     if (args.RemovalLength > 0)
     {
         TextRemove(args.Offset, args.RemovalLength);
     }
     if (args.InsertionLength > 0)
     {
         TextInsert(args.Offset, args.InsertedText.Text);
     }
 }
コード例 #3
0
ファイル: Caret.cs プロジェクト: mennodeij/XwtPlus.TextEditor
        internal void UpdateCaretPosition(DocumentChangeEventArgs e)
        {
            if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset)
            {
                offsetVersion = TextEditor.Document.Version;
                return;
            }
            var curVersion = TextEditor.Document.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      = TextEditor.Document.OffsetToLocation(newOffset);
            int newColumn        = newLocation.Column;

            var curLine = TextEditor.Document.GetLine(newLocation.Line);

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

            SetDesiredColumn();
            UpdateCaretOffset();
            OnPositionChanged(new DocumentLocationEventArgs(old));
        }
コード例 #4
0
        public void Replace(int offset, int count, string value, ICSharpCode.NRefactory.Editor.AnchorMovementType anchorMovementType = AnchorMovementType.Default)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "must be > 0, was: " + offset);
            }
            if (offset > TextLength)
            {
                throw new ArgumentOutOfRangeException("offset", "must be <= Length, was: " + offset);
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "must be > 0, was: " + count);
            }

            //InterruptFoldWorker();
            //int oldLineCount = LineCount;
            var args = new DocumentChangeEventArgs(offset, count > 0 ? GetTextAt(offset, count) : "", value, anchorMovementType);

            OnTextReplacing(args);
            value = args.InsertedText.Text;

            /*UndoOperation operation = null;
             * if (!isInUndo)
             * {
             *  operation = new UndoOperation(args);
             *  if (currentAtomicOperation != null)
             *  {
             *      currentAtomicOperation.Add(operation);
             *  }
             *  else
             *  {
             *      OnBeginUndo();
             *      undoStack.Push(operation);
             *      OnEndUndo(new UndoOperationEventArgs(operation));
             *  }
             *  redoStack.Clear();
             * }*/

            buffer.Replace(offset, count, value);
            //foldSegmentTree.UpdateOnTextReplace(this, args);
            splitter.TextReplaced(this, args);
            versionProvider.AppendChange(args);
            OnTextReplaced(args);
        }