Browse Source

ITextBufferVersion: add MoveOffsetTo method

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4782 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
7dd5d67102
  1. 14
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ChangeTrackingCheckpoint.cs
  2. 15
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditDocumentAdapter.cs
  3. 6
      src/Main/Base/Project/Src/Editor/ITextBuffer.cs
  4. 6
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

14
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ChangeTrackingCheckpoint.cs

@ -118,5 +118,19 @@ namespace ICSharpCode.AvalonEdit.Document
yield return node.value; yield return node.value;
} while (node != other); } while (node != other);
} }
/// <summary>
/// Calculates where the offset has moved in the other buffer version.
/// </summary>
/// <remarks>This method is thread-safe.</remarks>
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
public int MoveOffsetTo(ChangeTrackingCheckpoint other, int oldOffset, AnchorMovementType movement)
{
int offset = oldOffset;
foreach (DocumentChangeEventArgs e in GetChangesTo(other)) {
offset = e.GetNewOffset(offset, movement);
}
return offset;
}
} }
} }

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

@ -237,6 +237,21 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
throw new ArgumentException("Does not belong to same document"); throw new ArgumentException("Does not belong to same document");
return checkpoint.GetChangesTo(otherVersion.checkpoint).Select(c => new TextChangeEventArgs(c.Offset, c.RemovedText, c.InsertedText)); return checkpoint.GetChangesTo(otherVersion.checkpoint).Select(c => new TextChangeEventArgs(c.Offset, c.RemovedText, c.InsertedText));
} }
public int MoveOffsetTo(ITextBufferVersion other, int oldOffset, AnchorMovementType movement)
{
SnapshotVersion otherVersion = other as SnapshotVersion;
if (otherVersion == null)
throw new ArgumentException("Does not belong to same document");
switch (movement) {
case AnchorMovementType.AfterInsertion:
return checkpoint.MoveOffsetTo(otherVersion.checkpoint, oldOffset, ICSharpCode.AvalonEdit.Document.AnchorMovementType.AfterInsertion);
case AnchorMovementType.BeforeInsertion:
return checkpoint.MoveOffsetTo(otherVersion.checkpoint, oldOffset, ICSharpCode.AvalonEdit.Document.AnchorMovementType.BeforeInsertion);
default:
throw new NotSupportedException();
}
}
} }
#endregion #endregion

6
src/Main/Base/Project/Src/Editor/ITextBuffer.cs

@ -113,6 +113,12 @@ namespace ICSharpCode.SharpDevelop
/// <remarks>This method is thread-safe.</remarks> /// <remarks>This method is thread-safe.</remarks>
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception> /// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
IEnumerable<TextChangeEventArgs> GetChangesTo(ITextBufferVersion other); IEnumerable<TextChangeEventArgs> GetChangesTo(ITextBufferVersion other);
/// <summary>
/// Calculates where the offset has moved in the other buffer version.
/// </summary>
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
int MoveOffsetTo(ITextBufferVersion other, int oldOffset, AnchorMovementType movement);
} }
public sealed class StringTextBuffer : Editor.AvalonEdit.AvalonEditTextSourceAdapter public sealed class StringTextBuffer : Editor.AvalonEdit.AvalonEditTextSourceAdapter

6
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

@ -249,7 +249,11 @@ namespace ICSharpCode.SharpDevelop.Dom
[Conditional("DEBUG")] [Conditional("DEBUG")]
void CheckNotDisposed() void CheckNotDisposed()
{ {
Debug.Assert(!isDisposed); // TODO: this is broken - we are accessing project contents even after
// they have been unloaded, e.g. on other threads
if (!isDisposed) {
// throw new ObjectDisposedException();
}
} }
public void AddClassToNamespaceList(IClass addClass) public void AddClassToNamespaceList(IClass addClass)

Loading…
Cancel
Save