Change: drop .last and .rotate

This commit is contained in:
eight 2018-10-14 17:56:16 +08:00
parent 85e70491e4
commit d4ddfcc713
3 changed files with 4 additions and 20 deletions

View File

@ -138,10 +138,11 @@ const cmFactory = (() => {
} }
function autocompleteOnTyping(cm, [info], debounced) { function autocompleteOnTyping(cm, [info], debounced) {
const lastLine = info.text[info.text.length - 1];
if ( if (
cm.state.completionActive || cm.state.completionActive ||
info.origin && !info.origin.includes('input') || info.origin && !info.origin.includes('input') ||
!info.text.last !lastLine
) { ) {
return; return;
} }
@ -153,7 +154,7 @@ const cmFactory = (() => {
debounce(autocompleteOnTyping, 100, cm, [info], true); debounce(autocompleteOnTyping, 100, cm, [info], true);
return; return;
} }
if (info.text.last.match(/[-a-z!]+$/i)) { if (lastLine.match(/[-a-z!]+$/i)) {
cm.state.autocompletePicked = false; cm.state.autocompletePicked = false;
cm.options.hintOptions.completeSingle = false; cm.options.hintOptions.completeSingle = false;
cm.execCommand('autocomplete'); cm.execCommand('autocomplete');

View File

@ -476,6 +476,7 @@ function createSectionsEditor(style) {
function removeSection(section) { function removeSection(section) {
if (sections.every(s => s.isRemoved() || s === section)) { if (sections.every(s => s.isRemoved() || s === section)) {
// TODO: hide remove button when `#sections[data-section-count=1]`
throw new Error('Cannot remove last section'); throw new Error('Cannot remove last section');
} }
if (section.cm.isBlank()) { if (section.cm.isBlank()) {
@ -534,7 +535,6 @@ function createSectionsEditor(style) {
container.appendChild(section.el); container.appendChild(section.el);
} }
section.render(); section.render();
// maximizeCodeHeight(section.el);
updateSectionOrder(); updateSectionOrder();
section.onChange(updateLivePreview); section.onChange(updateLivePreview);
updateLivePreview(); updateLivePreview();

View File

@ -13,23 +13,6 @@ if (!/^Win\d+/.test(navigator.platform)) {
NodeList.prototype[method] = Array.prototype[method]; NodeList.prototype[method] = Array.prototype[method];
}); });
// eslint-disable-next-line no-extend-native
Object.defineProperties(Array.prototype, {
last: {
get() {
return this[this.length - 1];
},
},
rotate: {
value: function (amount) {
// negative amount == rotate left
const r = this.slice(-amount, this.length);
Array.prototype.push.apply(r, this.slice(0, this.length - r.length));
return r;
},
},
});
// polyfill for old browsers to enable [...results] and for-of // polyfill for old browsers to enable [...results] and for-of
for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection]) { for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection]) {
if (!type.prototype[Symbol.iterator]) { if (!type.prototype[Symbol.iterator]) {