Skip to content

Commit fd08758

Browse files
committed
Finish tests; make code work with all tests
1 parent 672a45c commit fd08758

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

code-input.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ code-input {
88
display: block;
99
overflow-y: auto;
1010
overflow-x: auto;
11-
1211
position: relative;
1312
top: 0;
1413
left: 0;
@@ -17,13 +16,13 @@ code-input {
1716
margin: 8px;
1817
--padding: 16px;
1918
height: 250px;
20-
font-size: normal;
19+
font-size: inherit;
2120
font-family: monospace;
2221
line-height: 1.5; /* Inherited to child elements */
2322
tab-size: 2;
2423
caret-color: darkgrey;
2524
white-space: pre;
26-
padding: 0!important; /* Use --padding */
25+
padding: 0!important; /* Use --padding to set the code-input element's padding */
2726
display: grid;
2827
grid-template-columns: 100%;
2928
grid-template-rows: 100%;
@@ -48,6 +47,7 @@ code-input textarea, code-input:not(.code-input_pre-element-styled) pre code, co
4847
resize: none;
4948
grid-row: 1;
5049
grid-column: 1;
50+
display: block;
5151
}
5252
code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_pre-element-styled pre {
5353
height: max-content;

plugins/autocomplete.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ codeInput.plugins.Autocomplete = class extends codeInput.Plugin {
4242
}
4343

4444
let textarea = codeInput.textareaElement;
45-
textarea.addEventListener("input", this.updatePopup.bind(this, codeInput, false)); // Override this+args in bind - not just scrolling
46-
textarea.addEventListener("click", this.updatePopup.bind(this, codeInput, false)); // Override this+args in bind - not just scrolling
47-
textarea.addEventListener("scroll", this.updatePopup.bind(this, codeInput, true)); // Override this+args in bind - just scrolling
45+
textarea.addEventListener("input", () => { this.updatePopup(codeInput, false)});
46+
textarea.addEventListener("click", () => { this.updatePopup(codeInput, false)});
4847
}
4948
/**
5049
* Return the coordinates of the caret in a code-input

plugins/go-to-line.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ codeInput.plugins.GoToLine = class extends codeInput.Plugin {
3333
const querySplitByColons = dialog.input.value.split(':');
3434
if(querySplitByColons.length > 2) return dialog.input.classList.add('code-input_go-to_error');
3535

36-
3736
if (event.key == 'Escape') return this.cancelPrompt(dialog, event);
3837

3938
if (dialog.input.value) {
@@ -62,6 +61,7 @@ codeInput.plugins.GoToLine = class extends codeInput.Plugin {
6261
/* Called with a dialog box keyup event to close and clear the dialog box */
6362
cancelPrompt(dialog, event) {
6463
let delay;
64+
console.log("Cancel", event);
6565
event.preventDefault();
6666
dialog.textarea.focus();
6767

@@ -98,7 +98,12 @@ codeInput.plugins.GoToLine = class extends codeInput.Plugin {
9898
dialog.textarea = textarea;
9999
dialog.input = input;
100100

101-
input.addEventListener('keyup', (event) => { this.checkPrompt(dialog, event); });
101+
input.addEventListener('keypress', (event) => {
102+
/* Stop enter from submitting form */
103+
if (event.key == 'Enter') event.preventDefault();
104+
});
105+
106+
input.addEventListener('keyup', (event) => { return this.checkPrompt(dialog, event); });
102107
cancel.addEventListener('click', (event) => { this.cancelPrompt(dialog, event); });
103108

104109
codeInput.appendChild(dialog);

tests/hljs.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@
3232
<script src="tester.js"></script>
3333
</head>
3434
<body>
35-
<!--TODO:
36-
Test with real Prism &
37-
Fix for hljs popup &
38-
(optional) In new branch, make Ctrl+F/H functionality like gotoline (finds in value, "string combinatorics" in pre code, Regex/case-insensitive accepted); Add tests for Ctrl+F/H
39-
(optional) In new branch, add one-line (input) option
40-
Make tester async function using await?
41-
Stop enter in go-to dialog from submitting form-->
4235
<h1>code-input Tester (highlight.js)</h1>
4336
<h4><a href="prism.html">Test for Prism.js</a></h4>
4437
<p>This page carries out automated tests for the code-input library to check that both the core components and the plugins work in some ways. It doesn't fully cover every scenario so you should test any code you change by hand, but it's good for quickly checking a wide range of functionality works.</p>

tests/prism.html

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ <h4><a href="hljs.html">Test for highlight.js</a></h4>
3939
<input type="submit" value="Search Google For Code"/>
4040
</form>
4141
<script>
42-
// codeInput.registerTemplate("code-editor", codeInput.templates.prism(Prism, [
43-
// new codeInput.plugins.AutoCloseBrackets(),
44-
// new codeInput.plugins.Autocomplete(function(popupElem, textarea, selectionEnd) {
45-
// if(textarea.value.substring(selectionEnd-5, selectionEnd) == "popup") {
46-
// // Show popup
47-
// popupElem.style.display = "block";
48-
// popupElem.innerHTML = "Here's your popup!";
49-
// } else {
50-
// popupElem.style.display = "none";
51-
// }
52-
// }),
53-
// new codeInput.plugins.GoToLine(),
54-
// new codeInput.plugins.Indent(true, 2),
55-
// new codeInput.plugins.SpecialChars(true),
56-
// ]));
5742
beginTest(false);
5843
</script>
5944
</body>

0 commit comments

Comments
 (0)