Skip to content

Commit 0cd0866

Browse files
committed
Avoid excessive, duplicate selection change notifications
That leads to unnecessary re-renderings.
1 parent cf47487 commit 0cd0866

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/editor.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,19 @@
15371537

15381538
}
15391539

1540-
WebViewBridge.send(JSON.stringify({type: 'SELECTION_CHANGE', data: {items: items}}))
1540+
notifyIfSelectionHasChanged(items);
1541+
}
1542+
1543+
function notifyIfSelectionHasChanged(items) {
1544+
var selectionChangeMessage = JSON.stringify({
1545+
data: {items: items},
1546+
type: 'SELECTION_CHANGE'
1547+
});
1548+
1549+
if (selectionChangeMessage !== zss_editor.previousSelectionChangeMessage) {
1550+
WebViewBridge.send(selectionChangeMessage);
1551+
zss_editor.previousSelectionChangeMessage = selectionChangeMessage;
1552+
}
15411553
}
15421554

15431555
zss_editor.focusContent = function() {

0 commit comments

Comments
 (0)