Skip to content

Commit 389e971

Browse files
authored
Merge pull request #230 from WebCoder49/main
Add recent bugfixes etc. to `breaking-key-events`
2 parents 92ff274 + 2d1be3d commit 389e971

42 files changed

Lines changed: 626 additions & 233 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Contributing to `code-input`
1+
# Contributing to `code-input.js`
22

3-
🎉**Here at `code-input`, contributions of all sizes are more than welcome. Below are some scenarios where you could contribute and how to do so.** Contributions are generally accepted when they help achieve at least one of the aims below, but others will be considered:
3+
🎉**Here at `code-input.js`, contributions of all sizes are more than welcome. Below are some scenarios where you could contribute and how to do so.** Contributions are generally accepted when they help achieve at least one of the aims below, but others will be considered:
44

5-
* The `code-input` element should act like a normal HTML `textarea` in all browsers, working with all of the normal attributes, events and other types of behaviour.
6-
* The `code-input` element should be easy to use with all popular syntax-highlighting libraries.
7-
* 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.
5+
* The `code-input.js` element should act like a normal HTML `textarea` in all browsers, working with all of the normal attributes, events and other types of behaviour.
6+
* The `code-input.js` element should be easy to use with all popular syntax-highlighting libraries.
7+
* Any modifications of `code-input.js` 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

99
We will generally *not* consider the following contributions:
1010
* Excess functionality and/or complexity in the main code-input files - these types of contributions should go in the plugin folder instead.
@@ -14,23 +14,23 @@ This said, if you're not sure whether your change will be accepted, please ask i
1414

