Browse Source

Merge pull request #156 in FUI/fineui from ~GUY/fineui:master to master

* commit '4e4066beddbf3deb15e5cb45d9969091c9b063fd':
  shouldUpdate生命周期
  update
  update
  code.editor的问题
master
guy 7 years ago
parent
commit
81d9f0167d
  1. 5
      bi/base.js
  2. 24
      bi/core.js
  3. 5
      demo/js/core/abstract/demo.virtual_group.js
  4. 5
      dist/base.js
  5. 29
      dist/bundle.js
  6. 68
      dist/bundle.min.js
  7. 24
      dist/core.js
  8. 5
      dist/demo.js
  9. 5
      src/base/single/editor/editor.code.js
  10. 2
      src/core/widget.js
  11. 22
      src/core/wrapper/layout.js

5
bi/base.js

@ -19045,6 +19045,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
lineWrapping: true, lineWrapping: true,
lineNumbers: false, lineNumbers: false,
readOnly: o.readOnly, readOnly: o.readOnly,
//解决插入字段由括号或其他特殊字符包围时分裂的bug
specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/ specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/
}); });
o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height"); o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height");
@ -19130,6 +19131,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
var value = param; var value = param;
param = this.options.paramFormatter(param); param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
//解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下
this.editor.replaceSelection('\u200b' + param + '\u200b'); this.editor.replaceSelection('\u200b' + param + '\u200b');
var to = this.editor.getCursor(); var to = this.editor.getCursor();
var options = {className: 'param', atomic: true}; var options = {className: 'param', atomic: true};
@ -19150,7 +19152,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
return this.editor.getValue("\n", function (line) { return this.editor.getValue("\n", function (line) {
var rawText = line.text, value = line.text, num = 0; var rawText = line.text, value = line.text, num = 0;
value.text = rawText; value.text = rawText;
_.forEach(line.markedSpans, function (i, ms) { //根据插入位置不同,line.markedSpan可能是乱序的
_.forEach(_.sortBy(line.markedSpans, "from"), function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "param": case "param":
case "error-param": case "error-param":

24
bi/core.js

@ -15570,6 +15570,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null, mounted: null,
shouldUpdate: null,
update: function () { update: function () {
}, },
@ -22584,6 +22586,17 @@ BI.Layout = BI.inherit(BI.Widget, {
}); });
}, },
shouldUpdateItem: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) {
return false;
}
var child = this._children[this._getChildName(index)];
if (!child.shouldUpdate) {
return null;
}
return child.shouldUpdate(this._getOptions(item)) === true;
},
updateItemAt: function (index, item) { updateItemAt: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) { if (index < 0 || index > this.options.items.length - 1) {
return; return;
@ -22676,7 +22689,8 @@ BI.Layout = BI.inherit(BI.Widget, {
}, },
patchItem: function (oldVnode, vnode, index) { patchItem: function (oldVnode, vnode, index) {
if (!this._compare(oldVnode, vnode)) { var shouldUpdate = this.shouldUpdateItem(index, vnode);
if (shouldUpdate === true || (shouldUpdate === null && !this._compare(oldVnode, vnode))) {
return this.updateItemAt(index, vnode); return this.updateItemAt(index, vnode);
} }
}, },
@ -22708,23 +22722,23 @@ BI.Layout = BI.inherit(BI.Widget, {
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) { } else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) { } else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { } else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
insertBefore(oldStartVnode, oldEndVnode, true); insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) { } else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
insertBefore(oldEndVnode, oldStartVnode); insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];

5
demo/js/core/abstract/demo.virtual_group.js

@ -89,6 +89,11 @@ Demo.Item = BI.inherit(BI.Widget, {
} }
}, },
shouldUpdate: function (nextProps) {
var o = this.options;
return o.type !== nextProps.type || o.key !== nextProps.key || o.value !== nextProps.value;
},
update: function (item) { update: function (item) {
this.label.setText(item.value); this.label.setText(item.value);
console.log("更新了一项"); console.log("更新了一项");

5
dist/base.js vendored

@ -19045,6 +19045,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
lineWrapping: true, lineWrapping: true,
lineNumbers: false, lineNumbers: false,
readOnly: o.readOnly, readOnly: o.readOnly,
//解决插入字段由括号或其他特殊字符包围时分裂的bug
specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/ specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/
}); });
o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height"); o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height");
@ -19130,6 +19131,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
var value = param; var value = param;
param = this.options.paramFormatter(param); param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
//解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下
this.editor.replaceSelection('\u200b' + param + '\u200b'); this.editor.replaceSelection('\u200b' + param + '\u200b');
var to = this.editor.getCursor(); var to = this.editor.getCursor();
var options = {className: 'param', atomic: true}; var options = {className: 'param', atomic: true};
@ -19150,7 +19152,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
return this.editor.getValue("\n", function (line) { return this.editor.getValue("\n", function (line) {
var rawText = line.text, value = line.text, num = 0; var rawText = line.text, value = line.text, num = 0;
value.text = rawText; value.text = rawText;
_.forEach(line.markedSpans, function (i, ms) { //根据插入位置不同,line.markedSpan可能是乱序的
_.forEach(_.sortBy(line.markedSpans, "from"), function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "param": case "param":
case "error-param": case "error-param":

29
dist/bundle.js vendored

@ -14415,6 +14415,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null, mounted: null,
shouldUpdate: null,
update: function () { update: function () {
}, },
@ -19798,6 +19800,17 @@ BI.Layout = BI.inherit(BI.Widget, {
}); });
}, },
shouldUpdateItem: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) {
return false;
}
var child = this._children[this._getChildName(index)];
if (!child.shouldUpdate) {
return null;
}
return child.shouldUpdate(this._getOptions(item)) === true;
},
updateItemAt: function (index, item) { updateItemAt: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) { if (index < 0 || index > this.options.items.length - 1) {
return; return;
@ -19890,7 +19903,8 @@ BI.Layout = BI.inherit(BI.Widget, {
}, },
patchItem: function (oldVnode, vnode, index) { patchItem: function (oldVnode, vnode, index) {
if (!this._compare(oldVnode, vnode)) { var shouldUpdate = this.shouldUpdateItem(index, vnode);
if (shouldUpdate === true || (shouldUpdate === null && !this._compare(oldVnode, vnode))) {
return this.updateItemAt(index, vnode); return this.updateItemAt(index, vnode);
} }
}, },
@ -19922,23 +19936,23 @@ BI.Layout = BI.inherit(BI.Widget, {
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) { } else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) { } else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { } else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
insertBefore(oldStartVnode, oldEndVnode, true); insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) { } else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
insertBefore(oldEndVnode, oldStartVnode); insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
@ -48074,6 +48088,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
lineWrapping: true, lineWrapping: true,
lineNumbers: false, lineNumbers: false,
readOnly: o.readOnly, readOnly: o.readOnly,
//解决插入字段由括号或其他特殊字符包围时分裂的bug
specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/ specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/
}); });
o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height"); o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height");
@ -48159,6 +48174,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
var value = param; var value = param;
param = this.options.paramFormatter(param); param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
//解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下
this.editor.replaceSelection('\u200b' + param + '\u200b'); this.editor.replaceSelection('\u200b' + param + '\u200b');
var to = this.editor.getCursor(); var to = this.editor.getCursor();
var options = {className: 'param', atomic: true}; var options = {className: 'param', atomic: true};
@ -48179,7 +48195,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
return this.editor.getValue("\n", function (line) { return this.editor.getValue("\n", function (line) {
var rawText = line.text, value = line.text, num = 0; var rawText = line.text, value = line.text, num = 0;
value.text = rawText; value.text = rawText;
_.forEach(line.markedSpans, function (i, ms) { //根据插入位置不同,line.markedSpan可能是乱序的
_.forEach(_.sortBy(line.markedSpans, "from"), function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "param": case "param":
case "error-param": case "error-param":

68
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

24
dist/core.js vendored

@ -14364,6 +14364,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null, mounted: null,
shouldUpdate: null,
update: function () { update: function () {
}, },
@ -19747,6 +19749,17 @@ BI.Layout = BI.inherit(BI.Widget, {
}); });
}, },
shouldUpdateItem: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) {
return false;
}
var child = this._children[this._getChildName(index)];
if (!child.shouldUpdate) {
return null;
}
return child.shouldUpdate(this._getOptions(item)) === true;
},
updateItemAt: function (index, item) { updateItemAt: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) { if (index < 0 || index > this.options.items.length - 1) {
return; return;
@ -19839,7 +19852,8 @@ BI.Layout = BI.inherit(BI.Widget, {
}, },
patchItem: function (oldVnode, vnode, index) { patchItem: function (oldVnode, vnode, index) {
if (!this._compare(oldVnode, vnode)) { var shouldUpdate = this.shouldUpdateItem(index, vnode);
if (shouldUpdate === true || (shouldUpdate === null && !this._compare(oldVnode, vnode))) {
return this.updateItemAt(index, vnode); return this.updateItemAt(index, vnode);
} }
}, },
@ -19871,23 +19885,23 @@ BI.Layout = BI.inherit(BI.Widget, {
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) { } else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) { } else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { } else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
insertBefore(oldStartVnode, oldEndVnode, true); insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) { } else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
insertBefore(oldEndVnode, oldStartVnode); insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];

5
dist/demo.js vendored

@ -7561,6 +7561,11 @@ Demo.Item = BI.inherit(BI.Widget, {
} }
}, },
shouldUpdate: function (nextProps) {
var o = this.options;
return o.type !== nextProps.type || o.key !== nextProps.key || o.value !== nextProps.value;
},
update: function (item) { update: function (item) {
this.label.setText(item.value); this.label.setText(item.value);
console.log("更新了一项"); console.log("更新了一项");

5
src/base/single/editor/editor.code.js

@ -26,6 +26,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
lineWrapping: true, lineWrapping: true,
lineNumbers: false, lineNumbers: false,
readOnly: o.readOnly, readOnly: o.readOnly,
//解决插入字段由括号或其他特殊字符包围时分裂的bug
specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/ specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/
}); });
o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height"); o.lineHeight === 1 ? this.element.addClass("codemirror-low-line-height") : this.element.addClass("codemirror-high-line-height");
@ -111,6 +112,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
var value = param; var value = param;
param = this.options.paramFormatter(param); param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
//解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下
this.editor.replaceSelection('\u200b' + param + '\u200b'); this.editor.replaceSelection('\u200b' + param + '\u200b');
var to = this.editor.getCursor(); var to = this.editor.getCursor();
var options = {className: 'param', atomic: true}; var options = {className: 'param', atomic: true};
@ -131,7 +133,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
return this.editor.getValue("\n", function (line) { return this.editor.getValue("\n", function (line) {
var rawText = line.text, value = line.text, num = 0; var rawText = line.text, value = line.text, num = 0;
value.text = rawText; value.text = rawText;
_.forEach(line.markedSpans, function (i, ms) { //根据插入位置不同,line.markedSpan可能是乱序的
_.forEach(_.sortBy(line.markedSpans, "from"), function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "param": case "param":
case "error-param": case "error-param":

2
src/core/widget.js

@ -34,6 +34,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null, mounted: null,
shouldUpdate: null,
update: function () { update: function () {
}, },

22
src/core/wrapper/layout.js

@ -256,6 +256,17 @@ BI.Layout = BI.inherit(BI.Widget, {
}); });
}, },
shouldUpdateItem: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) {
return false;
}
var child = this._children[this._getChildName(index)];
if (!child.shouldUpdate) {
return null;
}
return child.shouldUpdate(this._getOptions(item)) === true;
},
updateItemAt: function (index, item) { updateItemAt: function (index, item) {
if (index < 0 || index > this.options.items.length - 1) { if (index < 0 || index > this.options.items.length - 1) {
return; return;
@ -348,7 +359,8 @@ BI.Layout = BI.inherit(BI.Widget, {
}, },
patchItem: function (oldVnode, vnode, index) { patchItem: function (oldVnode, vnode, index) {
if (!this._compare(oldVnode, vnode)) { var shouldUpdate = this.shouldUpdateItem(index, vnode);
if (shouldUpdate === true || (shouldUpdate === null && !this._compare(oldVnode, vnode))) {
return this.updateItemAt(index, vnode); return this.updateItemAt(index, vnode);
} }
}, },
@ -380,23 +392,23 @@ BI.Layout = BI.inherit(BI.Widget, {
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) { } else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) { } else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { } else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated; updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
children[this._getChildName(oldStartIdx)] = this._children[this._getChildName(oldStartIdx)]; children[oldStartVnode.key == null ? this._getChildName(oldStartIdx) : oldStartVnode.key] = this._children[this._getChildName(oldStartIdx)];
insertBefore(oldStartVnode, oldEndVnode, true); insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx]; oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx]; newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) { } else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated; updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
children[this._getChildName(oldEndIdx)] = this._children[this._getChildName(oldEndIdx)]; children[oldEndVnode.key == null ? this._getChildName(oldEndIdx) : oldEndVnode.key] = this._children[this._getChildName(oldEndIdx)];
insertBefore(oldEndVnode, oldStartVnode); insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx]; oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx]; newStartVnode = newCh[++newStartIdx];

Loading…
Cancel
Save