Only refresh comment positions on current tab

Prevents comments on other tabs moving to the top of the page
pull/7050/head
Karl Hobley 2021-04-08 12:19:44 +01:00 zatwierdzone przez Matt Westcott
rodzic e2ee17bb59
commit c0588c1511
2 zmienionych plików z 14 dodań i 9 usunięć

Wyświetl plik

@ -271,7 +271,8 @@ export class CommentApp {
() => {
// Render again if layout has changed (eg, a comment was added, deleted or resized)
// This will just update the "top" style attributes in the comments to get them to move
if (this.layout.refresh()) {
this.layout.refreshDesiredPositions(state.settings.currentTab);
if (this.layout.refreshLayout()) {
ReactDOM.render(
renderCommentsUi(this.store, this.layout, commentList, strings),
element

Wyświetl plik

@ -57,15 +57,16 @@ export class LayoutController {
);
}
refreshDesiredPositions() {
this.commentAnnotations.forEach((_, commentId) =>
this.updateDesiredPosition(commentId)
);
}
refresh() {
refreshDesiredPositions(tab: string | null = null) {
/* Finds the current annotation positions of all the comments on the specified tab */
const oldDesiredPositions = new Map(this.commentDesiredPositions);
this.refreshDesiredPositions();
this.commentAnnotations.forEach((_, commentId) => {
if (this.getCommentVisible(tab, commentId)) {
this.updateDesiredPosition(commentId);
}
});
// It's not great to be recalculating all positions so regularly, but Wagtail's FE widgets
// aren't very constrained so could change layout in any number of ways. If we have a stable FE
// widget framework in the future, this could be used to trigger the position refresh more
@ -74,7 +75,10 @@ export class LayoutController {
if (this.commentDesiredPositions !== oldDesiredPositions) {
this.isDirty = true;
}
}
refreshLayout() {
/* Updates positions of all comments based on their annotation locations, and resolves any overlapping comments */
if (!this.isDirty) {
return false;
}