Commit 15852c4a authored by Leon Arnott's avatar Leon Arnott
Browse files

Removed Section.updateEnchantments(), as it doesn't actually work as intended.

Section.updateEnchantments() was designed to keep all the enchantments in a section up-to-date even in the face of nebulous DOM manipulations to the passage. However, it turns out that few situations rely on it, and its presence caused some bugs where multiple enchantments refer to the same hook or text. So, I'm trying to go on without it.

Also fixed a bug where the header syntax didn't work on the first line of a passage.
parent 90f6b08800bc
......@@ -48,8 +48,8 @@ define(['utils/hookutils', 'jquery'],function(HookUtils, $) {
{jQuery} The <tw-hook> element to manipulate.
*/
forEach: function(fn) {
return jQueryCall.call(this, "each", function() {
fn($(this));
return jQueryCall.call(this, "each", function(i) {
fn($(this), i);
});
},
......
......@@ -48,7 +48,7 @@ define(['jquery', 'utils/hookutils'],function($, HookUtils) {
/*
Now, call the passed function on all of the <tw-pseudo-hook> elements.
*/
e.each(function(){ fn($(this)); });
e.each(function(i){ fn($(this), i); });
/*
Having done that, we now remove the <tw-pseudo-hook> elements and normalize
the text nodes that were split up as a result of the
......
......@@ -233,7 +233,7 @@ define(['jquery', 'utils', 'macros', 'datatypes/hookset', 'datatypes/changercomm
+ enchantDesc.classList +"'>");
/*
It's a little odd that the generated wrapper must be retrieved in
this roundabout fashion, but oh well. That's how jQuery works.
this roundabout fashion, but oh well.
*/
wrapping = e.parent();
......@@ -254,9 +254,6 @@ define(['jquery', 'utils', 'macros', 'datatypes/hookset', 'datatypes/changercomm
if (enchantDesc.once) {
/*
Remove this enchantment from the Section's list.
This must be done now, so that renderInto(), when
it calls updateEnchantments(), will not re-enchant
the scope using this very enchantment.
*/
index = desc.section.enchantments.indexOf(enchantData);
desc.section.enchantments.splice(index,1);
......
......@@ -166,7 +166,7 @@
/*
Markdown setext headers conflict with the hr syntax, and are thus gone.
*/
heading = "\n" + ws + "(#{1,6})" + ws + "([^\\n]+?)" + ws + "#*" + ws + eol,
heading = either("^","\n") + ws + "(#{1,6})" + ws + "([^\\n]+?)" + ws + "#*" + ws + eol,
/*
New text alignment syntax.
......
......@@ -542,35 +542,8 @@ function($, Utils, Selectors, Renderer, Environ, Story, State, HookUtils, HookSe
The data is purely temporary and can be safely discarded.
*/
this.stack.shift();
/*
Finally, update the enchantments now that the DOM is modified.
TODO: this really should not be run more than once per frame,
so some way of throttled debouncing is necessary.
*/
this.updateEnchantments();
},
/**
Updates all enchantments in the section. Should be called after every
DOM manipulation within the section (such as, at the end of .render()).
@method updateEnchantments
*/
updateEnchantments: function () {
this.enchantments.forEach(function(e) {
/*
This first method removes old <tw-enchantment> elements...
*/
e.refreshScope();
/*
...and this one adds new ones.
*/
e.enchantScope();
});
}
};
return Object.preventExtensions(Section);
......
......@@ -200,8 +200,11 @@ define(['utils'], function(Utils) {
with the other.
*/
if (Array.isArray(l) && Array.isArray(r)) {
if (l.length < r.length) {
return is(r, l);
/*
A quick check: if they vary in length, they already fail.
*/
if (l.length !== r.length) {
return false;
}
return l.every(function(element, index) {
return is(r[index], element);
......@@ -217,6 +220,10 @@ define(['utils'], function(Utils) {
if (l instanceof Set && r instanceof Set) {
return is(Array.from(l.values()), Array.from(r.values()));
}
/*
For TwineScript built-ins, use the TwineScript_is() method to determine
uniqueness.
*/
if (l && typeof l.TwineScript_is === "function") {
return l.TwineScript_is(r);
}
......
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