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

add 0 key for beginning-of-line #15

Merged
merged 2 commits into from
Aug 17, 2014
Merged

Conversation

nathantypanski
Copy link
Contributor

This adds a shortcut for the 0 key to take the user to the beginning
of a given line, like Vim. It simply calls line_home like ^ does,
but this one is in my muscle memory from Vim usage.

By the way, thanks for developing this. I was looking for a dead-simple
command-line CSV viewer, and this fits the bill.

This adds a shortcut for the `0` key to take the user to the beginning
of a given line, like Vim. It simply calls `line_home` like `^` does,
but this one is in my muscle memory from Vim usage.
@nathantypanski
Copy link
Contributor Author

Ugh. This breaks the modifier key handling for 0. I'll update this PR if I fix it.

Previously, when `0` was used to call `line_home`, this would clobber
the modifiers even if a digit 1-9 was pressed before `0`, which should
signify the beginning of a modifier key sequence and cause `0` to behave
as a modifier until the next command is pressed.

This checks if a current modifier is in effect, and if so it does not
treat any digit keypresses as commands until the modifier is cleared.
@nathantypanski
Copy link
Contributor Author

Well, I've fixed that issue. Behavior for 0 is now the same as Vim:

  • Pressing 0 without any modifier present goes to the beginning of the current line.
  • If a modifier is already present, 0 is considered a part of that modifier sequence.

There's some jumping around required because of the fact that .isdigit() fails if c > 256, but it's otherwise straightforward.

Note: It occurs to me that because of this behavior, even in your current upstream pressing any key c > 256 that is not assigned in the Viewer.keys attribute will crash the program. For example, pressing F2 will trigger a crash.

@firecat53
Copy link
Collaborator

Thanks for doing that!! I've been hitting 0 too and been meaning to fix that. Haven't touched this for awhile though. Gimme a day or two to look at this (in between other stuff :) )

Scott

@nathantypanski
Copy link
Contributor Author

Of course!

One other thing I noticed when working on this/reviewing it:

Line 121 is probably unnecessary. But I have something of a habit of changing this kind of "boolean context" usage of regular objects into boolan expressions, since Python's behavior isn't always what you mean to say. For example, even though it works fine for strings:

>>> not ''
True
>>> not '0'
False
>>> not 'False'
False

it gets stranger when you start mixing numerics:

>>> not 0
True
>>> not 99
False
>>> modifier = '{}{}'.format(modifier, '0')
>>> not int(modifier)
True

So I just try to avoid these weird bugs altogether by specifying booleans explicitly when it doesn't hurt the duck typing.

@firecat53 firecat53 merged commit 65ebb38 into TabViewer:master Aug 17, 2014
@firecat53
Copy link
Collaborator

Thanks! I added one more commit that looks it fixes the crash on unhandled characters.

@nathantypanski
Copy link
Contributor Author

Good job fixing the crash. Thanks for merging. 💃

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

Successfully merging this pull request may close these issues.

2 participants