Commit 43318b72 by Bridger Maxwell

Fixing deletion / insertion bugs and inconsistencies

parent 952b7549
......@@ -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) {
......
......@@ -2,7 +2,7 @@ $(function(){
$(document).ready(function() {
$("a[rel*=leanModal]").leanModal();
$("body").append('<div id="circuit_editor" class="leanModal_box" style="z-index: 11000; left: 50%; margin-left: -250px; position: absolute; top: 100px; opacity: 1; "><div align="center"> <input class="schematic" height="300" width="400" id="schematic_editor" name="schematic" type="hidden" value=""/> <button type="button" id="circuit_save_btn">save</button></div></div>');
$("body").append('<div id="circuit_editor" class="leanModal_box" style="z-index: 11000; left: 50%; margin-left: -250px; position: absolute; top: 100px; opacity: 1; "><div align="center"> <input class="schematic" height="150" width="150" id="schematic_editor" name="schematic" type="hidden" value=""/> <button type="button" id="circuit_save_btn">save</button></div></div>');
//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 = "<a href='#circuit_editor' rel='leanModal' class='schematic_open' style='width:400px; '><input type='hidden' parts='' value='" +
circuit_value + "' analyses='' class='schematic ctrls'/></a>";
var html = "<a href='#circuit_editor' rel='leanModal' class='schematic_open' style='display:inline-block;'>" +
"<input type='hidden' parts='' value='" + circuit_value + "' width='150' height='150' analyses='' class='schematic ctrls'/></a>";
return html;
},
size: function(text) {
return {width: 400, height:302};
return {width: 150, height:154};
},
callback: function(node, line) {
update_schematics();
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment