-
Notifications
You must be signed in to change notification settings - Fork 17
carry text edits until successful migration #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace NMF.AnyText | ||
| { | ||
| internal class ItemEqualityComparer<T> : IEqualityComparer<T[]> | ||
| { | ||
| private readonly IEqualityComparer<T> _comparer; | ||
|
|
||
| public ItemEqualityComparer() : this(EqualityComparer<T>.Default) { } | ||
|
|
||
| public ItemEqualityComparer(IEqualityComparer<T> comparer) | ||
| { | ||
| _comparer = comparer; | ||
| } | ||
|
|
||
| public bool Equals(T[] x, T[] y) | ||
| { | ||
| if (x == null) | ||
| { | ||
| return y == null; | ||
| } | ||
| if (y == null || y.Length != x.Length) | ||
| { | ||
| return false; | ||
| } | ||
| for (int i = 0; i < x.Length; i++) | ||
| { | ||
| if (!_comparer.Equals(x[i], y[i])) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public int GetHashCode([DisallowNull] T[] obj) | ||
| { | ||
| unchecked | ||
| { | ||
| var hash = obj.Length.GetHashCode(); | ||
| for (int i = 0; i < obj.Length; i++) | ||
| { | ||
| hash ^= 23 * hash + obj[i].GetHashCode(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Array comparer crashes on null entries
Use a null-safe hash, e.g. |
||
| } | ||
| return hash; | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overlapping edit merge leaves stale original text behind
In the overlap branch, the tracker rewrites
_edits[editIndex]but never updates_oldTexts[editIndex]. That breaks the whole "carry edits until a successful migration" flow: a later edit can compare against the wrong pre-edit content and either drop a real change or keep an obsolete one.Update
_oldTexts[editIndex]when collapsing overlapping edits. Easiest fix is to recompute the merged old text for the new combined span, or explicitly carry forward the correct original slice before replacing_edits[editIndex].