drop experimental prewrap mode
- pasting in prewrap mode had been broken for a while and nobody noticed - needs changes to export code and cloze handling code to deal with the newlines - newline rewriting in filterNode() is likely fragile - may revisit post 2.1
This commit is contained in:
parent
c13b19820b
commit
554ff3d8d2
@ -135,10 +135,6 @@ lapses=?, left=?, odue=?, odid=?, did=? where id = ?""",
|
||||
else:
|
||||
args = tuple()
|
||||
self._qa = self.col._renderQA(data, *args)
|
||||
if m.get("prewrap", False):
|
||||
wsdiv = "<div style='white-space:pre-wrap;'>{}</div>"
|
||||
self._qa['q'] = wsdiv.format(self._qa['q'])
|
||||
self._qa['a'] = wsdiv.format(self._qa['a'])
|
||||
return self._qa
|
||||
|
||||
def note(self, reload=False):
|
||||
|
@ -297,14 +297,11 @@ class Editor:
|
||||
self.web.setFocus()
|
||||
runHook("loadNote", self)
|
||||
|
||||
self.web.evalWithCallback("setFields(%s, %s); setFonts(%s); focusField(%s)" % (
|
||||
json.dumps(data), json.dumps(self.prewrapMode()),
|
||||
self.web.evalWithCallback("setFields(%s); setFonts(%s); focusField(%s)" % (
|
||||
json.dumps(data),
|
||||
json.dumps(self.fonts()), json.dumps(focusTo)),
|
||||
oncallback)
|
||||
|
||||
def prewrapMode(self):
|
||||
return self.note.model().get('prewrap', False)
|
||||
|
||||
def fonts(self):
|
||||
return [(f['font'], f['size'], f['rtl'])
|
||||
for f in self.note.model()['flds']]
|
||||
@ -616,10 +613,9 @@ to a cloze type first, via Edit>Change Note Type."""))
|
||||
for node in doc(tag):
|
||||
node.decompose()
|
||||
|
||||
if not self.prewrapMode():
|
||||
# convert p tags to divs
|
||||
for node in doc("p"):
|
||||
node.name = "div"
|
||||
# convert p tags to divs
|
||||
for node in doc("p"):
|
||||
node.name = "div"
|
||||
|
||||
for tag in doc("img"):
|
||||
try:
|
||||
|
@ -110,7 +110,6 @@ class Models(QDialog):
|
||||
frm.latexsvg.setChecked(self.model.get("latexsvg", False))
|
||||
frm.latexHeader.setText(self.model['latexPre'])
|
||||
frm.latexFooter.setText(self.model['latexPost'])
|
||||
frm.newStyleWhitespace.setChecked(self.model.get("prewrap", False))
|
||||
d.setWindowTitle(_("Options for %s") % self.model['name'])
|
||||
frm.buttonBox.helpRequested.connect(lambda: openHelp("latex"))
|
||||
restoreGeom(d, "modelopts")
|
||||
@ -119,7 +118,6 @@ class Models(QDialog):
|
||||
self.model['latexsvg'] = frm.latexsvg.isChecked()
|
||||
self.model['latexPre'] = str(frm.latexHeader.toPlainText())
|
||||
self.model['latexPost'] = str(frm.latexFooter.toPlainText())
|
||||
self.model['prewrap'] = frm.newStyleWhitespace.isChecked()
|
||||
|
||||
def saveModel(self):
|
||||
self.mm.save(self.model)
|
||||
|
@ -64,33 +64,6 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="newStyleWhitespace">
|
||||
<property name="text">
|
||||
<string>New style whitespace handling (EXPERIMENTAL)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -64,10 +64,6 @@ body {
|
||||
border-bottom: 3px solid #000;
|
||||
}
|
||||
|
||||
.prewrap {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
#fields {
|
||||
margin-top: 35px;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
var currentField = null;
|
||||
var changeTimer = null;
|
||||
var dropTarget = null;
|
||||
var prewrapMode = false;
|
||||
|
||||
String.prototype.format = function () {
|
||||
var args = arguments;
|
||||
@ -27,12 +26,6 @@ function onKey() {
|
||||
currentField.blur();
|
||||
return;
|
||||
}
|
||||
// catch enter key in prewrap mode
|
||||
if (window.event.which === 13 && prewrapMode) {
|
||||
window.event.preventDefault();
|
||||
insertNewline();
|
||||
return;
|
||||
}
|
||||
// shift+tab goes to previous field
|
||||
if (navigator.platform === "MacIntel" &&
|
||||
window.event.which === 9 && window.event.shiftKey) {
|
||||
@ -264,7 +257,7 @@ function onCutOrCopy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function setFields(fields, prewrap) {
|
||||
function setFields(fields) {
|
||||
var txt = "";
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var n = fields[i][0];
|
||||
@ -282,10 +275,6 @@ function setFields(fields, prewrap) {
|
||||
}
|
||||
$("#fields").html("<table cellpadding=0 width=100%>" + txt + "</table>");
|
||||
maybeDisableButtons();
|
||||
prewrapMode = prewrap;
|
||||
if (prewrap) {
|
||||
$(".field").addClass("prewrap");
|
||||
}
|
||||
}
|
||||
|
||||
function setBackgrounds(cols) {
|
||||
@ -345,29 +334,6 @@ allowedTags["TD"] = {"attrs": ["COLSPAN", "ROWSPAN"]};
|
||||
allowedTags["TH"] = {"attrs": ["COLSPAN", "ROWSPAN"]};
|
||||
allowedTags["IMG"] = {"attrs": ["SRC"]};
|
||||
|
||||
var blockRegex = /^(address|blockquote|br|center|div|dl|h[1-6]|hr|ol|p|pre|table|ul|dd|dt|li|tbody|td|tfoot|th|thead|tr)$/i;
|
||||
function isBlockLevel(n) {
|
||||
return blockRegex.test(n.nodeName);
|
||||
}
|
||||
|
||||
function isInlineElement(n) {
|
||||
return n && !isBlockLevel(n);
|
||||
}
|
||||
|
||||
function convertDivToNewline(node, isParagraph) {
|
||||
var html = node.innerHTML;
|
||||
if (isInlineElement(node.previousSibling) && html) {
|
||||
html = "\n" + html;
|
||||
}
|
||||
if (isInlineElement(node.nextSibling)) {
|
||||
html += "\n";
|
||||
}
|
||||
if (isParagraph) {
|
||||
html += "\n";
|
||||
}
|
||||
node.outerHTML = html;
|
||||
}
|
||||
|
||||
// filtering from another field
|
||||
var filterInternalNode = function (node) {
|
||||
if (node.tagName === "SPAN") {
|
||||
@ -385,15 +351,6 @@ var filterInternalNode = function (node) {
|
||||
var filterNode = function (node) {
|
||||
// text node?
|
||||
if (node.nodeType === 3) {
|
||||
if (prewrapMode) {
|
||||
// collapse standard whitespace
|
||||
var val = node.nodeValue.replace(/^[ \r\n\t]+$/g, " ");
|
||||
|
||||
// non-breaking spaces can be represented as normal spaces
|
||||
val = val.replace(/ |\u00a0/g, " ");
|
||||
|
||||
node.nodeValue = val;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -420,12 +377,6 @@ var filterNode = function (node) {
|
||||
} else {
|
||||
node.outerHTML = node.innerHTML;
|
||||
}
|
||||
} else if (prewrapMode && node.tagName === "BR") {
|
||||
node.outerHTML = "\n";
|
||||
} else if (prewrapMode && node.tagName === "DIV") {
|
||||
convertBlockToNewline(node, false);
|
||||
} else if (prewrapMode && node.tagName === "P") {
|
||||
convertBlockToNewline(node, true);
|
||||
} else {
|
||||
// allowed, filter out attributes
|
||||
var toRemove = [];
|
||||
|
Loading…
Reference in New Issue
Block a user