Browse Source

Fixed SD2-961 - Null reference exception on performing a find next on a reopened file. The ProvidedDocumentInformation now has an Equals method which takes into account if the TextAreaControl is different. This Equals method is now used instead of only comparing the filenames so the search can determine if the document has been closed and reopened and a new ProvidedDocumentInformation instance will be required.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2301 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
39d46ef721
  1. 15
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/ProvidedDocumentInformation.cs
  2. 10
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs

15
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/ProvidedDocumentInformation.cs

@ -87,6 +87,21 @@ namespace SearchAndReplace @@ -87,6 +87,21 @@ namespace SearchAndReplace
return new DocumentFactory().CreateFromTextBuffer(textBuffer);
}
public override bool Equals(object obj)
{
ProvidedDocumentInformation info = obj as ProvidedDocumentInformation;
if (info == null) {
return false;
}
return this.fileName == info.fileName &&
this.textAreaControl == info.textAreaControl;
}
public override int GetHashCode()
{
return fileName.GetHashCode();
}
public ProvidedDocumentInformation(IDocument document, string fileName, int currentOffset)
{
this.document = document;

10
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs

@ -88,8 +88,9 @@ namespace SearchAndReplace @@ -88,8 +88,9 @@ namespace SearchAndReplace
Debug.Assert(textIteratorBuilder != null);
if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed
info = documentIterator.Current;
ProvidedDocumentInformation currentInfo = documentIterator.Current;
if (!info.Equals(currentInfo)) { // create new iterator, if document changed
info = currentInfo;
textIterator = textIteratorBuilder.BuildTextIterator(info);
} else { // old document -> initialize iterator position to caret pos
textIterator.Position = info.CurrentOffset;
@ -120,8 +121,9 @@ namespace SearchAndReplace @@ -120,8 +121,9 @@ namespace SearchAndReplace
public SearchResult FindNext(int offset, int length)
{
if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed
info = documentIterator.Current;
ProvidedDocumentInformation currentInfo = documentIterator.Current;
if (!info.Equals(currentInfo)) { // create new iterator, if document changed
info = currentInfo;
textIterator = textIteratorBuilder.BuildTextIterator(info);
} else { // old document -> initialize iterator position to caret pos
textIterator.Position = info.CurrentOffset;

Loading…
Cancel
Save