Skip to content

Commit 9d7256b

Browse files
Fix "live shell" hint reappearing when frame changed
1 parent 66f2949 commit 9d7256b

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

lib/better_errors/templates/main.erb

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@
595595
color: #8080a0;
596596
padding-left: 20px;
597597
}
598+
.console-has-been-used .live-console-hint {
599+
display: none;
600+
}
598601

599602
.hint:before {
600603
content: '\25b2';
@@ -817,6 +820,28 @@
817820
return html.replace(/&/, "&amp;").replace(/</g, "&lt;");
818821
}
819822

823+
function hasConsoleBeenUsedPreviously() {
824+
return !!document.cookie.split('; ').find(function(cookie) {
825+
return cookie.startsWith('BetterErrors-has-used-console=');
826+
});
827+
}
828+
829+
var consoleHasBeenUsed = hasConsoleBeenUsedPreviously();
830+
831+
function consoleWasJustUsed() {
832+
if (consoleHasBeenUsed) {
833+
return;
834+
}
835+
836+
hideConsoleHint();
837+
consoleHasBeenUsed = true;
838+
document.cookie = "BetterErrors-has-used-console=true;path=/;max-age=31536000;samesite"
839+
}
840+
841+
function hideConsoleHint() {
842+
document.querySelector('body').className += " console-has-been-used";
843+
}
844+
820845
function REPL(index) {
821846
this.index = index;
822847

@@ -838,32 +863,21 @@
838863
this.inputElement = this.container.querySelector("input");
839864
this.outputElement = this.container.querySelector("pre");
840865

841-
this.hasUsedConsole = document.cookie.split('; ').find(function(cookie) {
842-
return cookie.startsWith('BetterErrors-has-used-console=');
843-
});
844-
if (this.hasUsedConsole) {
845-
this.hideConsoleHint();
866+
if (consoleHasBeenUsed) {
867+
hideConsoleHint();
846868
}
847869

848870
var self = this;
849871
this.inputElement.onkeydown = function(ev) {
850872
self.onKeyDown(ev);
851-
if (!self.hasUsedConsole) {
852-
self.hideConsoleHint();
853-
self.hasUsedConsole = true;
854-
document.cookie = "BetterErrors-has-used-console=true;path=/;max-age=31536000;samesite"
855-
}
873+
consoleWasJustUsed();
856874
};
857875

858876
this.setPrompt(">>");
859877

860878
REPL.all[this.index] = this;
861879
};
862880

863-
REPL.prototype.hideConsoleHint = function() {
864-
document.querySelector('#live-shell-hint').style["display"] = "none";
865-
};
866-
867881
REPL.prototype.focus = function() {
868882
this.inputElement.focus();
869883
};

lib/better_errors/templates/variable_info.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</header>
2626

2727
<% if BetterErrors.binding_of_caller_available? && @frame.frame_binding %>
28-
<div class="hint" id='live-shell-hint'>
28+
<div class="hint live-console-hint">
2929
This is a live shell. Type in here.
3030
</div>
3131

0 commit comments

Comments
 (0)