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

[input-] fix word locator for Ctrl+Right motion #2663

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions visidata/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def delchar(s, i, remove=1):
'Delete `remove` characters from str `s` beginning at position `i`.'
return s if i < 0 else s[:i] + s[i+remove:]

def find_nonword(s, a, b, incr):
def find_word(s, a, b, incr):
if not s: return 0
a = min(max(a, 0), len(s)-1)
b = min(max(b, 0), len(s)-1)
Expand All @@ -124,9 +124,9 @@ def find_nonword(s, a, b, incr):
b += incr
return min(max(b, -1), len(s))
else:
while not s[a].isalnum() and a < b: # first skip non-word chars
while s[a].isalnum() and a < b: # first skip word chars
a += incr
while s[a].isalnum() and a < b:
while not s[a].isalnum() and a < b: # then skip non-word chars
a += incr
return min(max(a, 0), len(s))

Expand Down Expand Up @@ -261,12 +261,12 @@ def handle_key(self, ch:str, scr) -> bool:
elif ch == '^T': v = delchar(splice(v, i-2, v[i-1:i]), i) # swap chars
elif ch == '^U': v = v[i:]; i = 0 # clear to beginning
elif ch == '^V': v = splice(v, i, until_get_wch(scr)); i += 1 # literal character
elif ch == '^W': j = find_nonword(v, 0, i-1, -1); v = v[:j+1] + v[i:]; i = j+1 # erase word
elif ch == '^W': j = find_word(v, 0, i-1, -1); v = v[:j+1] + v[i:]; i = j+1 # erase word
elif ch == '^Y': v = splice(v, i, str(vd.memory.clipval))
elif ch == '^Z': vd.suspend()
# CTRL+arrow
elif ch == 'kLFT5': i = find_nonword(v, 0, i-1, -1)+1; # word left
elif ch == 'kRIT5': i = find_nonword(v, i+1, len(v)-1, +1)+1; # word right
elif ch == 'kLFT5': i = find_word(v, 0, i-1, -1)+1; # word left
elif ch == 'kRIT5': i = find_word(v, i, len(v)-1, +1); # word right
elif ch == 'kUP5': pass
elif ch == 'kDN5': pass
elif self.history and ch == 'KEY_UP': v, i = self.prev_history(v, i)
Expand Down
Loading