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 @@ -51,6 +51,8 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary>
public static string NormalizeNewLines(string input, string newLine)
{
if (input == null)
return null;
Debug.Assert(IsNewLine(newLine));
SimpleSegment ds = NextNewLine(input, 0);
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 @@ -208,14 +208,14 @@ namespace ICSharpCode.AvalonEdit.Editing
{
TransformSelectedLines(
delegate (TextArea textArea, DocumentLine line) {
int offset = line.Offset;
ISegment s = TextUtilities.GetSingleIndentationSegment(line.Document, offset, textArea.Options.IndentationSize);
if (s.Length > 0) {
s = textArea.ReadOnlySectionProvider.GetDeletableSegments(s).FirstOrDefault();
if (s != null && s.Length > 0) {
textArea.Document.Remove(s.Offset, s.Length);
}
int offset = line.Offset;
ISegment s = TextUtilities.GetSingleIndentationSegment(line.Document, offset, textArea.Options.IndentationSize);
if (s.Length > 0) {
s = textArea.ReadOnlySectionProvider.GetDeletableSegments(s).FirstOrDefault();
if (s != null && s.Length > 0) {
textArea.Document.Remove(s.Offset, s.Length);
}
}
}, target, args, DefaultSegmentType.CurrentLine);
}
#endregion
@ -344,12 +344,14 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -344,12 +344,14 @@ namespace ICSharpCode.AvalonEdit.Editing
string newLine = NewLineFinder.GetNewLineFromDocument(textArea.Document, textArea.Caret.Line);
string text = NewLineFinder.NormalizeNewLines(Clipboard.GetText(), newLine);
bool fullLine = textArea.Options.CutCopyWholeLine && Clipboard.ContainsData(LineSelectedType);
if (fullLine) {
DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
textArea.Document.Insert(currentLine.Offset, text);
} else {
textArea.ReplaceSelectionWithText(text);
if (!string.IsNullOrEmpty(text)) {
bool fullLine = textArea.Options.CutCopyWholeLine && Clipboard.ContainsData(LineSelectedType);
if (fullLine) {
DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
textArea.Document.Insert(currentLine.Offset, text);
} else {
textArea.ReplaceSelectionWithText(text);
}
}
textArea.Caret.BringCaretToView();
args.Handled = true;

Loading…
Cancel
Save