fixes
This commit is contained in:
@@ -91,6 +91,47 @@ export function replaceAuthorshipOwner(model, matcher, replacement, contentLengt
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function lineAuthors(content, model) {
|
||||
const starts = [0];
|
||||
for (let i = 0; i < content.length; i++) if (content.charCodeAt(i) === 10) starts.push(i + 1);
|
||||
return starts.map((start, index) => {
|
||||
const end = index + 1 < starts.length ? starts[index + 1] : content.length;
|
||||
const totals = new Map();
|
||||
for (const span of model?.spans || []) {
|
||||
const overlap = Math.max(0, Math.min(end, span.end) - Math.max(start, span.start));
|
||||
if (overlap) totals.set(span.owner, (totals.get(span.owner) || 0) + overlap);
|
||||
}
|
||||
return [...totals.entries()].sort((a, b) => b[1] - a[1]).map(([owner]) => owner);
|
||||
});
|
||||
}
|
||||
|
||||
export function mapSelectionThroughEdit(previousText, nextText, start, end = start) {
|
||||
if (previousText === nextText) return { start, end };
|
||||
let prefix = 0;
|
||||
const shared = Math.min(previousText.length, nextText.length);
|
||||
while (prefix < shared && previousText.charCodeAt(prefix) === nextText.charCodeAt(prefix)) prefix++;
|
||||
|
||||
let oldSuffix = previousText.length;
|
||||
let newSuffix = nextText.length;
|
||||
while (oldSuffix > prefix && newSuffix > prefix && previousText.charCodeAt(oldSuffix - 1) === nextText.charCodeAt(newSuffix - 1)) {
|
||||
oldSuffix--;
|
||||
newSuffix--;
|
||||
}
|
||||
|
||||
const insertedLength = newSuffix - prefix;
|
||||
const delta = insertedLength - (oldSuffix - prefix);
|
||||
const map = position => {
|
||||
if (position < prefix) return position;
|
||||
if (position > oldSuffix) return position + delta;
|
||||
if (position === prefix && oldSuffix === prefix) return prefix + insertedLength;
|
||||
return prefix + insertedLength;
|
||||
};
|
||||
return {
|
||||
start: Math.max(0, Math.min(nextText.length, map(start))),
|
||||
end: Math.max(0, Math.min(nextText.length, map(end))),
|
||||
};
|
||||
}
|
||||
export function lineOwners(content, model) {
|
||||
const starts = [0];
|
||||
for (let i = 0; i < content.length; i++) if (content.charCodeAt(i) === 10) starts.push(i + 1);
|
||||
|
||||
Reference in New Issue
Block a user