Exemplo n.º 1
0
        private static void DeleteStatement(VisualStudio.Text.ITextEdit edit, SourceSpan span, bool insertPass) {
            // remove the entire node, leave any trailing whitespace/comments, but include the
            // newline and any indentation.


            int start = span.Start.Index;
            int length = span.Length;
            int cur = start - 1;
            if (!insertPass) {
                // backup to remove any indentation
                while (start - 1 > 0) {
                    var curChar = edit.Snapshot.GetText(start - 1, 1);
                    if (curChar[0] == ' ' || curChar[0] == '\t' || curChar[0] == '\f') {
                        length++;
                        start--;
                    } else {
                        break;
                    }
                }
            }

            // extend past any trailing whitespace characters
            while (start + length < edit.Snapshot.Length) {
                var curChar = edit.Snapshot.GetText(start + length, 1);
                if (curChar[0] == ' ' || curChar[0] == '\t' || curChar[0] == '\f') {
                    length++;
                } else {
                    break;
                }
            }

            // remove the trailing newline as well.
            if (!insertPass) {
                if (start + length < edit.Snapshot.Length) {
                    var newlineText = edit.Snapshot.GetText(start + length, 1);
                    if (newlineText == "\r") {
                        if (start + length + 1 < edit.Snapshot.Length) {
                            newlineText = edit.Snapshot.GetText(start + length + 1, 1);
                            if (newlineText == "\n") {
                                length += 2;
                            } else {
                                length++;
                            }
                        } else {
                            length++;
                        }
                    } else if (newlineText == "\n") {
                        length++;
                    }
                }
            }
            edit.Delete(start, length);

            if (insertPass) {
                edit.Insert(start, "pass");
            }
        }