codemirror-interact icon indicating copy to clipboard operation
codemirror-interact copied to clipboard

Package seems to only support updating by an integer value (can't divide e.movementX).

Open zachwinter opened this issue 2 years ago • 1 comments

image

onDrag: (text, setText, e) => {
  const newVal = Number(text) + (e.movementX / 20);
  if (isNaN(newVal)) return;
  setText(newVal.toString());
},

When trying to update a numeric value by a decimal value, it still adds the ending decimal point to the final value.

Absolutely love this feature, but it'd be immeasurably more helpful if I could update more granularly! Especially with a viewport normalized to [-1, 1] on both axes (I'm using GLSL to write fragment shaders).

zachwinter avatar Jul 18 '23 22:07 zachwinter

One neat trick I've been using to help with the granularity is to set up fractions.

If I want to tweak a value from 1-3, instead of

const x = 2;

which will end up going way out of range, I'll do

const x = 20/10;

then use the widget on the 20 only. For more granularity:

const x = 200/100;

This works pretty well for me. It's a bit idiosyncratic to come across this in code, but I've been doing it for a while now so when I see fractions it's clear that the thing is ripe for tweaking.

curran avatar Mar 26 '24 09:03 curran