From 4fdb0861336e3981418b5c8f84158f061ad0ca79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr> Date: Thu, 10 Dec 2020 15:57:59 +0100 Subject: [PATCH] [ivette] AST view: do not register too many event handlers on the buffer. --- ivette/src/renderer/ASTview.tsx | 38 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ivette/src/renderer/ASTview.tsx b/ivette/src/renderer/ASTview.tsx index cdc4ac26493..574b069b906 100644 --- a/ivette/src/renderer/ASTview.tsx +++ b/ivette/src/renderer/ASTview.tsx @@ -130,29 +130,31 @@ const ASTview = () => { const propertyStatus = States.useSyncArray(Properties.status).getArray(); const statusDict = States.useTags(Properties.propStatusTags); + const [edited, setEdited] = React.useState(false); React.useEffect(() => { - function setBullets() { - if (theFunction) { - propertyStatus.forEach((prop) => { - if (prop.function === theFunction) { - const status = statusDict.get(prop.status); - if (status) { - const bullet = makeBullet(status); - const markers = buffer.findTextMarker(prop.key); - markers.forEach((marker) => { - const pos = marker.find(); - buffer.forEach((cm) => { - cm.setGutterMarker(pos.from.line, 'bullet', bullet); - }); + if (edited && theFunction) { + propertyStatus.forEach((prop) => { + if (prop.function === theFunction) { + const status = statusDict.get(prop.status); + if (status) { + const bullet = makeBullet(status); + const markers = buffer.findTextMarker(prop.key); + markers.forEach((marker) => { + const pos = marker.find(); + buffer.forEach((cm) => { + cm.setGutterMarker(pos.from.line, 'bullet', bullet); }); - } + }); } - }); - } + } + }); } - buffer.on('change', setBullets); - }, [buffer, propertyStatus, statusDict, theFunction]); + }, [buffer, edited, theFunction, propertyStatus, statusDict]); + + React.useEffect(() => { + buffer.on('edited', () => { setEdited(false); setEdited(true); }); + }, [buffer]); // Hook: async loading React.useEffect(() => { -- GitLab