Skip to content

Commit

Permalink
[#55040] do not update resolve comments on changes below their lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Jul 18, 2024
1 parent d519c30 commit d2472b5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/comments/ycomments.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,25 +448,22 @@ export class YComments {
/** @param {ViewUpdate} update */
syncResolvedComments(update) {
if (!update.docChanged && !update.transactions.some((t) => t.effects.some((e) => e.is(updateShownComments)))) return;
const linesNotMoved = update.startState.doc.lines === update.state.doc.lines;

const resolvedComments = this.resolver().resolved();
for (const comment of resolvedComments) {
if (linesNotMoved) {
let noChangesToCommentLine = true;
update.changes.iterChanges((from) => {
if (update.startState.doc.lineAt(from).number === comment.lineNumber) {
noChangesToCommentLine = false;
}
});

if (comment.occupied !== this.positions().isOccupied(comment.lineNumber)) {
noChangesToCommentLine = false;
let doNotUpdate = true;
update.changes.iterChanges((from) => {
if (update.startState.doc.lineAt(from).number <= comment.lineNumber) {
doNotUpdate = false;
}
});

if (noChangesToCommentLine) continue;
if (comment.occupied !== this.positions().isOccupied(comment.lineNumber)) {
doNotUpdate = false;
}

if (doNotUpdate) continue;

const oldPos = update.startState.doc.line(comment.lineNumber).from;
const newPos = update.changes.mapPos(oldPos, 1);
const newLineNumber = update.state.doc.lineAt(newPos).number;
Expand Down

0 comments on commit d2472b5

Please sign in to comment.