Skip to content
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

Cursor is offset in notebook in Chrome 17 on Linux #1503

Closed
chrodan opened this issue Mar 15, 2012 · 35 comments · Fixed by #1883
Closed

Cursor is offset in notebook in Chrome 17 on Linux #1503

chrodan opened this issue Mar 15, 2012 · 35 comments · Fixed by #1883
Milestone

Comments

@chrodan
Copy link

chrodan commented Mar 15, 2012

Using the current development version of the notebook I notice a vertical offset of the cursor in code cells. The offsets gets bigger the more lines the cell contains. This offset makes editing code unfeasible. As the effect does not occur in markdown cells, I assume that the reason is the java script code editor. I am using Chrome 17.0 on Linux.

@ellisonbg
Copy link
Member

Can you give a few more details or a screenshot. Does this always
happen? How is it triggered? Could you reload the page a few times
just to make sure.

On Thu, Mar 15, 2012 at 4:26 PM, chrodan
reply@reply.github.com
wrote:

Using the current development version of the notebook I notice a vertical offset of the cursor in code cells. This offset makes editing code unfeasible. As the effect does not occur in markdown cells, I assume that the reason is the java script code editor. I am using Chrome 17.0 on Linux.


Reply to this email directly or view it on GitHub:
#1503

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@chrodan
Copy link
Author

chrodan commented Mar 16, 2012

I had a closer look at the phenomenon. The problem does not occur in Firefox 10, but always in Chrome 17. Reloading does not help. I also tried to disable some CSS properties of the code block, but the offset did not go away.

Here is a screenshot where the text ("train.npy") was selected:
Offset

@pynixwang
Copy link

can notebook add an export ablity................such as html file, i know I can save pages,but not so perfect.....................

@ellisonbg
Copy link
Member

Are you using a non-default font size?

On Fri, Mar 16, 2012 at 1:30 AM, wccgithub
reply@reply.github.com
wrote:

can notebook add an export ablity................such as html file, i know I can save pages,but not so perfect.....................


Reply to this email directly or view it on GitHub:
#1503 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@chrodan
Copy link
Author

chrodan commented Mar 16, 2012

no. I also tried different zoom level and the offset changes slightly but is always present

@ghost
Copy link

ghost commented Mar 16, 2012

I also experience this bug in Chromium on Ubuntu Linux with default Ubuntu font. It's gone in Firefox but it is also gone in Chromium on a screen with aspect ratio different than 16:9.
I believe this bug is related to #1373

@ellisonbg
Copy link
Member

But in that case it is related to resizing of fonts.

On Fri, Mar 16, 2012 at 11:47 AM, Radek
reply@reply.github.com
wrote:

I also experience this bug in Chromium on Ubuntu Linux with default Ubuntu font. It's gone in Firefox but it is also gone in Chromium on a screen with aspect ratio different than 16:9.
I believe this bug is related to #1373


Reply to this email directly or view it on GitHub:
#1503 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@ellisonbg
Copy link
Member

Got this from a student that may point to a solution:

When I'm working in the IPython notebook and a code section is longer than about 11 lines, the cursor and highlight position do not line up with the code I am working on. I suspected that this had something to do with the fact that keywords are bolded and that bold letters are slightly larger than normal letters. I was able to fix this issue by adding the following CSS directive to remove all bold styles.

* { font-weight: normal !important; }

I'm using Google Chrome on Ubuntu but the issue happens for me on Google Chrome on OS X as well. I tried to find an issue in the IPython repo on github but found none.

@certik
Copy link

certik commented May 17, 2012

I just accidentally created a duplicate #1745, but I added a screenshot. This bug is unfortunate, because it makes it very hard to edit larger code cells.

@fperez
Copy link
Member

fperez commented May 17, 2012

