Skip to content

Commit

Permalink
[#68517] fix deleting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Nov 12, 2024
1 parent 30ca260 commit 64ab745
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/comments/textareaWidget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditorView } from "@codemirror/view";
import { Decoration, WidgetType } from "@codemirror/view";
import { RangeSetBuilder, RangeSet, StateField, Transaction } from "@codemirror/state";
import { RangeSetBuilder, RangeSet, StateField, Transaction, MapMode } from "@codemirror/state";
import { ycommentsFacet, updateShownComments } from "./state";
import { YComments } from "./ycomments";
import { yHistoryAnnotation } from "../extensions/collab";
Expand Down Expand Up @@ -76,7 +76,12 @@ const moveComments = (transaction, ycomments) => {
ycomments.positions().positions.value.forEach((pos) => {
const oldPos = transaction.startState.doc.line(pos.lineNumber).from;
const newPos = transaction.changes.mapPos(oldPos, 1);
if (oldPos != newPos) {
const lineDeletedViaSelection = transaction.changes.mapPos(oldPos, 1, MapMode.TrackDel) == null;
const lineDeletedViaBackspace = transaction.changes.mapPos(oldPos, 1, MapMode.TrackBefore) == null;

if (lineDeletedViaSelection || lineDeletedViaBackspace) {
ycomments.deleteComment(pos.commentId);
} else if (oldPos != newPos) {
moved.push(pos.commentId);
ycomments.positions().move(pos.commentId, transaction.state.doc.lineAt(newPos).number, false);
}
Expand Down

0 comments on commit 64ab745

Please sign in to comment.