-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-141374: Add vi mode to PyREPL #141375
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
base: main
Are you sure you want to change the base?
gh-141374: Add vi mode to PyREPL #141375
Changes from 14 commits
beca8d7
a054e5d
cd7b85d
17ef56b
0b14fce
23babd6
237f559
1406699
aa5b41a
e8afc9e
f863425
fa1a578
0a8a1e3
d3e358d
aeb8345
f40ecaf
86defc0
12197cb
d7311af
cbe7707
a6fb266
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| import os | ||
| import time | ||
|
|
||
| from .types import ViMode | ||
|
|
||
| # Categories of actions: | ||
| # killing | ||
| # yanking | ||
|
|
@@ -59,6 +61,8 @@ def do(self) -> None: | |
|
|
||
|
|
||
| class KillCommand(Command): | ||
| modifies_buffer = True | ||
|
||
|
|
||
| def kill_range(self, start: int, end: int) -> None: | ||
| if start == end: | ||
| return | ||
|
|
@@ -325,10 +329,19 @@ def do(self) -> None: | |
| b = r.buffer | ||
| for _ in range(r.get_arg()): | ||
| p = r.pos + 1 | ||
| if p <= len(b): | ||
| r.pos = p | ||
| # In vi normal mode, don't move past the last character | ||
| if r.vi_mode == ViMode.NORMAL: | ||
| eol_pos = r.eol() | ||
| max_pos = max(r.bol(), eol_pos - 1) if eol_pos > r.bol() else r.bol() | ||
| if p <= max_pos: | ||
| r.pos = p | ||
| else: | ||
| self.reader.error("end of line") | ||
| else: | ||
| self.reader.error("end of buffer") | ||
| if p <= len(b): | ||
| r.pos = p | ||
| else: | ||
| self.reader.error("end of buffer") | ||
|
|
||
|
|
||
| class beginning_of_line(MotionCommand): | ||
|
|
@@ -338,7 +351,14 @@ def do(self) -> None: | |
|
|
||
| class end_of_line(MotionCommand): | ||
| def do(self) -> None: | ||
| self.reader.pos = self.reader.eol() | ||
| r = self.reader | ||
| eol_pos = r.eol() | ||
| if r.vi_mode == ViMode.NORMAL: | ||
| bol_pos = r.bol() | ||
| # Don't go past the last character (but stay at bol if line is empty) | ||
| r.pos = max(bol_pos, eol_pos - 1) if eol_pos > bol_pos else bol_pos | ||
| else: | ||
| r.pos = eol_pos | ||
|
|
||
|
|
||
| class home(MotionCommand): | ||
|
|
@@ -404,6 +424,8 @@ def do(self) -> None: | |
|
|
||
|
|
||
| class backspace(EditCommand): | ||
| modifies_buffer = True | ||
|
|
||
| def do(self) -> None: | ||
| r = self.reader | ||
| b = r.buffer | ||
|
|
@@ -417,6 +439,8 @@ def do(self) -> None: | |
|
|
||
|
|
||
| class delete(EditCommand): | ||
| modifies_buffer = True | ||
|
|
||
| def do(self) -> None: | ||
| r = self.reader | ||
| b = r.buffer | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's correct to expect timeouts. People can write slowly. Or not. Hold a key, or not. I also can't figure an example of when this would happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.