Permalink
Browse files

tied expr boxes to output boxes, so when they convert to and from, th…

…e output boxes go with them
  • Loading branch information...
zot committed Apr 23, 2012
1 parent fb57e61 commit e5ef5a3e5341b6fe7a97bdb1cfb04be79365b905
Showing with 39 additions and 24 deletions.
  1. +18 −13 notebook.cs
  2. +21 −11 notebook.js
View
@@ -36,6 +36,7 @@
sp.setAttribute('generatedNL', '')
bx = box s.getRangeAt(0), 'codeMainExpr', true
bx.appendChild sp
+ makeOutputBox bx
r = document.createRange()
r.setStart(sp, 0)
s.removeAllRanges()
@@ -49,12 +50,18 @@ bx.appendChild sp
checkMutateFromModification = (b)->
if b?
inDef = selInDef()
- if inDef and b.classList.contains('codeMainExpr')
- b.classList.remove 'codeMainExpr'
- b.classList.add 'codeMain'
- else if !inDef and b.classList.contains('codeMain')
- b.classList.remove 'codeMain'
- b.classList.add 'codeMainExpr'
+ if inDef and b.classList.contains('codeMainExpr') then toDefBox b
+ else if !inDef and b.classList.contains('codeMain') then toExprBox b
+
+toExprBox = (b)->
+ b.classList.remove 'codeMain'
+ b.classList.add 'codeMainExpr'
+ makeOutputBox b
+
+toDefBox = (b)->
+ if b.output then b.parentNode.removeChild b.output
+ b.classList.remove 'codeMainExpr'
+ b.classList.add 'codeMain'
selInDef = (expectedClass)->
s = window.getSelection()
@@ -72,8 +79,7 @@ bx.appendChild sp
s = window.getSelection()
r = s.getRangeAt(0)
if p = selInDef('codeMainExpr')
- p.classList.remove 'codeMainExpr'
- p.classList.add 'codeMain'
+ toDefBox p
initNotebook = (el)->
el.replacing = true
@@ -83,9 +89,6 @@ removeOldDefs el
el.appendChild textNode('\n')
el.appendChild textNode('\n')
el.appendChild textNode('\n')
- # bx = codeBox 'codeMain'
- # bx.appendChild textNode('\n')
- # el.appendChild bx
el.normalize()
el.replacing = false
pgm
@@ -130,7 +133,7 @@ s.appendChild textNode('\n')
s.setAttribute('generatedNL', '')
bx = box main, 'codeMainExpr', true
bx.appendChild s
- bx.parentNode.insertBefore exprBox(bx), bx.nextSibling
+ makeOutputBox(bx)
pgm
textNode = (text)-> document.createTextNode(text)
@@ -147,15 +150,17 @@ bx.appendChild s
exBox.lastChild.scrollIntoView()
prompt:(msg, cont)-> cont(window.prompt(msg))
-exprBox = (source)->
+makeOutputBox = (source)->
node = document.createElement 'div'
node.setAttribute 'LeisureOutput', ''
node.setAttribute 'Leisure', ''
node.setAttribute 'class', 'output'
node.setAttribute 'contentEditable', 'false'
node.source = source
+ source.output = node
node.innerHTML = "<button onclick='Notebook.evalOutput(this.parentNode)'>-&gt;</button>"
node.appendChild textNode(' \n')
+ source.parentNode.insertBefore node, source.nextSibling
node
codeSpan = (text, boxType)->
View
@@ -4,7 +4,7 @@
*/
(function() {
- var Leisure, ReplCore, addsLine, bindNotebook, box, checkMutateFromModification, checkMutateToDef, codeBox, codeSpan, continueRangePosition, delay, envFor, evalOutput, exprBox, findDefs, getBox, getRangePosition, getRanges, grp, initNotebook, makeRange, markupDefs, nodeEnd, prepExpr, removeOldDefs, root, selInDef, textNode;
+ var Leisure, ReplCore, addsLine, bindNotebook, box, checkMutateFromModification, checkMutateToDef, codeBox, codeSpan, continueRangePosition, delay, envFor, evalOutput, findDefs, getBox, getRangePosition, getRanges, grp, initNotebook, makeOutputBox, makeRange, markupDefs, nodeEnd, prepExpr, removeOldDefs, root, selInDef, textNode, toDefBox, toExprBox;
if ((typeof window !== "undefined" && window !== null) && (!(typeof global !== "undefined" && global !== null) || global === window)) {
window.global = window;
@@ -57,6 +57,7 @@
sp.setAttribute('generatedNL', '');
bx = box(s.getRangeAt(0), 'codeMainExpr', true);
bx.appendChild(sp);
+ makeOutputBox(bx);
r = document.createRange();
r.setStart(sp, 0);
s.removeAllRanges();
@@ -79,15 +80,25 @@
if (b != null) {
inDef = selInDef();
if (inDef && b.classList.contains('codeMainExpr')) {
- b.classList.remove('codeMainExpr');
- return b.classList.add('codeMain');
+ return toDefBox(b);
} else if (!inDef && b.classList.contains('codeMain')) {
- b.classList.remove('codeMain');
- return b.classList.add('codeMainExpr');
+ return toExprBox(b);
}
}
};
+ toExprBox = function toExprBox(b) {
+ b.classList.remove('codeMain');
+ b.classList.add('codeMainExpr');
+ return makeOutputBox(b);
+ };
+
+ toDefBox = function toDefBox(b) {
+ if (b.output) b.parentNode.removeChild(b.output);
+ b.classList.remove('codeMainExpr');
+ return b.classList.add('codeMain');
+ };
+
selInDef = function selInDef(expectedClass) {
var box, defType, leading, m, matched, name, r, s, txt;
s = window.getSelection();
@@ -109,10 +120,7 @@
if (!el.replacing) {
s = window.getSelection();
r = s.getRangeAt(0);
- if (p = selInDef('codeMainExpr')) {
- p.classList.remove('codeMainExpr');
- return p.classList.add('codeMain');
- }
+ if (p = selInDef('codeMainExpr')) return toDefBox(p);
}
};
@@ -193,7 +201,7 @@
s.setAttribute('generatedNL', '');
bx = box(main, 'codeMainExpr', true);
bx.appendChild(s);
- bx.parentNode.insertBefore(exprBox(bx), bx.nextSibling);
+ makeOutputBox(bx);
}
}
return pgm;
@@ -227,16 +235,18 @@
};
};
- exprBox = function exprBox(source) {
+ makeOutputBox = function makeOutputBox(source) {
var node;
node = document.createElement('div');
node.setAttribute('LeisureOutput', '');
node.setAttribute('Leisure', '');
node.setAttribute('class', 'output');
node.setAttribute('contentEditable', 'false');
node.source = source;
+ source.output = node;
node.innerHTML = "<button onclick='Notebook.evalOutput(this.parentNode)'>-&gt;</button>";
node.appendChild(textNode(' \n'));
+ source.parentNode.insertBefore(node, source.nextSibling);
return node;
};

0 comments on commit e5ef5a3

Please sign in to comment.