예제 #1
0
        public void OnRemoveTrailingWhiteSpaces()
        {
            Mono.TextEditor.TextEditorData data = doc.Editor;
            if (data == null)
            {
                return;
            }

            System.Collections.Generic.List <RemoveInfo> removeList = new System.Collections.Generic.List <RemoveInfo> ();
            int        pos        = data.Document.Length - 1;
            RemoveInfo removeInfo = RemoveInfo.GetRemoveInfo(data.Document, ref pos);

            if (!removeInfo.IsEmpty)
            {
                removeList.Add(removeInfo);
            }

            while (pos >= 0)
            {
                char ch = data.Document.GetCharAt(pos);
                if (ch == '\n' || ch == '\r')
                {
                    if (RemoveInfo.IsWhiteSpace(data.Document.GetCharAt(pos - 1)))
                    {
                        --pos;
                        removeInfo = RemoveInfo.GetRemoveInfo(data.Document, ref pos);
                        if (!removeInfo.IsEmpty)
                        {
                            removeList.Add(removeInfo);
                        }
                    }
                }
                --pos;
            }

            data.Document.BeginAtomicUndo();
            foreach (var info in removeList)
            {
                ((Mono.TextEditor.IBuffer)data.Document).Remove(info.Position, info.Length);
                data.Document.CommitLineUpdate(data.Document.OffsetToLineNumber(info.Position));
            }
            data.Caret.Offset = Math.Min(data.Caret.Offset, data.Document.Length - 1);
            data.Document.EndAtomicUndo();
        }
예제 #2
0
        public void OnRemoveTrailingWhiteSpaces()
        {
            Mono.TextEditor.TextEditorData data = doc.Editor;
            if (data == null)
            {
                return;
            }

            System.Collections.Generic.List <RemoveInfo> removeList = new System.Collections.Generic.List <RemoveInfo> ();
            int        pos        = data.Document.TextLength - 1;
            RemoveInfo removeInfo = RemoveInfo.GetRemoveInfo(data.Document, ref pos);

            if (!removeInfo.IsEmpty)
            {
                removeList.Add(removeInfo);
            }

            while (pos >= 0)
            {
                char ch = data.Document.GetCharAt(pos);
                if (ch == '\n' || ch == '\r')
                {
                    if (RemoveInfo.IsWhiteSpace(data.Document.GetCharAt(pos - 1)))
                    {
                        --pos;
                        removeInfo = RemoveInfo.GetRemoveInfo(data.Document, ref pos);
                        if (!removeInfo.IsEmpty)
                        {
                            removeList.Add(removeInfo);
                        }
                    }
                }
                --pos;
            }
            using (var undo = data.OpenUndoGroup())
            {
                foreach (var info in removeList)
                {
                    data.Document.Remove(info.Position, info.Length);
                    data.Document.CommitLineUpdate(data.Document.OffsetToLineNumber(info.Position));
                }
            }
        }
예제 #3
0
        public void OnRemoveTrailingWhiteSpaces()
        {
            var data = doc.Editor;

            if (data == null)
            {
                return;
            }

            System.Collections.Generic.List <RemoveInfo> removeList = new System.Collections.Generic.List <RemoveInfo> ();
            int        pos        = data.Length - 1;
            RemoveInfo removeInfo = RemoveInfo.GetRemoveInfo(data, ref pos);

            if (!removeInfo.IsEmpty)
            {
                removeList.Add(removeInfo);
            }

            while (pos >= 0)
            {
                char ch = data.GetCharAt(pos);
                if (ch == '\n' || ch == '\r')
                {
                    if (RemoveInfo.IsWhiteSpace(data.GetCharAt(pos - 1)))
                    {
                        --pos;
                        removeInfo = RemoveInfo.GetRemoveInfo(data, ref pos);
                        if (!removeInfo.IsEmpty)
                        {
                            removeList.Add(removeInfo);
                        }
                    }
                }
                --pos;
            }
            using (var undo = data.OpenUndoGroup()) {
                foreach (var info in removeList)
                {
                    data.RemoveText(info.Position, info.Length);
                }
            }
        }