Here is how it looks like (original report by @certik in #1754, now closed):

Screenshot

The cursor appears on the line above the correct line. With this cursor, I was just pressing "s" repeatedly and you can see where it was typed.

@fperez
Copy link
Member

fperez commented May 17, 2012

As I indicated in #1745, I can't reproduce on Chrome 19, even with a huge cell (over 2000 lines long). Could it be a Chrome-17-specific issue?

@chrodan
Copy link
Author

chrodan commented May 17, 2012

I observe the issue with Ubuntu 12.04 and Chrome 18. So it is not limited to Chrome-17, but maybe pre19 or it has something to do with Ubuntu's system fonts?

@ghost
Copy link

ghost commented May 17, 2012

I tried it on different machines and found that it requires a screen with 16:9 aspect ratio and happens only in cells with bolded keywords in them. It looks like bolded words are a few points higher than in regular font and Notebook somehow does not take it into account when calculating cursor position.

@ellisonbg
Copy link
Member

I think this is an issue with CodeMirror itself and it may have to do with the fact that we have changed the CSS styling of the CodeMirror editor in the following way:

.CodeMirror { line-height: 1.231; /* Changed from 1em to our global default */ }

We could test to see if this is related by commenting these lines out of static/css/notebook.js.

Can someone follow this up with this on the CodeMirror list. Please mention that setting the font-weight: normal fixes the issue as well.

@mcelrath
Copy link

mcelrath commented Jun 7, 2012

I dug into this a bit in investigating all the reasons cells were jumping around.

It is caused by Chrome choosing fonts for which the bold and italic variants do not have the same height as the normal variant. On my computer (Ubuntu 12.04, Chrome 20 beta), Chrome is choosing "Courier New" as the monospaced font, while Firefox is choosing "Bitstream Vera Sans Mono". The Bitstream fonts do not have this problem that different weights have different heights, which is why Firefox did not display the problem. You can fix it in Chrome too by changing its font to the Bitstream one.

So technically, this is a browser bug, and I was unable to find a way to fix it using CSS. Fixing line-height, font-size, etc, do not work to fix this bug. The only thing that fixes it is to avoid bold and italic fonts as pointed out by @ellisonbg, or to make an explicit list of fonts using CSS font-family.

Fonts which do not have the problem on my computer include:

  • Bitstream Vera Sans Mono
  • Droid Sans Mono
  • DejaVu Sans Mono
  • FreeMono
  • Liberation Mono
  • Luxi Mono
  • Mono Uralic
  • Monospace
  • Monotype.com
  • Ubuntu Mono
  • WenQuanYi Zen Hei Mono
  • WenQuanYi Micro Zen Hei Mono

Fonts that do have the problem on my computer include:

  • Courier New
  • Nimbus Mono L

Perhaps someone on windows or mac can tell us which fonts do or don't have the problem? I find the easiest way is to type two or more lines that do not contain any bold/italic keywords, and add "print" or something which gets bolded to the first line. The second you hit the 't' of 'print', the text below it will shift down by 1px or so. You may have to zoom in, making to font larger, to see this. Simultaneously, choose the mono font in your browser settings.

Change these lines in notebook.css to fix it, using the fonts above, or some subset thereof...

.CodeMirror pre {
line-height: 1.231em; /* Changed from 1em to our global default */
font-family: 'Bitstream Vera Sans Mono', 'Droid Sans Mono', 'DejaVu Sans Mono', 'FreeMono', 'Liberation Mono', 'Luxi Mono', 'Mono Uralic', 'Monospace', 'Monotype.com', 'Ubuntu Mono', 'WenQuanYi Zen Hei Mono', 'WenQuanYi Micro Zen Hei Mono', monospace;
}

What is the reasoning behind the odd 1.231 font size (also in boilerplate.css)? Is it related to this bug?

@ellisonbg
Copy link
Member

Wow, thanks for looking around at all of this. Some points:

  • I agree that this is a browser bug - we could simply tell people this and that they need to change their monospace font on Chrome as a workaround. What a pain though.
  • When we first worked on the notebook, we had long discussions about monospaced fonts. There was a moderately strong opinion amongst the devs that we should not list font explicitly. Up to know that has served us well.
  • Not using bold or italic fonts in the CodeMirror editors is a simple fix, but it is nice for syntax highlighting purposes.

Whew, this is a very tough choice. What to others think @fperez, @minrk, @Carreau?

Fonts which do not have the problem on my computer include:

  • Bitstream Vera Sans Mono
  • Droid Sans Mono
  • DejaVu Sans Mono
  • FreeMono
  • Liberation Mono
  • Luxi Mono
  • Mono Uralic
  • Monospace
  • Monotype.com
  • Ubuntu Mono
  • WenQuanYi Zen Hei Mono
  • WenQuanYi Micro Zen Hei Mono

Fonts that do have the problem on my computer include:

  • Courier New
  • Nimbus Mono L

Perhaps someone on windows or mac can tell us which fonts do or don't have the problem?  I find the easiest way is to type two or more lines that do not contain any bold/italic keywords, and add "print" or something which gets bolded to the first line.  The second you hit the 't' of 'print', the text below it will shift down by 1px or so.  You may have to zoom in, making to font larger, to see this.  Simultaneously, choose the mono font in your browser settings.

Change these lines in notebook.css to fix it, using the fonts above, or some subset thereof...

.CodeMirror pre {
   line-height: 1.231em;  /* Changed from 1em to our global default */
   font-family: 'Bitstream Vera Sans Mono', 'Droid Sans Mono', 'DejaVu Sans Mono', 'FreeMono', 'Liberation Mono', 'Luxi Mono', 'Mono Uralic', 'Monospace', 'Monotype.com', 'Ubuntu Mono', 'WenQuanYi Zen Hei Mono', 'WenQuanYi Micro Zen Hei Mono', monospace;
}

What is the reasoning behind the odd 1.231 font size (also in boilerplate.css)?  Is it related to this bug?

I am using the YUI CSS font stuff to size text in a consistent way across browsers:

http://yuilibrary.com/yui/docs/cssfonts/

@fperez
Copy link
Member

fperez commented Jun 8, 2012

On Thu, Jun 7, 2012 at 12:15 PM, Brian E. Granger
reply@reply.github.com
wrote:

Whew, this is a very tough choice.  What to others think @fperez, @minrk, @Carreau?

Tough one; the reason I dislike hardcoding font lists is because it
prevents users from choosing fonts they know work well on the screen
in front of their eyes. For example, I have configured chrome to use
Consolas as my monospaced font, because Courier New is quite possibly
the single worst monospaced font on the face of the planet, and I have
no clue why an otherwise competent browser like chrome makes such a
boneheaded choice by default.

I get unbelievably annoyed when sites hardcode monospaced fonts
because they never hardcode consolas as an option, the one that I like
best (and I obsessively test monospaced font every year or two to see
if that choice changes). So as long as we put consolas on that list
in front of everything else (which won't harm anyone who doesn't have
it) I don't mind. Hardcoding anything else will drive me insane.

@minrk
Copy link
Member

minrk commented Jun 8, 2012

Tough choice. It seems like if we want allow users to choose, the first choice should be 'monospace', and let users configure their browsers/systems as they may. There's no typeface blacklist, is there? Hardcoding Fernando's preference doesn't make a lot of sense to me.

@fperez
Copy link
Member

fperez commented Jun 8, 2012

All I was saying is that if we're going to make a hardlist (which I don't like), I want it to be the one I can live with ;)

