Browse Source

Fixed commenting out lines selected from the line number margin.

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
4b24dd80f8
  1. 6
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs
  2. 14
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditDocumentAdapter.cs
  3. 1
      src/Main/Base/Project/Src/Editor/IDocument.cs
  4. 11
      src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs
  5. 13
      src/Main/Base/Project/Src/Editor/ReadOnlyDocument.cs

6
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs

@ -313,7 +313,7 @@ namespace CSharpBinding.FormattingStrategy @@ -313,7 +313,7 @@ namespace CSharpBinding.FormattingStrategy
case '>':
if (IsInsideDocumentationComment(textArea, curLine, cursorOffset)) {
curLineText = curLine.Text;
int column = textArea.Caret.Offset - curLine.Offset;
int column = cursorOffset - curLine.Offset;
int index = Math.Min(column - 1, curLineText.Length - 1);
while (index >= 0 && curLineText[index] != '<') {
@ -332,9 +332,7 @@ namespace CSharpBinding.FormattingStrategy @@ -332,9 +332,7 @@ namespace CSharpBinding.FormattingStrategy
tag += ">";
}
if (!tag.StartsWith("/")) {
int caretOffset = textArea.Caret.Offset;
textArea.Document.Insert(caretOffset, "</" + tag.Substring(1));
textArea.Caret.Offset = caretOffset;
textArea.Document.Insert(cursorOffset, "</" + tag.Substring(1), AnchorMovementType.BeforeInsertion);
}
}
}

14
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditDocumentAdapter.cs

@ -145,6 +145,15 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -145,6 +145,15 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
document.Insert(offset, text);
}
public void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType)
{
if (defaultAnchorMovementType == AnchorMovementType.BeforeInsertion) {
document.Replace(offset, 0, text, OffsetChangeMappingType.KeepAnchorBeforeInsertion);
} else {
document.Insert(offset, text);
}
}
public void Remove(int offset, int length)
{
document.Remove(offset, length);
@ -155,6 +164,11 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -155,6 +164,11 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
document.Replace(offset, length, newText);
}
public void Replace(int offset, int length, string newText, AnchorMovementType defaultAnchorMovementType)
{
document.Replace(offset, length, newText);
}
public char GetCharAt(int offset)
{
return document.GetCharAt(offset);

1
src/Main/Base/Project/Src/Editor/IDocument.cs

@ -38,6 +38,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -38,6 +38,7 @@ namespace ICSharpCode.SharpDevelop.Editor
Location OffsetToPosition(int offset);
void Insert(int offset, string text);
void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType);
void Remove(int offset, int length);
void Replace(int offset, int length, string newText);

11
src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs

@ -76,20 +76,23 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -76,20 +76,23 @@ namespace ICSharpCode.SharpDevelop.Editor
Location startPosition = editor.Document.OffsetToPosition(editor.SelectionStart);
Location endPosition = editor.Document.OffsetToPosition(editor.SelectionStart + editor.SelectionLength);
// endLine is one above endPosition if no characters are selected on the last line (e.g. line selection from the margin)
int endLine = (endPosition.Column == 1 && endPosition.Line > startPosition.Line) ? endPosition.Line - 1 : endPosition.Line;
List<IDocumentLine> lines = new List<IDocumentLine>();
bool removeComment = true;
for (int i = startPosition.Line; i <= endPosition.Line; i++) {
for (int i = startPosition.Line; i <= endLine; i++) {
lines.Add(editor.Document.GetLine(i));
if (!lines[i - startPosition.Line].Text.Trim().StartsWith(comment))
if (!lines[i - startPosition.Line].Text.Trim().StartsWith(comment, StringComparison.Ordinal))
removeComment = false;
}
foreach (IDocumentLine line in lines) {
if (removeComment) {
editor.Document.Remove(line.Offset + line.Text.IndexOf(comment), comment.Length);
editor.Document.Remove(line.Offset + line.Text.IndexOf(comment, StringComparison.Ordinal), comment.Length);
} else {
editor.Document.Insert(line.Offset, comment);
editor.Document.Insert(line.Offset, comment, AnchorMovementType.BeforeInsertion);
}
}
}

13
src/Main/Base/Project/Src/Editor/ReadOnlyDocument.cs

@ -18,6 +18,8 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -18,6 +18,8 @@ namespace ICSharpCode.SharpDevelop.Editor
public ReadOnlyDocument(ITextBuffer textBuffer)
{
if (textBuffer == null)
throw new ArgumentNullException("textBuffer");
// ensure that underlying buffer is immutable
this.textBuffer = textBuffer.CreateSnapshot();
List<int> lines = new List<int>();
@ -168,17 +170,22 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -168,17 +170,22 @@ namespace ICSharpCode.SharpDevelop.Editor
get { return textBuffer.TextLength; }
}
public void Insert(int offset, string text)
void IDocument.Insert(int offset, string text)
{
throw new NotSupportedException();
}
public void Remove(int offset, int length)
void IDocument.Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType)
{
throw new NotSupportedException();
}
public void Replace(int offset, int length, string newText)
void IDocument.Remove(int offset, int length)
{
throw new NotSupportedException();
}
void IDocument.Replace(int offset, int length, string newText)
{
throw new NotSupportedException();
}

Loading…
Cancel
Save