Skip to content

Commit fee2bb7

Browse files
Narciso Jaramillomarijnh
authored andcommitted
Unit test for line widget focus restoration
1 parent 0b97e94 commit fee2bb7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

test/index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
font-weight: bold;
2626
white-space: pre;
2727
}
28+
#testground {
29+
visibility: hidden;
30+
}
31+
#testground.offscreen {
32+
visibility: visible;
33+
position: absolute;
34+
left: -10000px;
35+
top: -10000px;
36+
}
2837
.CodeMirror { border: 1px solid black; }
2938
</style>
3039
</head>
@@ -39,7 +48,7 @@ <h1>CodeMirror: Test Suite</h1>
3948
<p id=status>Please enable JavaScript...</p>
4049
<div id=output></div>
4150

42-
<div style="visibility: hidden" id=testground></div>
51+
<div id=testground></div>
4352

4453
<script src="driver.js"></script>
4554
<script src="test.js"></script>

test/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,22 @@ testCM("lineWidgets", function(cm) {
971971
eqPos(cm.getCursor(), {line: 1, ch: 1});
972972
});
973973

974+
testCM("lineWidgetFocus", function(cm) {
975+
var place = document.getElementById("testground");
976+
place.className = "offscreen";
977+
try {
978+
addDoc(cm, 500, 10);
979+
var node = document.createElement("input");
980+
var widget = cm.addLineWidget(1, node);
981+
node.focus();
982+
eq(document.activeElement, node);
983+
cm.replaceRange("new stuff", {line: 1, ch: 0});
984+
eq(document.activeElement, node);
985+
} finally {
986+
place.className = "";
987+
}
988+
});
989+
974990
testCM("getLineNumber", function(cm) {
975991
addDoc(cm, 2, 20);
976992
var h1 = cm.getLineHandle(1);

0 commit comments

Comments
 (0)