Add support to show and hide line numbers.#389
Closed
jerubball wants to merge 5 commits intoasottile:mainfrom
Closed
Add support to show and hide line numbers.#389jerubball wants to merge 5 commits intoasottile:mainfrom
jerubball wants to merge 5 commits intoasottile:mainfrom
Conversation
for more information, see https://pre-commit.ci
Owner
|
thanks for the patch but yeah I do not want line numbers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding support to show line number using command line option or keyboard shortcut.
I use babi for my Windows machines, where installing nano would take more than 5 minutes of my time.
Because I am used to seeing line number in nano and VS code, I decided spend 5+ hours of my time to add this feature.
I did see the issue #239, but still I want to give a shot with this pull request.
By default, line number will not be shown, and it will only come to effect when user requests it via command line option or keyboard shortcut.
After all, I am too lazy to press ^C each time to know where I am.
Like GNU nano, I have added
-land--linenumberscommand-line flag to enable line number.Also,
M-#(Alt + Shift + 3) can be pressed to toggle the display in-editor.The behavior of displayed number is also made to match that of nano.
On some notes on what changes are made,
The main fix was done in
File.draw()method in babi/file.py.Line number is printed first, then rest of line buffer is printed.
To have cursor to appear in the correct place (shifted right),
Screen.layout.filedimension needed to be updated.Apparently, no parts of code heavily relied on
Screen.layout.file.xbeing zero, and changinglayout.file.xandlayout.file.widthworked surprisingly well, so I utilized this to keep track of screen offset of file layout area.This would mean that layout needed to be updated time to time as edits are happening, therefore
Screen.update_layout()method is created to exposeScreen._layout_from_current_screen().And finally, keyboard shortcut was added to babi/screen.py, and command line option was added to babi/main.py.
These fixes were good enough to make everything work well.
I confirmed that all existing features including horizontal scrolling, highlight, search, replace, undo, redo, cut, uncut, switching to prev/next files are working properly as intended in both on and off state.
Please review, and see if you like it.
Regardless, thank you for your work on babi editor. It made my life so easier when I ssh into Windows machines.