1515
---
1616

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).
17+
To keep this community productive and enjoyable, please [don't break our code of conduct](CODE_OF_CONDUCT.md).
1818

1919
---
2020
# Ways you could contribute:
21-
If you don't want to use GitHub, for all of these you can alternatively [get in touch via email so the maintainer can add your contribution for you](mailto:code-input-js@webcoder49.dev).
21+
If you don't want to use either of Codeberg or GitHub, for all of these you can alternatively [get in touch via email so the maintainer can add your contribution for you](mailto:code-input-js@webcoder49.dev).
2222

2323
## 1. I've found a bug but don't know how / don't have time to fix it.
24-
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.
24+
If you think you've found a bug, please submit an issue on [GitHub](https://github.com/WebCoder49/code-input/issues) or [Codeberg](https://codeberg.org/code-input-js/code-input-js/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 piece of code demonstrating your bug would be incredibly useful.
2525

2626
## 2. I have implemented a feature / have thought of a potential feature for the library and think it could be useful for others.
27-
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.
28-
Otherwise, if you do not have the time needed / do not want to implement it, any potential plugins would be [welcome as an Issue](https://github.com/WebCoder49/code-input/issues) which specifies the uses and desired characteristics.
27+
The best way to implement a feature is as a plugin like those in the `plugins` folder of `code-input.js`. If you do this, you could contribute it as in point 3 below.
28+
Otherwise, if you do not have the time needed / do not want to implement it, any potential plugins would be (on [GitHub](https://github.com/WebCoder49/code-input/issues) or [Codeberg](https://codeberg.org/code-input-js/code-input-js/issues)) which specifies the uses and desired characteristics.
2929

3030
## 3. I want to contribute code that I need / have seen in the Issues.
3131
Firstly, thank you for doing this! This is probably the most time consuming way of contributing but is also the most rewarding for both you and me as a maintainer.
3232

33-
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).
33+
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 (how-tos by [Codeberg](https://docs.codeberg.org/collaborating/pull-requests-and-git-flow/) and [GitHub](https://docs.github.com/en/get-started/quickstart/contributing-to-projects)).
3434

3535
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!
3636

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-2025 Oliver Geer and contributors
3+
Copyright (c) 2021-2026 Oliver Geer and contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# code-input
22

3-
![Click to Switch](https://img.shields.io/static/v1?label=&message=Click%20to%20Switch:%20&color=grey&style=for-the-badge)[![Website and Demos](https://img.shields.io/static/v1?label=&message=Website&color=black&style=for-the-badge)](https://code-input-js.org)[![GitHub](https://img.shields.io/static/v1?label=&message=GitHub&color=navy&style=for-the-badge&logo=github)](https://github.com/WebCoder49/code-input)[![Yarn](https://img.shields.io/static/v1?label=&message=Yarn&color=purple&style=for-the-badge&logo=yarn)](https://yarnpkg.com/package?name=@webcoder49/code-input)[![NPM](https://img.shields.io/static/v1?label=&message=NPM&color=red&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@webcoder49/code-input)
3+
![Click to Switch](https://img.shields.io/static/v1?label=&message=Click%20to%20Switch:%20&color=grey&style=for-the-badge)[![Website and Demos](https://img.shields.io/static/v1?label=&message=Website&color=444400&style=for-the-badge)](https://code-input-js.org)[![GitHub](https://img.shields.io/static/v1?label=&message=GitHub&color=black&style=for-the-badge&logo=github)](https://github.com/WebCoder49/code-input)[![Codeberg](https://img.shields.io/static/v1?label=&message=Codeberg&color=navy&style=for-the-badge&logo=codeberg)](https://codeberg.org/code-input-js/code-input-js)[![Yarn](https://img.shields.io/static/v1?label=&message=Yarn&color=purple&style=for-the-badge&logo=yarn)](https://yarnpkg.com/package?name=@webcoder49/code-input)[![NPM](https://img.shields.io/static/v1?label=&message=NPM&color=red&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@webcoder49/code-input)
44

5-
[![View License](https://img.shields.io/github/license/webcoder49/code-input?style=for-the-badge)](LICENSE) [![View Releases](https://img.sHields.io/github/v/release/webcoder49/code-input?style=for-the-badge)](https://github.com/WebCoder49/code-input/releases)
5+
[![View License](https://img.shields.io/github/license/webcoder49/code-input?color=darkgreen&style=for-the-badge)](LICENSE) [![View Releases](https://img.shields.io/github/v/release/webcoder49/code-input?style=for-the-badge)](https://github.com/WebCoder49/code-input/releases)
66
> **An editable <textarea> that supports *any* syntax highlighting algorithm, for code or something else. Also, added plugins.**
77
>
88
> Aiming to be more flexible, lightweight, modular, progressively enhanced and standards-based than the alternatives, we support HTML forms, the `<textarea>` JavaScript interface, more languages and more use cases.
@@ -13,12 +13,16 @@ Demos and usage instructions are available at <https://code-input-js.org> and [t
1313

1414
---
1515

16+
A lightweight setup like the animation below is still the default for `code-input.js`, but a wide range of plugins are available to modularly and progressively enhance the experience - see [the website](https://code-input-js.org) for interactive demos!
17+
1618
![Using code-input with many different themes](https://user-images.githubusercontent.com/69071853/133924472-05edde5c-23e7-4350-a41b-5a74d2dc1a9a.gif)
1719
*This demonstration uses themes from [Prism.js](https://prismjs.com/) and [highlight.js](https://highlightjs.org/), two syntax-highlighting programs which work well with and have compatibility built-in with code-input.*
1820

1921
## Contributing
2022
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).
2123

24+
**If you find a sensitive security vulnerability in the code-input.js library, please email the maintainer Oliver Geer at [security@webcoder49.dev](mailto:security@webcoder49.dev), optionally using [this encryption key](https://ogeer.org#pgp). GitHub security advisories (different to the more general "issues") are also accepted.**
25+
2226

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

SECURITY.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
# Reporting Security Vulnerabilities
2-
If you find a sensitive security vulnerability
3-
in the code-input.js library, please
4-
contact the maintainer Oliver Geer at
5-
[security@webcoder49.dev](mailto:security@webcoder49.dev),
6-
after reading [this page with an encryption key](https://oliver.geer.im#email).
2+
3+
If you find a sensitive security vulnerability in the code-input.js library, please email the maintainer Oliver Geer at [security@webcoder49.dev](mailto:security@webcoder49.dev), optionally using [this encryption key](https://ogeer.org#pgp). GitHub security advisories (different to the more general "issues") are also accepted.

code-input.css

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
*
66
* License of whole library for bundlers:
77
*
8-
* Copyright 2021-2025 Oliver Geer and contributors
8+
* Copyright 2021-2026 Oliver Geer and contributors
99
* @license MIT
1010
*
1111
* **<https://code-input-js.org>**
1212
*/
1313

1414
code-input {
1515
/* Allow other elements to be inside */
16-
display: block;
16+
display: grid;
17+
grid-template-columns: 100%;
18+
grid-template-rows: 100%;
1719
overflow-y: auto;
1820
overflow-x: auto;
1921
position: relative;
@@ -46,9 +48,6 @@ code-input {
4648
tab-size: 2;
4749
white-space: pre;
4850
padding: 0!important; /* Use --padding to set the code-input element's padding */
49-
display: grid;
50-
grid-template-columns: 100%;
51-
grid-template-rows: 100%;
5251
}
5352

5453
code-input :not(.code-input_dialog-container *) {
@@ -100,7 +99,7 @@ code-input textarea, code-input pre, code-input pre * {
10099
tab-size: inherit!important;
101100
text-align: inherit!important;
102101
}
103-
code-input textarea, code-input pre, code-input pre code {
102+
code-input pre, code-input pre code {
104103
overflow: visible!important;
105104
}
106105

@@ -285,5 +284,7 @@ code-input textarea[data-code-input-fallback] {
285284
color: var(--code-input_highlight-text-color, inherit);
286285

287286
/* Don't overlap with message */
288-
min-height: calc(100% - var(--padding-top, 16px) - 2em - var(--padding-bottom, 16px));
287+
min-height: calc(100% - var(--padding-top, 16px) - max(2em, var(--padding-bottom, 16px)));
288+
height: calc(100% - var(--padding-top, 16px) - max(2em, var(--padding-bottom, 16px)));
289+
padding-bottom: max(2em, var(--padding-bottom, 16px))!important;
289290
}

code-input.d.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,16 @@ export namespace plugins {
129129

130130
// ESM-SUPPORT-START-PLUGIN-find-and-replace Do not (re)move this - it's needed for ESM generation
131131
/**
132-
* Add Find-and-Replace (Ctrl+F for find, Ctrl+H for replace by default) functionality to the code editor.
132+
* Add Find-and-Replace (Ctrl/Cmd+F for find, Ctrl+H for replace by default) functionality to the code editor.
133133
* Files: find-and-replace.js / find-and-replace.css
134134
*/
135135
class FindAndReplace extends Plugin {
136136
/**
137-
* Create a find-and-replace command plugin to pass into a template
138-
* @param {boolean} useCtrlF Should Ctrl+F be overriden for find-and-replace find functionality? Either way, you can also trigger it yourself using (instance of this plugin)`.showPrompt(code-input element, false)`.
139-
* @param {boolean} useCtrlH Should Ctrl+H be overriden for find-and-replace replace functionality? Either way, you can also trigger it yourself using (instance of this plugin)`.showPrompt(code-input element, true)`.
137+
* Create a find-and-replace command plugin to pass into a template. To ensure keyboard shortcuts remain intuitive, set the alwaysCtrl parameter to false.
138+
* @param {boolean} useCtrlF Should Ctrl/Cmd+F be overridden for find-and-replace find functionality? Either way, you can also trigger it yourself using (instance of this plugin)`.showPrompt(code-input element, false)`.
139+
* @param {boolean} useCtrlH Should Ctrl+H be overridden for find-and-replace replace functionality? Either way, you can also trigger it yourself using (instance of this plugin)`.showPrompt(code-input element, true)`.
140140
* @param {Object} instructionTranslations: user interface string keys mapped to translated versions for localisation. Look at the find-and-replace.js source code for the English text.
141+
* @param {boolean} alwaysCtrl Setting this to false makes the keyboard shortcuts follow the operating system while avoiding clashes (right now: Cmd+F/Ctrl+H on Apple, Ctrl+F/Ctrl+H otherwise.) and is recommended; true forces Ctrl+F/Ctrl+H and is default for backwards compatibility.
141142
*/
142143
constructor(useCtrlF?: boolean, useCtrlH?: boolean,
143144
instructionTranslations?: {
@@ -159,7 +160,8 @@ export namespace plugins {
159160
replaceAction?: string;
160161
replaceAllActionShort?: string;
161162
replaceAllAction?: string
162-
}
163+
},
164+
alwaysCtrl?: boolean
163165
);
164166
/**
165167
* Show a find-and-replace dialog.
@@ -172,13 +174,13 @@ export namespace plugins {
172174

173175
// ESM-SUPPORT-START-PLUGIN-go-to-line Do not (re)move this - it's needed for ESM generation
174176
/**
175-
* Add basic Go-To-Line (ctrl-G by default) functionality to the code editor.
177+
* Add Go-To-Line (Ctrl/Cmd+G by default) functionality to the code editor.
176178
* Files: go-to-line.js / go-to-line.css
177179
*/
178180
class GoToLine extends Plugin {
179181
/**
180-
* Create a go-to-line command plugin to pass into a template
181-
* @param {boolean} useCtrlG Should Ctrl+G be overriden for go-to-line functionality? Either way, you can trigger it yourself using (instance of this plugin)`.showPrompt(code-input element)`.
182+
* Create a go-to-line command plugin to pass into a template.
183+
* @param {boolean} useCtrlG Should Ctrl/Cmd+G be overridden for go-to-line functionality? Either way, you can trigger it yourself using (instance of this plugin)`.showPrompt(code-input element)`.
182184
* @param {Object} instructionTranslations: user interface string keys mapped to translated versions for localisation. Look at the go-to-line.js source code for the English text.
183185
*/
184186
constructor(useCtrlG?: boolean,
@@ -190,7 +192,8 @@ export namespace plugins {
190192
guidanceColumnRange?: (line: Number, current: Number, max: Number) => string;
191193
guidanceValidLine?: (line: Number) => string;
192194
guidanceValidColumn?: (line: Number, column: Number) => string;
193-
});
195+
},
196+
);
194197
/**
195198
* Show a search-like dialog prompting line number.
196199
* @param {codeInput.CodeInput} codeInput the `<code-input>` element.

0 commit comments

Comments
 (0)