1.9 KiB
Text Scrolling Implementation in Simplicitty
This document outlines the implementation of text scrolling in the Simplicitty terminal emulator project.
Overview
The implementation adds the ability to scroll through text content when it doesn't fit completely in the window. The scrolling is implemented on a line-by-line basis, allowing users to navigate through the content using keyboard shortcuts.
Key Components
-
Scroll State Management:
- Added
scroll_offsetto track the current scroll position (in visual lines) - Added
max_scroll_offsetto limit scrolling to available content
- Added
-
Viewport Calculation:
- Modified
get_visible_line_range()to consider the scroll offset when determining visible lines - Added
update_max_scroll_offset()to recalculate the maximum scroll position based on content and viewport size
- Modified
-
Scrolling Methods:
scroll_up(lines): Move viewport up by specified number of linesscroll_down(lines): Move viewport down by specified number of linespage_up(): Scroll up by one page (viewport height)page_down(): Scroll down by one page (viewport height)
-
Keyboard Controls:
- Ctrl+Up/Down: Scroll one line up/down
- Page Up/Down: Scroll one page up/down
- Ctrl+Home/End: Scroll to top/bottom of content
Implementation Details
The scrolling implementation works by adjusting the scroll_offset value, which determines which visual lines are rendered in the viewport. The get_visible_line_range() function uses this offset to calculate which logical lines should be rendered.
When the window is resized or content changes, the max_scroll_offset is recalculated to ensure scrolling remains within valid bounds.
Future Improvements
- Add mouse wheel support for scrolling
- Implement smooth scrolling animations
- Add a visual scrollbar indicator
- Preserve horizontal scroll position when navigating vertically