omorphia icon indicating copy to clipboard operation
omorphia copied to clipboard

allow simple arithmetic in slider input field

Open jakobhellermann opened this issue 2 years ago • 3 comments

implements a simple form of https://github.com/modrinth/theseus/issues/720

https://github.com/modrinth/omorphia/assets/22177966/5a4a1e34-41d8-4dc7-9c5d-b1c29933cc44

This only allows simple math in the form of 50+2, no multiple operators, parenthesis, or "8gb + 10mb" symbols, but I wanted to open this PR first to check if there's even interest in merging this.


ChatGPT suggested this alternative implementation which would implement parenthesis etc. nicely but I don't know if that's worth the use of the dubious eval function.

let sanitizedExpression = expression.replace(/[^0-9+\-*/().]/g, ''); // Sanitize input
let result = eval(sanitizedExpression); // Use eval on sanitized input

jakobhellermann avatar Dec 28 '23 23:12 jakobhellermann

I would definitely not use eval, that sounds like a really bad idea.

Prospector avatar Dec 29 '23 00:12 Prospector

I think this is nice for when trying to do it in gigs, but don't want to do the math. And it would be nice to have just general gb mb terms in general (ik this isn't in the PR yet)

Though, I think the main problem with the idea is discverability

Minenash avatar Dec 29 '23 01:12 Minenash

Discoverability isn't really a concern with shortcut features like this, they're things people can use if they learn about them and if they dont, it's no big deal because they can still do the math themselves and type the number in.

Prospector avatar Dec 29 '23 01:12 Prospector