I think the problem is that if we say 'monospace', Chrome defaults to Courier New, which if I understand things correctly, happens to have this bug (in addition to be horrible and suck).

@mcelrath
Copy link

mcelrath commented Jun 8, 2012

Fernando Perez [reply@reply.github.com] wrote:

All I was saying is that if we're going to make a hardlist (which I don't
like), I want it to be the one I can live with ;)

I think the problem is that if we say 'monospace', Chrome defaults to Courier
New, which if I understand things correctly, happens to have this bug (in
addition to be horrible and suck).

Yes. 'monospace' as the first option is not viable. As a desperate fallback
it's better than nothing.

Another alternative would be to serve up a reasonable font itself. I see no way
to do "font blacklists". See for example:

http://www.fontsquirrel.com/fontfacedemo/Bitstream-Vera-Sans-Mono

Cheers, Bob McElrath

"The individual has always had to struggle to keep from being overwhelmed by
the tribe. If you try it, you will be lonely often, and sometimes frightened.
But no price is too high to pay for the privilege of owning yourself."
-- Friedrich Nietzsche

@fperez
Copy link
Member

fperez commented Jun 8, 2012

As long as a served font doesn't override my own custom choice, I'm fine with it. But if a served font prevents me from getting the font I've configured as my monospace font from displaying, then no.

@minrk
Copy link
Member

minrk commented Jun 8, 2012

It is impossible for force any monospace fonts without pissing people off. Programmers are far too attached to their coding typefaces. (for instance, forcing Consolas would piss me off, and anything else would do the same for Fernando). That seems like a complete non-starter, so I think the font-family must be left as monospace. I've tried to replicate the bug with CodeMirror theme demos and can't seem to do it, even with Courier New, so I think it's something we are doing.

