Browse Source

Avoid NullReferenceException when pasting text.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4267 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
8a4b2018a5
  1. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/NewLineFinder.cs
  2. 28
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/NewLineFinder.cs

@ -51,6 +51,8 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary> /// </summary>
public static string NormalizeNewLines(string input, string newLine) public static string NormalizeNewLines(string input, string newLine)
{ {
if (input == null)
return null;
Debug.Assert(IsNewLine(newLine)); Debug.Assert(IsNewLine(newLine));
SimpleSegment ds = NextNewLine(input, 0); SimpleSegment ds = NextNewLine(input, 0);
if (ds == SimpleSegment.Invalid) // text does not contain any new lines if (ds == SimpleSegment.Invalid) // text does not contain any new lines

28
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

@ -208,14 +208,14 @@ namespace ICSharpCode.AvalonEdit.Editing
{ {
TransformSelectedLines( TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line) { delegate (TextArea textArea, DocumentLine line) {
int offset = line.Offset; int offset = line.Offset;
ISegment s = TextUtilities.GetSingleIndentationSegment(line.Document, offset, textArea.Options.IndentationSize); ISegment s = TextUtilities.GetSingleIndentationSegment(line.Document, offset, textArea.Options.IndentationSize);
if (s.Length > 0) { if (s.Length > 0) {
s = textArea.ReadOnlySectionProvider.GetDeletableSegments(s).FirstOrDefault(); s = textArea.ReadOnlySectionProvider.GetDeletableSegments(s).FirstOrDefault();
if (s != null && s.Length > 0) { if (s != null && s.Length > 0) {
textArea.Document.Remove(s.Offset, s.Length); textArea.Document.Remove(s.Offset, s.Length);
}
} }
}
}, target, args, DefaultSegmentType.CurrentLine); }, target, args, DefaultSegmentType.CurrentLine);
} }
#endregion #endregion
@ -344,12 +344,14 @@ namespace ICSharpCode.AvalonEdit.Editing
string newLine = NewLineFinder.GetNewLineFromDocument(textArea.Document, textArea.Caret.Line); string newLine = NewLineFinder.GetNewLineFromDocument(textArea.Document, textArea.Caret.Line);
string text = NewLineFinder.NormalizeNewLines(Clipboard.GetText(), newLine); string text = NewLineFinder.NormalizeNewLines(Clipboard.GetText(), newLine);
bool fullLine = textArea.Options.CutCopyWholeLine && Clipboard.ContainsData(LineSelectedType); if (!string.IsNullOrEmpty(text)) {
if (fullLine) { bool fullLine = textArea.Options.CutCopyWholeLine && Clipboard.ContainsData(LineSelectedType);
DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line); if (fullLine) {
textArea.Document.Insert(currentLine.Offset, text); DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
} else { textArea.Document.Insert(currentLine.Offset, text);
textArea.ReplaceSelectionWithText(text); } else {
textArea.ReplaceSelectionWithText(text);
}
} }
textArea.Caret.BringCaretToView(); textArea.Caret.BringCaretToView();
args.Handled = true; args.Handled = true;

Loading…
Cancel
Save