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:
Damien Elmes 2017-10-25 19:18:00 +10:00
parent c13b19820b
commit 554ff3d8d2
6 changed files with 6 additions and 96 deletions

View File

@ -135,10 +135,6 @@ lapses=?, left=?, odue=?, odid=?, did=? where id = ?""",
else: else:
args = tuple() args = tuple()
self._qa = self.col._renderQA(data, *args) 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 return self._qa
def note(self, reload=False): def note(self, reload=False):

View File

@ -297,14 +297,11 @@ class Editor:
self.web.setFocus() self.web.setFocus()
runHook("loadNote", self) runHook("loadNote", self)
self.web.evalWithCallback("setFields(%s, %s); setFonts(%s); focusField(%s)" % ( self.web.evalWithCallback("setFields(%s); setFonts(%s); focusField(%s)" % (
json.dumps(data), json.dumps(self.prewrapMode()), json.dumps(data),
json.dumps(self.fonts()), json.dumps(focusTo)), json.dumps(self.fonts()), json.dumps(focusTo)),
oncallback) oncallback)
def prewrapMode(self):
return self.note.model().get('prewrap', False)
def fonts(self): def fonts(self):
return [(f['font'], f['size'], f['rtl']) return [(f['font'], f['size'], f['rtl'])
for f in self.note.model()['flds']] 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): for node in doc(tag):
node.decompose() node.decompose()
if not self.prewrapMode(): # convert p tags to divs
# convert p tags to divs for node in doc("p"):
for node in doc("p"): node.name = "div"
node.name = "div"
for tag in doc("img"): for tag in doc("img"):
try: try:

View File

@ -110,7 +110,6 @@ class Models(QDialog):
frm.latexsvg.setChecked(self.model.get("latexsvg", False)) frm.latexsvg.setChecked(self.model.get("latexsvg", False))
frm.latexHeader.setText(self.model['latexPre']) frm.latexHeader.setText(self.model['latexPre'])
frm.latexFooter.setText(self.model['latexPost']) frm.latexFooter.setText(self.model['latexPost'])
frm.newStyleWhitespace.setChecked(self.model.get("prewrap", False))
d.setWindowTitle(_("Options for %s") % self.model['name']) d.setWindowTitle(_("Options for %s") % self.model['name'])
frm.buttonBox.helpRequested.connect(lambda: openHelp("latex")) frm.buttonBox.helpRequested.connect(lambda: openHelp("latex"))
restoreGeom(d, "modelopts") restoreGeom(d, "modelopts")
@ -119,7 +118,6 @@ class Models(QDialog):
self.model['latexsvg'] = frm.latexsvg.isChecked() self.model['latexsvg'] = frm.latexsvg.isChecked()
self.model['latexPre'] = str(frm.latexHeader.toPlainText()) self.model['latexPre'] = str(frm.latexHeader.toPlainText())
self.model['latexPost'] = str(frm.latexFooter.toPlainText()) self.model['latexPost'] = str(frm.latexFooter.toPlainText())
self.model['prewrap'] = frm.newStyleWhitespace.isChecked()
def saveModel(self): def saveModel(self):
self.mm.save(self.model) self.mm.save(self.model)

View File

@ -64,33 +64,6 @@
</item> </item>
</layout> </layout>
</widget> </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> </widget>
</item> </item>
<item> <item>

View File

@ -64,10 +64,6 @@ body {
border-bottom: 3px solid #000; border-bottom: 3px solid #000;
} }
.prewrap {
white-space: pre-wrap;
}
#fields { #fields {
margin-top: 35px; margin-top: 35px;
} }

View File

@ -1,7 +1,6 @@
var currentField = null; var currentField = null;
var changeTimer = null; var changeTimer = null;
var dropTarget = null; var dropTarget = null;
var prewrapMode = false;
String.prototype.format = function () { String.prototype.format = function () {
var args = arguments; var args = arguments;
@ -27,12 +26,6 @@ function onKey() {
currentField.blur(); currentField.blur();
return; return;
} }
// catch enter key in prewrap mode
if (window.event.which === 13 && prewrapMode) {
window.event.preventDefault();
insertNewline();
return;
}
// shift+tab goes to previous field // shift+tab goes to previous field
if (navigator.platform === "MacIntel" && if (navigator.platform === "MacIntel" &&
window.event.which === 9 && window.event.shiftKey) { window.event.which === 9 && window.event.shiftKey) {
@ -264,7 +257,7 @@ function onCutOrCopy() {
return true; return true;
} }
function setFields(fields, prewrap) { function setFields(fields) {
var txt = ""; var txt = "";
for (var i = 0; i < fields.length; i++) { for (var i = 0; i < fields.length; i++) {
var n = fields[i][0]; var n = fields[i][0];
@ -282,10 +275,6 @@ function setFields(fields, prewrap) {
} }
$("#fields").html("<table cellpadding=0 width=100%>" + txt + "</table>"); $("#fields").html("<table cellpadding=0 width=100%>" + txt + "</table>");
maybeDisableButtons(); maybeDisableButtons();
prewrapMode = prewrap;
if (prewrap) {
$(".field").addClass("prewrap");
}
} }
function setBackgrounds(cols) { function setBackgrounds(cols) {
@ -345,29 +334,6 @@ allowedTags["TD"] = {"attrs": ["COLSPAN", "ROWSPAN"]};
allowedTags["TH"] = {"attrs": ["COLSPAN", "ROWSPAN"]}; allowedTags["TH"] = {"attrs": ["COLSPAN", "ROWSPAN"]};
allowedTags["IMG"] = {"attrs": ["SRC"]}; 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 // filtering from another field
var filterInternalNode = function (node) { var filterInternalNode = function (node) {
if (node.tagName === "SPAN") { if (node.tagName === "SPAN") {
@ -385,15 +351,6 @@ var filterInternalNode = function (node) {
var filterNode = function (node) { var filterNode = function (node) {
// text node? // text node?
if (node.nodeType === 3) { 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(/&nbsp;|\u00a0/g, " ");
node.nodeValue = val;
}
return; return;
} }
@ -420,12 +377,6 @@ var filterNode = function (node) {
} else { } else {
node.outerHTML = node.innerHTML; 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 { } else {
// allowed, filter out attributes // allowed, filter out attributes
var toRemove = []; var toRemove = [];