AutoYADM commit: 2025-05-12 21:31:08

This commit is contained in:
Daniel Fichtinger 2025-05-12 21:31:08 -04:00
parent fb094dda5b
commit dbd404e03b

View file

@ -10,9 +10,12 @@
# Basically, look at the target line, and figure out the logical column # Basically, look at the target line, and figure out the logical column
# number that corresponds to the visual column number we see right now. # number that corresponds to the visual column number we see right now.
# ISSUE: does not work if the line has indentation
# Also TODO: once this is ironed out, re-write it in Rust for le speed # Also TODO: once this is ironed out, re-write it in Rust for le speed
import sys import sys
import re
session_id = sys.argv[1] session_id = sys.argv[1]
line_n = int(sys.argv[2]) line_n = int(sys.argv[2])
@ -30,8 +33,16 @@ with open(path, "r") as f:
for n, l in enumerate(f, start=1): for n, l in enumerate(f, start=1):
if n == line_n: if n == line_n:
line = l line = l
match = re.match(r"^(\s*)", line)
if match:
indent = match.group(1)
indent_len = len(indent)
else:
indent_len = 0
chunks = [line[i : i + wrap_width] for i in range(0, len(line), wrap_width)] content = line[indent_len:]
chunks = [content[i : i + wrap_width] for i in range(0, len(content), wrap_width)]
visual_row = col // wrap_width visual_row = col // wrap_width
visual_col = col % wrap_width visual_col = col % wrap_width
@ -39,7 +50,7 @@ new_visual_row = visual_row + (-1 if direction == "up" else 1)
if 0 <= new_visual_row < len(chunks): if 0 <= new_visual_row < len(chunks):
target_chunk = chunks[new_visual_row] target_chunk = chunks[new_visual_row]
new_col = min(visual_col, len(target_chunk) - 1) new_col = min(visual_col, len(target_chunk) - 1)
new_abs_col = new_visual_row * wrap_width + new_col new_abs_col = indent_len + (new_visual_row * wrap_width + new_col)
diff = abs(new_abs_col - col) diff = abs(new_abs_col - col)
key = "h" if direction == "up" else "l" key = "h" if direction == "up" else "l"
print(f"{diff}{key}") print(f"{diff}{key}")