Skip to content

Commit 6f56782

Browse files
committed
actually the previous fix was not fixing: now it does
1 parent 60aba2d commit 6f56782

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

cjs/utils.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
const Map = (require('@ungap/essential-map'));
33

44
const append = (get, parent, children, start, end, before) => {
5-
while (start < end)
6-
parent.insertBefore(get(children[start++], 1), before);
5+
const isSelect = 'selectedIndex' in parent;
6+
let selectedIndex = -1;
7+
while (start < end) {
8+
const child = get(children[start], 1);
9+
if (isSelect && selectedIndex < 0 && child.selected)
10+
selectedIndex = start;
11+
parent.insertBefore(child, before);
12+
start++;
13+
}
14+
if (isSelect && -1 < selectedIndex)
15+
parent.selectedIndex = selectedIndex;
716
};
817
exports.append = append;
918

esm/utils.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import Map from '@ungap/essential-map';
22

33
export const append = (get, parent, children, start, end, before) => {
4-
while (start < end)
5-
parent.insertBefore(get(children[start++], 1), before);
4+
const isSelect = 'selectedIndex' in parent;
5+
let selectedIndex = -1;
6+
while (start < end) {
7+
const child = get(children[start], 1);
8+
if (isSelect && selectedIndex < 0 && child.selected)
9+
selectedIndex = start;
10+
parent.insertBefore(child, before);
11+
start++;
12+
}
13+
if (isSelect && -1 < selectedIndex)
14+
parent.selectedIndex = selectedIndex;
615
};
716

817
export const eqeq = (a, b) => a == b;

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ try {
3939
var Map$1 = self.Map;
4040

4141
var append = function append(get, parent, children, start, end, before) {
42+
var isSelect = 'selectedIndex' in parent;
43+
var selectedIndex = -1;
4244
while (start < end) {
43-
parent.insertBefore(get(children[start++], 1), before);
45+
var child = get(children[start], 1);
46+
if (isSelect && selectedIndex < 0 && child.selected) selectedIndex = start;
47+
parent.insertBefore(child, before);
48+
start++;
4449
}
50+
if (isSelect && -1 < selectedIndex) parent.selectedIndex = selectedIndex;
4551
};
4652

4753
var eqeq = function eqeq(a, b) {

min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,26 @@ newState = domdiff(
12181218
);
12191219
console.timeEnd('reversed');
12201220

1221+
document.body.selectedIndex = -1;
1222+
newState = domdiff(
1223+
document.body,
1224+
newState,
1225+
[]
1226+
);
1227+
1228+
var option = document.createTextNode('b');
1229+
option.selected = true;
1230+
newState = domdiff(
1231+
document.body,
1232+
newState,
1233+
[
1234+
document.createTextNode('a'),
1235+
option,
1236+
document.createTextNode('c')
1237+
]
1238+
);
1239+
1240+
console.assert(document.body.selectedIndex === 1, 'selectedIndex is OK');
12211241
// */
12221242

12231243
tressa.end();

0 commit comments

Comments
 (0)