Skip to content

Commit

Permalink
feat(json-crdt-peritext-ui): 🎸 keep score while actively moving cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Nov 11, 2024
1 parent 3d7f58e commit 071ec09
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/json-crdt-peritext-ui/plugins/minimal/RenderPeritext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ export const RenderPeritext: React.FC<RenderPeritextProps> = ({ctx, children}) =
case 'delete':
case 'insert':
case 'format':
case 'marker':
case 'marker': {
const now = Date.now();
const timeDiff = now - lastNow;
const delta = timeDiff < 30 ? 10 : timeDiff < 70 ? 5 : timeDiff < 150 ? 2 : timeDiff <= 1000 ? 1 : 0;
value.score.next(delta ? value.score.value + delta : 0);
value.scoreDelta.next(delta);
lastNow = now;
break;
}
case 'cursor': {
lastNow = Date.now();
break;
}
}
};
dom.et.addEventListener('change', listener);
Expand Down

0 comments on commit 071ec09

Please sign in to comment.