Skip to content

Commit e002cdc

Browse files
authored
Merge pull request #63 from WebCoder49/cursor-below-view
Cursor below view
2 parents 25ff82f + ba555df commit e002cdc

12 files changed

+131
-127
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
---
1010
# Ways you could contribute:
1111
## 1. I've found a bug but don't know how / don't have time to fix it.
12-
If you think you've found a bug, please [submit an issue](https://github.com/WebCoder49/code-input/issues) with screenshots, how you found the bug, and copies of the console's logs if an error is in them. Please also mention the template and plugins you used (your `codeInput.registerTemplate(...)` snippet). We'd be more than happy to help you fix it.
12+
If you think you've found a bug, please [submit an issue](https://github.com/WebCoder49/code-input/issues) with screenshots, how you found the bug, and copies of the console's logs if an error is in them. Please also mention the template and plugins you used (your `codeInput.registerTemplate(...)` snippet). We'd be more than happy to help you fix it. A demo using [CodePen](https://codepen.io/) would be incredibly useful.
1313

1414
## 2. I have implemented a feature / have thought of a potential feature for the library and think it could be useful for others.
1515
The best way to implement a feature is as a plugin like those in the `plugins` folder of `code-input`. If you do this, you could contribute it as in point 3 below.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The next step is to set up a `template` to link `code-input` to your syntax-high
9999
hljs,
100100
[
101101
new codeInput.plugins.Autodetect(),
102-
new codeInput.plugins.Indent()
102+
new codeInput.plugins.Indent(true, 2) // 2 spaces indentation
103103
]
104104
)
105105
);
@@ -119,7 +119,7 @@ Now that you have registered a template, you can use the custom `<code-input>` e
119119
```
120120

121121
## Contributing
122-
If you have any features you would like to add to `code-input`, or have found any bugs, please [open an issue](https://github.com/WebCoder49/code-input/issues) or [fork and submit a pull request](https://github.com/WebCoder49/code-input/fork)! All contributions to this open-source project would be greatly appreciated.
122+
If you have any features you would like to add to `code-input` as plugins or core functionality, or have found any bugs, please [open an issue](https://github.com/WebCoder49/code-input/issues) or [fork and submit a pull request](https://github.com/WebCoder49/code-input/fork)! All contributions to this open-source project will be greatly appreciated. You can see [more info in our `CONTRIBUTING.md` file](CONTRIBUTING.md).
123123

124124

125125
|[![Contributors](https://contrib.rocks/image?repo=WebCoder49%2Fcode-input)](https://github.com/WebCoder49/code-input/graphs/contributors)|

code-input.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ code-input:not(.code-input_loaded)::after {
8383
color: #ccc;
8484
}
8585

86-
/* Make textarea almost completely transparent */
86+
/* Make textarea almost completely transparent, except for caret and placeholder */
8787

8888
code-input textarea {
8989
color: transparent;
9090
background: transparent;
9191
caret-color: inherit!important; /* Or choose your favourite color */
9292
}
93+
code-input textarea::placeholder {
94+
color: lightgrey;
95+
}
9396

9497
/* Can be scrolled */
9598
code-input textarea, code-input pre {

code-input.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ export namespace plugins {
116116
* Files: indent.js
117117
*/
118118
class Indent extends Plugin {
119-
constructor();
119+
/**
120+
* Create an indentation plugin to pass into a template
121+
* @param {Boolean} defaultSpaces Should the Tab key enter spaces rather than tabs? Defaults to false.
122+
* @param {Number} numSpaces How many spaces is each tab character worth? Defaults to 4.
123+
*/
124+
constructor(defaultSpaces?: boolean, numSpaces?: Number);
120125
}
121126

122127
/**

code-input.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,15 +774,13 @@ var codeInput = {
774774
oldValue = oldValue.toLowerCase();
775775

776776
// Remove old language class and add new
777-
console.log("code-input: Language: REMOVE", "language-" + oldValue);
778777
code.classList.remove("language-" + oldValue); // From codeElement
779778
code.parentElement.classList.remove("language-" + oldValue); // From preElement
780779
code.classList.remove("language-none"); // Prism
781780
code.parentElement.classList.remove("language-none"); // Prism
782781

783782
if (newValue != undefined && newValue != "") {
784783
code.classList.add("language-" + newValue);
785-
console.log("code-input: Language: ADD", "language-" + newValue);
786784
}
787785

788786
if (mainTextarea.placeholder == oldValue) mainTextarea.placeholder = newValue;
@@ -792,8 +790,7 @@ var codeInput = {
792790
break;
793791
default:
794792
if (codeInput.textareaSyncAttributes.includes(name)) {
795-
console.log("sync", name, oldValue, newValue);
796-
if(newValue == null || newValue == undefined) { // TODO: Console.Log to check reaches here with disabled attribute; Fix for disabled attr removal
793+
if(newValue == null || newValue == undefined) {
797794
this.textareaElement.removeAttribute(name);
798795
} else {
799796
this.textareaElement.setAttribute(name, newValue);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webcoder49/code-input",
3-
"version": "2.0.3",
3+
"version": "2.1.0",
44
"description": "Fully customisable, editable syntax-highlighted textareas.",
55
"browser": "code-input.js",
66
"scripts": {

plugins/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Code-input: Plugins
22
## List Of Plugins
33

4+
💡 Do you just want to get a quick editor working? We suggest the [Indent](#indent) and [Prism Line Numbers](#prism-line-numbers) plugins.
5+
6+
**Lots of plugins are very customisable - please see the JavaScript files for parameters and if you want more features let us know via GitHub Issues.**
7+
8+
---
9+
410
### Autocomplete
511
Display a popup under the caret using the text in the code-input element. This works well with autocomplete suggestions.
612

@@ -23,7 +29,7 @@ Files: [debounce-update.js](./debounce-update.js)
2329
[🚀 *CodePen Demo*](https://codepen.io/WebCoder49/pen/GRXyxzV)
2430

2531
### Indent
26-
Adds indentation using the `Tab` key, and auto-indents after a newline, as well as making it possible to indent/unindent multiple lines using Tab/Shift+Tab
32+
Adds indentation using the `Tab` key, and auto-indents after a newline, as well as making it possible to indent/unindent multiple lines using Tab/Shift+Tab. **Supports tab characters and custom numbers of spaces as indentation.**
2733

2834
Files: [indent.js](./indent.js)
2935

@@ -60,7 +66,7 @@ Plugins allow you to add extra features to a template, like [automatic indentati
6066
hljs,
6167
[
6268
new codeInput.plugins.Autodetect(),
63-
new codeInput.plugins.Indent()
69+
new codeInput.plugins.Indent(true, 2) // 2 spaces indentation
6470
]
6571
)
6672
);

plugins/autocomplete.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ codeInput.plugins.Autocomplete = class extends codeInput.Plugin {
1313
}
1414
/* When a key is pressed, or scrolling occurs, update the autocomplete */
1515
updatePopup(codeInput, onlyScrolled) {
16-
let textarea = codeInput.querySelector("textarea");
16+
let textarea = codeInput.textareaElement;
1717
let caretCoords = this.getCaretCoordinates(codeInput, textarea, textarea.selectionEnd, onlyScrolled);
1818
let popupElem = codeInput.querySelector(".code-input_autocomplete_popup");
1919
popupElem.style.top = caretCoords.top + "px";
@@ -33,7 +33,7 @@ codeInput.plugins.Autocomplete = class extends codeInput.Plugin {
3333
testPosElem.classList.add("code-input_autocomplete_testpos");
3434
codeInput.appendChild(testPosElem); // Styled like first pre, but first pre found to update
3535

36-
let textarea = codeInput.querySelector("textarea");
36+
let textarea = codeInput.textareaElement;
3737
textarea.addEventListener("keyup", this.updatePopup.bind(this, codeInput, false)); // Override this+args in bind - not just scrolling
3838
textarea.addEventListener("click", this.updatePopup.bind(this, codeInput, false)); // Override this+args in bind - not just scrolling
3939
textarea.addEventListener("scroll", this.updatePopup.bind(this, codeInput, true)); // Override this+args in bind - just scrolling

plugins/autodetect.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ codeInput.plugins.Autodetect = class extends codeInput.Plugin {
99
}
1010
/* Remove previous language class */
1111
beforeHighlight(codeInput) {
12-
let result_element = codeInput.querySelector("pre code");
13-
result_element.className = ""; // CODE
14-
result_element.parentElement.className = ""; // PRE
12+
let resultElement = codeInput.codeElement;
13+
resultElement.className = ""; // CODE
14+
resultElement.parentElement.className = ""; // PRE
1515
}
1616
/* Get new language class and set `lang` attribute */
1717
afterHighlight(codeInput) {
18-
let result_element = codeInput.querySelector("pre code");
19-
let lang_class = result_element.className || result_element.parentElement.className;
20-
let lang = lang_class.match(/lang(\w|-)*/i)[0]; // Get word starting with lang...; Get outer bracket
18+
let resultElement = codeInput.codeElement;
19+
let langClass = resultElement.className || resultElement.parentElement.className;
20+
let lang = langClass.match(/lang(\w|-)*/i)[0]; // Get word starting with lang...; Get outer bracket
2121
lang = lang.split("-")[1];
2222
if(lang == "undefined") {
2323
codeInput.removeAttribute("lang");

plugins/debounce-update.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ codeInput.plugins.DebounceUpdate = class extends codeInput.Plugin {
1414
}
1515
/* Runs before elements are added into a `code-input`; Params: codeInput element) */
1616
beforeElementsAdded(codeInput) {
17-
console.log(codeInput, "before elements added");
1817
this.update = codeInput.update.bind(codeInput); // Save previous update func
1918
codeInput.update = this.updateDebounced.bind(this, codeInput);
2019
}

0 commit comments

Comments
 (0)