New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Line number is misaligned when we overwrite the text using setValue method #3098
Comments
I think I have an regression window here: last good: 4.6.0 @Manoj-RG can you confirm it works in 4.6.0 for you? |
Reverting cde95c4 fixes it for me. |
Can you provide a test HTML file that produces the issue? Calling |
Try my demo. Go to 'Prefs' above and set 'Editor Theme' to 'mdn-like'. The issue should be visible immediately (floating gutter in Chrome, gutter bleeding into text in Firefox). My demo runs CM 5.0 right now. (If for some reason, the link doesn't open to a CodeMirror, nagivate to any other text file). |
Can you create a stand alone demo? The problem could be anywhere in the bucketloads of scripts and styles that that page is including. I am not going to sift through them. |
Can do, but I can assure you that no script touches CM positioning or gutter positioning. |
Well, I was able to solve the issue about the floating gutter in Chrome it seems. I think the cause for it was that I did The line number misalignment in Firefox is still unresolved. The |
Dumping out the 3 vars in Firefox: n.offsetLeft = 6
n.clientLeft = 0
gutterLeft = 6 Chrome: n.offsetLeft = 0
n.clientLeft = 0
gutterLeft = 6 |
Probably this: https://bugzilla.mozilla.org/show_bug.cgi?id=850684 @marijnh think you can work around that bug? |
I'll see if I can provide a patch for Firefox, but I'd appreciate a workaround in the meantime :) |
Firefox build finally finished, turns out the miscalculation of |
I scanned all offset related bugs in bugzilla, and while there are at least 5-6 dupes of above bug, none matches our case. I wonder if we could do without JS positioning on the line numbers. How about using CSS positioning like |
So is there still a problem if you ensure that you don't use a theme that hasn't been loaded? And if so, for the last time, can you give me an HTML page that actually allows me to reproduce it? I need to be able to see a bug and poke at it in order to know what's going on. |
I'm not sure how much help a plain HTML would be. The bug is only happening in a seemingly rare condition where Firefox miscalculates #3098 (comment) is a separate bug, where the border of the gutter isn't taken into account when calculating line number width. |
Finally found the cause, it's |
Margins for gutter markers aren't supported, and this was pushing the numbers into the content. Issue #3098
Thanks! I've pushed two patches that should help here -- one to force |
Awesome, thanks 👍 @Manoj-RG: Please verify. I'm not totally sure this change covers your issue. |
@goyatparmod In my case, I was using the version 4.6.0 and I was not allowed to migrate to higher versions. I fixed this gutter issue by making the 'fixedGutter' parameter to FALSE. I don't know how it worked. I was trying multiple options and finally setting the 'fixedGutter' parameter to FALSE fixed my issue (same version 4.6.0). @silverwind and @marijnh |
I had the exact same issue when displaying a CM element on an Angular-wrapped bootstrap tab that's hidden when the page loads (i.e. another tab is shown by default). When the user clicks on the tab with the CM element, the element would appear, but it would behave as @goyatparmod described (weird until you enter the 10th line). I figured I might have to call CM.refresh when the tab gets activated. The trouble was figuring out what event actually corresponded to the tab being activated. I found that the element wasn't hidden, so trying to react to element.show() didn't help. Rather, the element had width & height set to 0 until the tab it was displayed on became active. This actually might explain the weird CM behavior because it would have initialized with zero width and height. So instead of reacting to .show() I tried .resize() and it works. I suspect this might help you @goyatparmod because you're showing the code in a modal kinda like I'm showing it in a tab. In essence the code looks something like this (sorry just off the top of my head here...) <div id="target"></div> var elem = $('#target');
var cm = CodeMirror(elem[0], {});
elem.resize(function(){
if(elem.width() > 0){ cm.refresh(); }
}); |
Thanks to marijnh....mwileyTibco..My problem is also solved ..I use https://codemirror.net/addon/display/autorefresh.js and autorefrsh:true and it work very well. |
Whew! so glad I stumbled across post. I had the same issue as @goyatparmod and i've working on it for the past few hours trying to figure how to fix. Installing the "autorefresh" addon and setting the config option to true solved the problem for me. |
Could we please reopen this issue, as it seems to be present still? I created a fiddle to reproduce. It shows another issue (CodeWarrior being not visible at all), but this isn't relevant here. http://jsfiddle.net/TcqAf/184/ tested with Firefox 42.0 |
No we can't reopen the issue. Use |
@dcsaszar did u solve the issue? |
@tedwong The quick fix was using I later fixed it by initializing the editor at a later point in time, when the page rendering was more complete. I don't remember the specifics. |
I have created a text editor in my application using Code mirror. The content of the text editor has to be fetched from DataBase, when I reopen the text editor in my application. I aslo have line number for the text editor in the left side.
The problem is when I overwrite the content using setValue method, the line numbers are misaligned. That is it get collapsed with the content.
The above image is the output which I get. The line numbers has to be in the left. But after calling setValue method, the line numbers moved out from left position and gets collapsed with the content
The text was updated successfully, but these errors were encountered: