Line numbers appear outside gutter
See original GitHub issueSetting a gutter, and then quickly hiding CodeMirror will cause it to incorrectly measure itself and display the gutter improperly.
HTML file:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CodeMirror: Gutter Issue</title>
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<link rel="stylesheet" href="../addon/lint/lint.css">
<link rel="stylesheet" href="../doc/docs.css">
<style type="text/css">
.CodeMirror {border: 1px solid black; font-size:13px}
</style>
</head>
<body>
<h1>CodeMirror: Gutter issue</h1>
<p>Clicking "set gutter" causes line numbers to be misplaced.</p>
<div id="container">
<textarea id="code" name="code">
function findSequence(goal) {
function find(start, history) {
if (start == goal)
return history;
else if (start > goal)
return null;
else
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
}
return find(1, "1");
}
</textarea>
</div>
<p>
<button type=button onclick="setgutter()">set gutter</button>
<button type=button onclick="cleargutter()">clear gutter</button>
</p>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true
});
console.log('CodeMirror version: ' + CodeMirror.version);
function setgutter() {
editor.setOption('gutters', ['CodeMirror-lint-markers']);
document.getElementById("container").style.display = "none";
setTimeout(()=>{
document.getElementById("container").style.display = "block";
}, 100)
}
function cleargutter() {
editor.setOption('gutters', []);
}
</script>
</body>
</html>
This appears to be related to issue #1498, with the fix being to wrap alignHorizontally in a setTimeout. This makes working with CodeMirror very hard, because it forces me to leave CodeMirror onscreen longer than I might like, or to perform an expensive refresh every time I show it.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Line numbers appear outside gutter · Issue #4412 - GitHub
Setting a gutter, and then quickly hiding CodeMirror will cause it to incorrectly measure itself and display the gutter improperly.
Read more >Line numbers in alternate gutter of facing pages - nisus.com
Hello. I am trying to get my line numbers to show in the inside (or outside) margin, or gutter, consistently. At the moment,...
Read more >My gutter marks appear outside the gutter - CodeMirror
In every demo, the gutter appear wider, the line number always have a margin or are centered, and the mark either appear from...
Read more >Line numbers in outer margins in Word Mac
Hi, I want to use the option "line numbers" in a very large ... Set "Gutter" measurement according to the type "Binding" you...
Read more >How to dynamically show line numbers in gutter according to ...
I need to print out accurate line numbers in the sidebar of my app using only vanilla JS. The line numbers must auto-increase...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’re expected to call
.refresh()
after un-hiding the editor (unless you can be sure that it was in a fully coherent state before it was hidden, and its size hasn’t changed).Indeed, I also can’t reproduce #1498 anymore with the current code. A bunch of things changed in the updating code in the meantime, so I assume the timeout really isn’t necessary anymore. Removed it in attached patch.