Skip to content

Commit 7fca3b2

Browse files
authored
Merge pull request #149 from WebCoder49/code-input-scrolls-but-no-blur-focus
Remove blur/focus which was causing many bugs
2 parents 350e422 + 926fb75 commit 7fca3b2

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

code-input.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ var codeInput = {
474474
* to syntax-highlight it. */
475475

476476
needsHighlight = false; // Just inputted
477-
handleEventsFromTextarea = true; // Turn to false when unusual internal events are called on the textarea
478477
originalAriaDescription;
479478

480479
/**
@@ -515,14 +514,6 @@ var codeInput = {
515514

516515
this.syncSize();
517516

518-
// If editing here, scroll to the caret by focusing, though this shouldn't count as a focus event
519-
if(this.textareaElement === document.activeElement) {
520-
this.handleEventsFromTextarea = false;
521-
this.textareaElement.blur();
522-
this.textareaElement.focus();
523-
this.handleEventsFromTextarea = true;
524-
}
525-
526517
this.pluginEvt("afterHighlight");
527518
}
528519

@@ -638,9 +629,7 @@ var codeInput = {
638629
this.classList.add("code-input_mouse-focused");
639630
});
640631
textarea.addEventListener("blur", () => {
641-
if(this.handleEventsFromTextarea) {
642-
this.classList.remove("code-input_mouse-focused");
643-
}
632+
this.classList.remove("code-input_mouse-focused");
644633
});
645634

646635
this.innerHTML = ""; // Clear Content
@@ -866,22 +855,20 @@ var codeInput = {
866855
this.boundEventCallbacks[listener] = boundCallback;
867856

868857
if (codeInput.textareaSyncEvents.includes(type)) {
869-
// Synchronise with textarea, only when handleEventsFromTextarea is true
870-
// This callback is modified to only run when the handleEventsFromTextarea is set.
871-
let conditionalBoundCallback = function(evt) { if(this.handleEventsFromTextarea) boundCallback(evt); }.bind(this);
872-
this.boundEventCallbacks[listener] = conditionalBoundCallback;
858+
// Synchronise with textarea
859+
this.boundEventCallbacks[listener] = boundCallback;
873860

874861
if (options === undefined) {
875862
if(this.textareaElement == null) {
876863
this.addEventListener("code-input_load", () => { this.textareaElement.addEventListener(type, boundCallback); });
877864
} else {
878-
this.textareaElement.addEventListener(type, conditionalBoundCallback);
865+
this.textareaElement.addEventListener(type, boundCallback);
879866
}
880867
} else {
881868
if(this.textareaElement == null) {
882869
this.addEventListener("code-input_load", () => { this.textareaElement.addEventListener(type, boundCallback, options); });
883870
} else {
884-
this.textareaElement.addEventListener(type, conditionalBoundCallback, options);
871+
this.textareaElement.addEventListener(type, boundCallback, options);
885872
}
886873
}
887874
} else {
@@ -941,10 +928,12 @@ var codeInput = {
941928
if (val === null || val === undefined) {
942929
val = "";
943930
}
931+
944932
// Save in editable textarea element
945933
this.textareaElement.value = val;
946934
// Trigger highlight
947935
this.scheduleHighlight();
936+
948937
return val;
949938
}
950939

0 commit comments

Comments
 (0)