diff --git a/static/js/CodeMirror/codemirror.js b/static/js/CodeMirror/codemirror.js index bc5927b831..a34d520891 100644 --- a/static/js/CodeMirror/codemirror.js +++ b/static/js/CodeMirror/codemirror.js @@ -616,6 +616,24 @@ var CodeMirror = (function() { // Afterwards, set the selection to selFrom, selTo. function updateLines(from, to, newText, selFrom, selTo) { if (suppressEdits) return; + + if (from.ch > 0 && newText[0] != '' && getLine(from.line).isWidgetBlock) { + newText.unshift(''); + var widgetLine = getLine(from.line); + function moveSel(sel) { + if (sel.line == from.line && sel.ch > 0){ + return {line: sel.line + 1, ch: sel.ch - widgetLine.text.length}; + } else if (sel.line > from.line) { + return {line: sel.line + 1, ch: sel.ch}; + } + } + selFrom = moveSel(selFrom, widgetLine); + selTo = moveSel(selTo, widgetLine); + } + if (to.ch == 0 && newText[newText.length - 1] != '' && getLine(to.line).isWidgetBlock) { + newText.push(''); + } + if (history) { var old = []; doc.iter(from.line, to.line + 1, function(line) { old.push(line.text); }); @@ -726,7 +744,6 @@ var CodeMirror = (function() { if (guess != line.height) updateLineHeight(line, guess); }); } else { - //TODO: update height here for widget blocks doc.iter(from.line, from.line + newText.length, function(line) { var l = line.text; if (l.length > maxLineLength) { @@ -779,23 +796,11 @@ var CodeMirror = (function() { return end; } function replaceSelection(code, collapse) { - var reposition = false; - if (code.length > 0) { - var fromLine = getLine(sel.from.line), toLine = getLine(sel.to.line); - if (fromLine.isWidgetBlock && sel.from.ch == fromLine.text.length) { - code = "\n" + code; - } else if (toLine.isWidgetBlock && sel.to.ch == 0) { - code = code + "\n"; - reposition = true; - } - } - replaceRange1(splitLines(code), sel.from, sel.to, function(end) { if (collapse == "end") return {from: end, to: end}; else if (collapse == "start") return {from: sel.from, to: sel.from}; else return {from: sel.from, to: end}; }); - if (reposition) moveH(-1, "char"); } function replaceRange1(code, from, to, computeSel) { var endch = code.length == 1 ? code[0].length + from.ch : code[code.length-1].length; @@ -1266,9 +1271,19 @@ var CodeMirror = (function() { setCursor(pos.line, pos.ch, true); } function deleteH(dir, unit) { - if (!posEq(sel.from, sel.to)) replaceRange("", sel.from, sel.to); - else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to); - else replaceRange("", sel.from, findPosH(dir, unit)); + var from = sel.from; + var to = sel.to; + if (posEq(sel.from, sel.to)) { + if (dir < 0) { + from = findPosH(dir, unit); + if (getLine(from.line).isWidgetBlock) from.ch = 0; + } + else { + to = findPosH(dir, unit); + if (getLine(to.line).isWidgetBlock) to.ch = getLine(to.line).text.length; + } + } + replaceRange("", from, to); userSelChange = true; } var goalColumn = null; @@ -1554,6 +1569,10 @@ var CodeMirror = (function() { var tempId = Math.floor(Math.random() * 0xffffff).toString(16); function measureLine(line, ch) { if (ch == 0) return {top: 0, left: 0}; + if (line.isWidgetBlock) { + var size = line.styles[1].size(line.text); + return {top: -1, left: size.width}; + } var extra = ""; // Include extra text at the end to make sure the measured line is wrapped in the right way. if (options.lineWrapping) { diff --git a/static/js/CodeMirror/mitx_markdown.js b/static/js/CodeMirror/mitx_markdown.js index 9a29b65fe0..aa63967c58 100644 --- a/static/js/CodeMirror/mitx_markdown.js +++ b/static/js/CodeMirror/mitx_markdown.js @@ -2,7 +2,7 @@ $(function(){ $(document).ready(function() { $("a[rel*=leanModal]").leanModal(); - $("body").append('
'); + $("body").append('
'); //This is the editor that pops up as a modal var editorCircuit = $("#schematic_editor").get(0); @@ -65,13 +65,13 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { //TODO: We need real html escaping here circuit_value = CodeMirror.htmlEscape(circuit_value);// circuit_value.replace("\"", "'"); - var html = ""; + var html = "" + + ""; return html; }, size: function(text) { - return {width: 400, height:302}; + return {width: 150, height:154}; }, callback: function(node, line) { update_schematics(); diff --git a/templates/simplewiki_edit.html b/templates/simplewiki_edit.html index 1c5ebd40fc..75e1fec325 100644 --- a/templates/simplewiki_edit.html +++ b/templates/simplewiki_edit.html @@ -45,11 +45,11 @@ //Store the inital contents so we can compare for unsaved changes var initial_contents = editor.getValue(); - window.onbeforeunload = function askConfirm() { //Warn the user before they navigate away - if ( editor.getValue() != initial_contents ) { - return "You have made changes to the article that have not been saved yet."; - } - }; + // window.onbeforeunload = function askConfirm() { //Warn the user before they navigate away + // if ( editor.getValue() != initial_contents ) { + // return "You have made changes to the article that have not been saved yet."; + // } + // }; $("#submit_edit").click(function() { initial_contents = editor.getValue();