Skip to content

Commit c91d9da

Browse files
committed
Remove old fix for Ctrl+F due to its inconsistency
1 parent 9f835ba commit c91d9da

File tree

3 files changed

+10
-60
lines changed

3 files changed

+10
-60
lines changed

CONTRIBUTING.md

Lines changed: 9 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:

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.js

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ var codeInput = {
108108
if(!(typeof template.includeCodeInputInHighlightFunc == "boolean" || template.includeCodeInputInHighlightFunc instanceof Boolean)) throw TypeError(`code-input: Template for "${templateName}" invalid, because the includeCodeInputInHighlightFunc value provided is not a true or false; it is "${template.includeCodeInputInHighlightFunc}". Please make sure you use one of the constructors in codeInput.templates, and that you provide the correct arguments.`);
109109
if(!(typeof template.preElementStyled == "boolean" || template.preElementStyled instanceof Boolean)) throw TypeError(`code-input: Template for "${templateName}" invalid, because the preElementStyled value provided is not a true or false; it is "${template.preElementStyled}". Please make sure you use one of the constructors in codeInput.templates, and that you provide the correct arguments.`);
110110
if(!(typeof template.isCode == "boolean" || template.isCode instanceof Boolean)) throw TypeError(`code-input: Template for "${templateName}" invalid, because the isCode value provided is not a true or false; it is "${template.isCode}". Please make sure you use one of the constructors in codeInput.templates, and that you provide the correct arguments.`);
111-
if(!(typeof template.autoDisableDuplicateSearching == "boolean" || template.autoDisableDuplicateSearching instanceof Boolean)) throw TypeError(`code-input: Template for "${templateName}" invalid, because the autoDisableDuplicateSearching value provided is not a true or false; it is "${template.autoDisableDuplicateSearching}". Please make sure you use one of the constructors in codeInput.templates, and that you provide the correct arguments.`);
112111
if(!Array.isArray(template.plugins)) throw TypeError(`code-input: Template for "${templateName}" invalid, because the plugin array provided is not an array; it is "${template.plugins}". Please make sure you use one of the constructors in codeInput.templates, and that you provide the correct arguments.`);
113112

114113
template.plugins.forEach((plugin, i) => {
@@ -166,18 +165,11 @@ var codeInput = {
166165
* @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.Plugin`
167166
* @returns {codeInput.Template} template object
168167
*/
169-
constructor(highlight = function () { }, preElementStyled = true, isCode = true, includeCodeInputInHighlightFunc = false, autoDisableDuplicateSearching = true, plugins = []) {
170-
// @deprecated to support old function signature without autoDisableDuplicateSearching
171-
if(Array.isArray(autoDisableDuplicateSearching)) {
172-
plugins = autoDisableDuplicateSearching;
173-
autoDisableDuplicateSearching = true;
174-
}
175-
168+
constructor(highlight = function () { }, preElementStyled = true, isCode = true, includeCodeInputInHighlightFunc = false, plugins = []) {
176169
this.highlight = highlight;
177170
this.preElementStyled = preElementStyled;
178171
this.isCode = isCode;
179172
this.includeCodeInputInHighlightFunc = includeCodeInputInHighlightFunc;
180-
this.autoDisableDuplicateSearching = autoDisableDuplicateSearching;
181173
this.plugins = plugins;
182174
}
183175

@@ -210,15 +202,6 @@ var codeInput = {
210202
*/
211203
includeCodeInputInHighlightFunc = false;
212204

213-
/**
214-
* Leaving this as true uses code-input's default fix for preventing duplicate results in Ctrl+F searching
215-
* from the input and result elements, and setting this to false indicates your highlighting function implements
216-
* its own fix.
217-
*
218-
* The default fix works by moving text content from elements to CSS ::before pseudo-elements after highlighting.
219-
*/
220-
autoDisableDuplicateSearching = true;
221-
222205
/**
223206
* An array of plugin objects to add extra features -
224207
* see `codeInput.Plugin`.
@@ -251,7 +234,6 @@ var codeInput = {
251234
true, // preElementStyled
252235
true, // isCode
253236
false, // includeCodeInputInHighlightFunc
254-
true, // autoDisableDuplicateSearching
255237
plugins
256238
);
257239
},
@@ -270,7 +252,6 @@ var codeInput = {
270252
false, // preElementStyled
271253
true, // isCode
272254
false, // includeCodeInputInHighlightFunc
273-
true, // autoDisableDuplicateSearching
274255
plugins
275256
);
276257
},
@@ -297,7 +278,6 @@ var codeInput = {
297278
includeCodeInputInHighlightFunc: true,
298279
preElementStyled: true,
299280
isCode: false,
300-
autoDisableDuplicateSearching: true,
301281
plugins: plugins,
302282
}
303283
},
@@ -322,7 +302,6 @@ var codeInput = {
322302
includeCodeInputInHighlightFunc: true,
323303
preElementStyled: true,
324304
isCode: false,
325-
autoDisableDuplicateSearching: true,
326305

327306
rainbowColors: rainbowColors,
328307
delimiter: delimiter,
@@ -514,7 +493,6 @@ var codeInput = {
514493
* to syntax-highlight it. */
515494

516495
needsHighlight = false; // Just inputted
517-
// needsDisableDuplicateSearching = false; // Just highlighted
518496

519497
/**
520498
* Highlight the code ASAP
@@ -540,14 +518,7 @@ var codeInput = {
540518
if(this.needsHighlight) {
541519
this.update();
542520
this.needsHighlight = false;
543-
// this.needsDisableDuplicateSearching = true;
544521
}
545-
// if(this.needsDisableDuplicateSearching && this.codeElement.querySelector("*") != null) {
546-
// // Has been highlighted
547-
// this.resultElementDisableSearching();
548-
// this.needsDisableDuplicateSearching = false;
549-
// }
550-
551522
window.requestAnimationFrame(this.animateFrame.bind(this));
552523
}
553524

@@ -592,30 +563,6 @@ var codeInput = {
592563
return text.replace(new RegExp("&amp;", "g"), "&").replace(new RegExp("&lt;", "g"), "<").replace(new RegExp("&gt;", "g"), ">"); /* Global RegExp */
593564
}
594565

595-
/**
596-
* Make the text contents of highlighted code in the `<pre><code>` result element invisible to Ctrl+F by moving them to a data attribute
597-
* then the CSS `::before` pseudo-element on span elements with the class code-input_searching-disabled. This function is called recursively
598-
* on all child elements of the <code> element.
599-
*
600-
* @param {HTMLElement} element The element on which this is carried out recursively. Optional - defaults to the `<pre><code>`'s `<code>` element.
601-
*/
602-
resultElementDisableSearching(element=this.preElement) {
603-
for (let i = 0; i < element.childNodes.length; i++) {
604-
let content = element.childNodes[i].textContent;
605-
606-
if (element.childNodes[i].nodeType == 3) {
607-
// Turn plain text node into span element
608-
element.replaceChild(document.createElement('span'), element.childNodes[i]);
609-
element.childNodes[i].classList.add("code-input_searching-disabled")
610-
element.childNodes[i].setAttribute("data-content", content);
611-
element.childNodes[i].innerText = '';
612-
} else {
613-
// Recurse deeper
614-
this.resultElementDisableSearching(element.childNodes[i]);
615-
}
616-
}
617-
}
618-
619566
/**
620567
* Get the template object this code-input element is using.
621568
* @returns {Object} - Template object

0 commit comments

Comments
 (0)