@fperez
Copy link
Member

fperez commented Jun 8, 2012

Ah, then that means there may be a hope of fixing it... Thanks for digging further, Min.

@mcelrath
Copy link

mcelrath commented Jun 8, 2012

Min RK [reply@reply.github.com] wrote:

It is impossible for force any monospace fonts without pissing people off.
Programmers are far too attached to their coding typefaces. (for instance,
forcing Consolas would piss me off, and anything else would do the same for
Fernando). That seems like a complete non-starter, so I think the font-family
must be left as monospace. I've tried to replicate the bug with CodeMirror
theme demos and can't seem to do it, even with Courier New, so I think it's
something we are doing.

Well then so far the only solution is to turn off bold and italics.

It may be possible to detect the presence of this bug... there's a trick used by
the jsMath javascript library which consists of writing something to a hidden
div, and then measuring its height in px using offsetHeight, in order to measure
the properties of the font. Here is some code that does that:

http://stackoverflow.com/questions/1134586/how-can-you-find-the-height-of-text-on-an-html-canvas

Cheers, Bob McElrath

"The individual has always had to struggle to keep from being overwhelmed by
the tribe. If you try it, you will be lonely often, and sometimes frightened.
But no price is too high to pay for the privilege of owning yourself."
-- Friedrich Nietzsche

@ellisonbg
Copy link
Member

Min, great tracking that point down. I think the one thing we might be doing is setting the font size differently in the CodeMirror editor. It was actually quite subtle to get the font in the CodeMirror cell to match things like the prompt's font size. I used the YUI font stuff because it simplified everything, but it may not play well with how CodeMirror works.

@mcelrath
Copy link

mcelrath commented Jun 8, 2012

It can be fixed with vertical-align:bottom on the span tag. See my new pull request #1883.

I'm going to go change fonts now, because I hate Courier too...triply so now, having wasted so much time on the stupid thing.

@fperez
Copy link
Member

fperez commented Jun 8, 2012

On Thu, Jun 7, 2012 at 10:41 PM, Bob McElrath
reply@reply.github.com
wrote:

It can be fixed with vertical-align:bottom on the span tag.  See my new pull request #1883.

Awesome! Thanks a ton for all your patience in hunting this down...

Cheers,

f

@minrk
Copy link
Member

minrk commented Jun 11, 2012

So has this one been fixed?

@fperez
Copy link
Member

fperez commented Jun 11, 2012

Closed by #1883.

@fperez fperez closed this as completed Jun 11, 2012
@fperez
Copy link
Member

fperez commented Jun 11, 2012

Yup, sorry: I failed to put the closing tag in the merge message, thanks for spotting it!

@minrk
Copy link
Member

minrk commented Jun 11, 2012

No problem, just doing my periodic skim of Issues, to see if we've missed some. I've also been bumping various we obviously won't get to for 0.13 over to 0.14.

@fperez
Copy link
Member

fperez commented Jun 11, 2012

Yup, awesome. I've also been doing triage and will email the list
shortly about more concrete 0.13 plans...

@jtratner
Copy link
Contributor

I'm using IPython 0.13.2 and still seeing this issue (but the font-weight force fixed it). Any chance you could add a note about this to the docs? (maybe there's even a way to use display + CSS to force it so you could just add a code snippet).

@ivanov
Copy link
Member

ivanov commented Oct 15, 2013

@jtratner can you see if you still have this issue in 1.0, which was released in August? If you still see the issue, please open a new bug for it (referencing this one). Thanks

@jtratner
Copy link
Contributor

I will check (I don't recall seeing it though). Clearly searching for the
cursor issue got me to this GH issue, so probably fine - just saying that,
for people on old distros, could be helpful. I'll get back to you tonight
about whether I see this on 1.0.

On Tue, Oct 15, 2013 at 2:48 PM, Paul Ivanov notifications@github.comwrote:

@jtratner https://github.com/jtratner can you see if you still have
this issue in 1.0, which was released in August? If you still see the
issue, please open a new bug for it (referencing this one). Thanks


Reply to this email directly or view it on GitHubhttps://github.com//issues/1503#issuecomment-26361503
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants