MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / insertFloatHelper

Function insertFloatHelper

lib/web/drags.js:441–516  ·  view source on GitHub ↗
(onWord)

Source from the content-addressed store, hash-verified

439//makeSlider(rrRaph, w, h, function(){return 0.5}, function(o,p,n){_field.log(n);return n})
440
441var insertFloatHelper = function (onWord) {
442
443 // var f = cm.findWordAt(onWord);
444 // var selection_start = f.anchor
445 // var selection_end = f.head
446
447 var h = cm.getTokenAt(onWord)
448 var selection_start = {line: onWord.line, ch: h.start}
449 var selection_end = {line: onWord.line, ch: h.end}
450
451 var w = 150;
452 var h = 13;
453
454 console.log(" inserting a new marking canvas into the editor between " + stringify(selection_start));
455 var canvas = newOverlayWidget(selection_start.line, selection_start.ch, w, h);
456 var marks = canvas.mark;
457
458 var val = 0.5;
459
460 var start = cm.setBookmark(selection_start);
461 var end = cm.setBookmark(selection_end);
462
463 var get = function () {
464 return val;
465 };
466 var set = function (o, p, x) {
467 // update in animation?
468
469 console.log(" x-p = " + (x - p));
470
471 var s = start.find()
472 var e = end.find()
473
474 var text = cm.getDoc().getRange(s, e)
475
476 var currentDP = numDP(text);
477
478 var nextVal = "" + (parseFloat(text) + 4 * (Math.abs(parseFloat(text)) + Math.pow(10, -currentDP)) * (x - p)).toFixed(Math.max(2, currentDP - 1))
479
480 while (numDP(nextVal) > currentDP && nextVal.charAt(nextVal.length - 1) == '0')
481 nextVal = nextVal.substring(0, nextVal.length - 1)
482
483 console.log(nextVal);
484 console.log(s);
485 console.log(e);
486
487 nextVal = "" + nextVal
488 text = "" + text
489
490 if (nextVal.endsWith(".") && !text.endsWith(".")) nextVal = nextVal.substring(0, nextVal.length - 1);
491
492
493
494 if (text != nextVal) {
495 cm.getDoc().replaceRange(nextVal, s, e);
496
497 var f = findEnclosingPathForLine(onWord.line);
498 if (f != null) {

Callers 1

drags.jsFile · 0.85

Calls 4

makeDifferentialSliderFunction · 0.85
updateAllBracketsFunction · 0.85
logMethod · 0.80
stringifyFunction · 0.70

Tested by

no test coverage detected