bpo-17535: IDLE editor line numbers by taleinat · Pull Request #14030 · python/cpython (original) (raw)

Tal, thank you for reviving the improving the old patch. This seems to work better than the 2014 version, enough so I want to get this into b3 (scheduled in 3 weeks, 7/29). If we can coordinate, I will help with the needed changes. (I believe some of them amount to fixing parts of the old patch that are now obsolete.)

I would like to immediately follow up with a shell sidebar, which will, among other things, separate prompt and code and allow properly spaced indents instead of the wonky tabbing. (we might do something else immediately, but I want it eventually.) I will try to post something for discussion tomorrow.

Issues (couple of which would be separate).

  1. New names: Because the sidebar is not just about line numbers, the new file should be sidebar.py and the highlights sidebar-foreground and -background.
  2. Startup
>>> import idlelib.idle

 Warning: config.IdleConf.GetThemeDict -
 problem retrieving theme element 'linenumber-foreground'
 from theme 'Custom Dark'.
 returning default color: '#000000'

 Warning: config.IdleConf.GetThemeDict -
 problem retrieving theme element 'linenumber-background'
 from theme 'Custom Dark'.
 returning default color: '#ffffff'

This happens with custom themes every time we add theme elements. We immediately need to extend previous workaround, but should do a more permanent fix that adds elements, with default values, to custom themes.

  1. Default status: When I opened the editor, line numbers appeared. I believe the consensus on the issue is that the default should be off.
  2. Menu: Location good, but as I said on the issue, I want to copy the code context solution, which works, instead of keeping the check mark. Besides aesthetics and consistency, the line number mark is buggy in a way similar to the way that the old code context check was: changing the mark in one window affects the mark in other windows, possibly resulting in the menu checkmark for a window becoming out of sync with the window state. When a window with a check does not have line numbers, they sometimes cannot be added.
  3. Scrolling. While working on code context, Cheryl and I fixed scrolling to be by lines, and intended that there should always be an even line at the top. I wonder if this helped this patch work better.

The default size of a Text widget with all lines the same height (as in IDLE) is an even number of lines, and when this is true, there are no partial lines to worry about. When a user changes the window height to have a fractional size, IDLE (without this patch) puts a whole line at the top and the fractional line at the bottom. I intend that this remain true.

While using the patch, I discovered that when one scrolls to the bottom of the file, the fractional line moves to the top. It stays there until one scrolls to the top or until the widget just switches back. This looks even worse with line numbers, so a fix would be good if it can be done without making scrolling on macOS worse. (1? adjust window size to an integral number of line after a resize? 2? display a partial unnumbered blank line, like Notepad++.)

  1. Selection: With Notepad++, one can select a whole line by clicking on a line number. To select multiple lines, one drags the cursor to the last line one wants to include. Very intuitive to me. With this patch, clicking does nothing and one must drag to the first line to be excluded. Much worse. This slice-like behavior would look better if the cursor were a horizontal line, so one could click between line numbers and drag to another slice position, between numbers. But even then, click -- select would be more useful, and eventually I would like to be able to select a multiline statement with a double click. (And in Shell, double click select an entire traceback, where the sidebar might have 'ERR' opposite the 'Traceback...' line.)
  2. Font resizing: This seems to now work the same as without line numbers, with none of the vertical jumps I remember. The main issue now is that with 4 windows, at least 1 with a few 1000 lines, resizing takes about a second to complete, mostly because of re-colorizing the files. It naively seems that changing the font attribute should be enough. Do you know whether it is tk or IDLE that removes the tags?
  3. Implementation: Implementing builtin features as extensions is obsolete since Sept 2017. Issue 27099.