feat: implement scrolling in editor
Some checks failed
Tests / test (macos-latest, 3.10) (push) Waiting to run
Tests / test (macos-latest, 3.11) (push) Waiting to run
Tests / test (macos-latest, 3.12) (push) Waiting to run
Tests / test (windows-latest, 3.10) (push) Waiting to run
Tests / test (windows-latest, 3.11) (push) Waiting to run
Tests / test (windows-latest, 3.12) (push) Waiting to run
Lint / lint (push) Failing after 24s
Tests / test (ubuntu-latest, 3.10) (push) Failing after 40s
Tests / test (ubuntu-latest, 3.11) (push) Failing after 37s
Tests / test (ubuntu-latest, 3.12) (push) Failing after 1m3s
Some checks failed
Tests / test (macos-latest, 3.10) (push) Waiting to run
Tests / test (macos-latest, 3.11) (push) Waiting to run
Tests / test (macos-latest, 3.12) (push) Waiting to run
Tests / test (windows-latest, 3.10) (push) Waiting to run
Tests / test (windows-latest, 3.11) (push) Waiting to run
Tests / test (windows-latest, 3.12) (push) Waiting to run
Lint / lint (push) Failing after 24s
Tests / test (ubuntu-latest, 3.10) (push) Failing after 40s
Tests / test (ubuntu-latest, 3.11) (push) Failing after 37s
Tests / test (ubuntu-latest, 3.12) (push) Failing after 1m3s
feat: update version to 1.26.0 refactor: adjust cursor position based on scroll_y maintenance: update changelog with new version information
This commit is contained in:
parent
55d8814f94
commit
a6c276862e
@ -21,6 +21,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Version 1.25.0 - 2025-11-08
|
||||
|
||||
Autonomous mode now has improved error handling and tracks usage and costs. Several internal components were updated to improve reliability and logging.
|
||||
|
||||
**Changes:** 10 files, 342 lines
|
||||
**Languages:** Markdown (8 lines), Python (332 lines), TOML (2 lines)
|
||||
|
||||
## Version 1.24.0 - 2025-11-07
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "rp"
|
||||
version = "1.24.0"
|
||||
version = "1.25.0"
|
||||
description = "R python edition. The ultimate autonomous AI CLI."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
51
rp/editor.py
51
rp/editor.py
@ -26,6 +26,7 @@ class RPEditor:
|
||||
self.lines = [""]
|
||||
self.cursor_y = 0
|
||||
self.cursor_x = 0
|
||||
self.scroll_y = 0
|
||||
self.mode = "normal"
|
||||
self.command = ""
|
||||
self.stdscr = None
|
||||
@ -222,9 +223,10 @@ class RPEditor:
|
||||
try:
|
||||
self.stdscr.clear()
|
||||
height, width = self.stdscr.getmaxyx()
|
||||
for i, line in enumerate(self.lines):
|
||||
if i >= height - 1:
|
||||
break
|
||||
for i in range(height - 1):
|
||||
line_idx = self.scroll_y + i
|
||||
if line_idx < len(self.lines):
|
||||
line = self.lines[line_idx]
|
||||
try:
|
||||
display_line = line[: width - 1] if len(line) >= width else line
|
||||
self.stdscr.addstr(i, 0, display_line)
|
||||
@ -238,9 +240,10 @@ class RPEditor:
|
||||
except curses.error:
|
||||
pass
|
||||
cursor_x = min(self.cursor_x, width - 1)
|
||||
cursor_y = min(self.cursor_y, height - 2)
|
||||
cursor_y_display = self.cursor_y - self.scroll_y
|
||||
if 0 <= cursor_y_display < height - 1:
|
||||
try:
|
||||
self.stdscr.move(cursor_y, cursor_x)
|
||||
self.stdscr.move(cursor_y_display, cursor_x)
|
||||
except curses.error:
|
||||
pass
|
||||
self.stdscr.refresh()
|
||||
@ -321,15 +324,33 @@ class RPEditor:
|
||||
if self.prev_key == ord("g"):
|
||||
self.cursor_y = 0
|
||||
self.cursor_x = 0
|
||||
self.scroll_y = 0
|
||||
elif key == ord("G"):
|
||||
self.cursor_y = max(0, len(self.lines) - 1)
|
||||
self.cursor_x = 0
|
||||
# Adjust scroll_y
|
||||
if self.stdscr:
|
||||
height, _ = self.stdscr.getmaxyx()
|
||||
if self.cursor_y >= self.scroll_y + height - 1:
|
||||
self.scroll_y = self.cursor_y - height + 2
|
||||
elif key == ord("u"):
|
||||
self.undo()
|
||||
elif key == 18:
|
||||
self.redo()
|
||||
elif key == 19:
|
||||
self._save_file()
|
||||
elif key == curses.KEY_PPAGE: # Page Up
|
||||
if self.stdscr:
|
||||
height, _ = self.stdscr.getmaxyx()
|
||||
page_size = height - 2
|
||||
self.cursor_y = max(0, self.cursor_y - page_size)
|
||||
self.scroll_y = max(0, self.scroll_y - page_size)
|
||||
elif key == curses.KEY_NPAGE: # Page Down
|
||||
if self.stdscr:
|
||||
height, _ = self.stdscr.getmaxyx()
|
||||
page_size = height - 2
|
||||
self.cursor_y = min(len(self.lines) - 1, self.cursor_y + page_size)
|
||||
self.scroll_y = min(max(0, len(self.lines) - height + 1), self.scroll_y + page_size)
|
||||
self.prev_key = key
|
||||
except Exception:
|
||||
pass
|
||||
@ -420,6 +441,13 @@ class RPEditor:
|
||||
elif new_y >= len(self.lines):
|
||||
self.cursor_y = max(0, len(self.lines) - 1)
|
||||
self.cursor_x = len(self.lines[self.cursor_y])
|
||||
# Adjust scroll_y to keep cursor visible
|
||||
if self.stdscr:
|
||||
height, _ = self.stdscr.getmaxyx()
|
||||
if self.cursor_y < self.scroll_y:
|
||||
self.scroll_y = self.cursor_y
|
||||
elif self.cursor_y >= self.scroll_y + height - 1:
|
||||
self.scroll_y = self.cursor_y - height + 2
|
||||
|
||||
def save_state(self):
|
||||
"""Save current state for undo."""
|
||||
@ -428,6 +456,7 @@ class RPEditor:
|
||||
"lines": list(self.lines),
|
||||
"cursor_y": self.cursor_y,
|
||||
"cursor_x": self.cursor_x,
|
||||
"scroll_y": self.scroll_y,
|
||||
}
|
||||
self.undo_stack.append(state)
|
||||
if len(self.undo_stack) > self.max_undo:
|
||||
@ -442,6 +471,7 @@ class RPEditor:
|
||||
"lines": list(self.lines),
|
||||
"cursor_y": self.cursor_y,
|
||||
"cursor_x": self.cursor_x,
|
||||
"scroll_y": self.scroll_y,
|
||||
}
|
||||
self.redo_stack.append(current_state)
|
||||
state = self.undo_stack.pop()
|
||||
@ -450,6 +480,7 @@ class RPEditor:
|
||||
self.cursor_x = min(
|
||||
state["cursor_x"], len(self.lines[self.cursor_y]) if self.lines else 0
|
||||
)
|
||||
self.scroll_y = state.get("scroll_y", 0)
|
||||
|
||||
def redo(self):
|
||||
"""Redo last undone change."""
|
||||
@ -459,6 +490,7 @@ class RPEditor:
|
||||
"lines": list(self.lines),
|
||||
"cursor_y": self.cursor_y,
|
||||
"cursor_x": self.cursor_x,
|
||||
"scroll_y": self.scroll_y,
|
||||
}
|
||||
self.undo_stack.append(current_state)
|
||||
state = self.redo_stack.pop()
|
||||
@ -467,6 +499,7 @@ class RPEditor:
|
||||
self.cursor_x = min(
|
||||
state["cursor_x"], len(self.lines[self.cursor_y]) if self.lines else 0
|
||||
)
|
||||
self.scroll_y = state.get("scroll_y", 0)
|
||||
|
||||
def _insert_text(self, text):
|
||||
"""Insert text at cursor position."""
|
||||
@ -571,6 +604,7 @@ class RPEditor:
|
||||
self.lines = text.splitlines() if text else [""]
|
||||
self.cursor_y = 0
|
||||
self.cursor_x = 0
|
||||
self.scroll_y = 0
|
||||
|
||||
def set_text(self, text):
|
||||
"""Thread-safe text setting."""
|
||||
@ -589,6 +623,13 @@ class RPEditor:
|
||||
line_num = max(0, min(line_num - 1, len(self.lines) - 1))
|
||||
self.cursor_y = line_num
|
||||
self.cursor_x = 0
|
||||
# Adjust scroll_y
|
||||
if self.stdscr:
|
||||
height, _ = self.stdscr.getmaxyx()
|
||||
if self.cursor_y < self.scroll_y:
|
||||
self.scroll_y = self.cursor_y
|
||||
elif self.cursor_y >= self.scroll_y + height - 1:
|
||||
self.scroll_y = self.cursor_y - height + 2
|
||||
|
||||
def goto_line(self, line_num):
|
||||
"""Thread-safe goto line."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user