Skip to content

Commit 9bc938f

Browse files
authored
Merge pull request #76 from WebCoder49/performance-improvements
Improve library performance; Make scrolling use CSS rather than JS; Add unit tests and fix code following them.
2 parents 357cf43 + 79ce263 commit 9bc938f

20 files changed

+789
-456
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
* The `code-input` element should be easy to use with all popular syntax-highlighting libraries.
77
* Any modifications of `code-input` that would be useful for the open-source community but are not core to this functionality should be available as optional plugins in the `plugins` folder. Here's where most feature contributions will go.
88

9-
To keep this community productive and enjoyable, please [don't break the code of conduct here](https://github.com/WebCoder49/code-input/blob/main/CODE_OF_CONDUCT.md).
9+
We will generally *not* consider the following contributions:
10+
* Excess functionality and/or complexity in the main code-input files - these types of contributions should go in the plugin folder instead.
11+
* Issues that have been closed as not planned in the past (you can search the issue list to check), unless you bring a change that overcomes the reason they were not planned.
12+
13+
This said, if you're not sure whether your change will be accepted, please ask in an issue.
14+
15+
---
16+
17+
To keep this community productive and enjoyable, please [don't break our code of conduct](https://github.com/WebCoder49/code-input/blob/main/CODE_OF_CONDUCT.md).
1018

1119
---
1220
# Ways you could contribute:
@@ -22,4 +30,6 @@ Firstly, thank you for doing this! This is probably the most time consuming way
2230

2331
Please first open an issue if one doesn't already exist, and assign yourself to it. Then, [make a fork of the repo and submit a pull request](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
2432

33+
In the pull request, include the code updates for your feature / bug, and if you're adding a new feature make sure you comment your code so it's understandable to future contributors, and if you can, add unit tests for it in tests/tester.js. If you have any questions, just let me (@WebCoder49) know!
34+
2535
If an issue is open but already assigned to someone, it is probably already being worked on - you could still suggest a method of fixing it in the comments but shouldn't open a pull request as it would waste your time.

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ The next step is to set up a `template` to link `code-input` to your syntax-high
8888
* argument to the highlight function to be used for getting data- attribute values
8989
* and using the DOM for the code-input */,
9090

91-
true /* Optional - Leaving this as true uses code-input's default fix for preventing duplicate
92-
* results in Ctrl+F searching from the input and result elements, and setting this to false
93-
* indicates your highlighting function implements its own fix. The default fix works by moving
94-
* text content from elements to CSS ::before pseudo-elements after highlighting. */
95-
9691
[] // Array of plugins (see below)
9792
));
9893
```

code-input.css

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,54 @@
44

55

66
code-input {
7-
/* Allow other elems to be inside */
7+
/* Allow other elements to be inside */
8+
display: block;
9+
overflow-y: auto;
10+
overflow-x: auto;
811
position: relative;
912
top: 0;
1013
left: 0;
11-
display: block;
12-
/* Only scroll inside elems */
13-
overflow: hidden;
1414

1515
/* Normal inline styles */
1616
margin: 8px;
1717
--padding: 16px;
1818
height: 250px;
19-
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 */
26+
display: grid;
27+
grid-template-columns: 100%;
28+
grid-template-rows: 100%;
2729
}
2830

29-
code-input textarea, code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_pre-element-styled pre {
30-
/* Both elements need the same text and space styling so they are directly on top of each other */
31+
32+
code-input:not(.code-input_loaded) {
3133
margin: 0px!important;
34+
margin-bottom: calc(-1 * var(--padding, 16px))!important;
3235
padding: var(--padding, 16px)!important;
3336
border: 0;
34-
width: calc(100% - var(--padding, 16px) * 2);
35-
height: calc(100% - var(--padding, 16px) * 2);
3637
}
3738

38-
code-input:not(.code-input_loaded) {
39+
code-input textarea, code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_pre-element-styled pre {
40+
/* Both elements need the same text and space styling so they are directly on top of each other */
3941
margin: 0px!important;
40-
margin-bottom: calc(-1 * var(--padding, 16px))!important;
4142
padding: var(--padding, 16px)!important;
4243
border: 0;
44+
min-width: calc(100% - var(--padding, 16px) * 2);
45+
min-height: calc(100% - var(--padding, 16px) * 2);
46+
overflow: hidden;
47+
resize: none;
48+
grid-row: 1;
49+
grid-column: 1;
50+
display: block;
51+
}
52+
code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_pre-element-styled pre {
53+
height: max-content;
54+
width: max-content;
4355
}
4456

4557
code-input:not(.code-input_pre-element-styled) pre, code-input.code-input_pre-element-styled pre code {
@@ -58,15 +70,12 @@ code-input textarea, code-input pre, code-input pre * {
5870
tab-size: inherit!important;
5971
}
6072

61-
6273
code-input textarea, code-input pre {
6374
/* In the same place */
64-
position: absolute;
65-
top: 0;
66-
left: 0;
75+
grid-column: 1;
76+
grid-row: 1;
6777
}
6878

69-
7079
/* Move the textarea in front of the result */
7180

7281
code-input textarea {
@@ -79,7 +88,7 @@ code-input pre {
7988
code-input:not(.code-input_loaded) pre, code-input:not(.code-input_loaded) textarea {
8089
opacity: 0;
8190
}
82-
code-input:not(.code-input_loaded)::after {
91+
code-input:not(.code-input_loaded)::before {
8392
color: #ccc;
8493
}
8594

@@ -96,8 +105,6 @@ code-input textarea::placeholder {
96105

97106
/* Can be scrolled */
98107
code-input textarea, code-input pre {
99-
overflow: auto!important;
100-
101108
white-space: inherit;
102109
word-spacing: normal;
103110
word-break: normal;
@@ -110,17 +117,9 @@ code-input textarea {
110117
outline: none!important;
111118
}
112119

113-
code-input:not(.code-input_registered)::after {
120+
code-input:not(.code-input_registered)::before {
114121
/* Display message to register */
115122
content: "Use codeInput.registerTemplate to set up.";
116123
display: block;
117124
color: grey;
118-
}
119-
120-
/* To prevent Ctrl+F in result element */
121-
code-input pre .code-input_searching-disabled::before {
122-
content: attr(data-content);
123-
}
124-
code-input pre .code-input_searching-disabled {
125-
font-size: 0;
126125
}

code-input.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export namespace plugins {
9595
*/
9696
class Autocomplete extends Plugin {
9797
/**
98-
* Pass in a function to display the popup that takes in (popup element, textarea, textarea.selectionEnd).
98+
* Pass in a function to create a plugin that displays the popup that takes in (popup element, textarea, textarea.selectionEnd).
9999
* @param {function} updatePopupCallback a function to display the popup that takes in (popup element, textarea, textarea.selectionEnd).
100100
*/
101101
constructor(updatePopupCallback: (popupElem: HTMLElement, textarea: HTMLTextAreaElement, selectionEnd: number) => void);

0 commit comments

Comments
 (0)