Skip to content

Commit b4b1e8e

Browse files
bwhitmanclaude
andcommitted
pye on Tulip: fast page flips and old-editor viewport jumps
Two hardware-speed fixes in the display_window override: - Scrolls, pages and full redraws now freeze TFB pixel rendering (tfb_stop) and flush once at the end (tfb_start + tfb_update). Every stdout write used to re-render its row to pixels -- a page flip was ~150 row renders; now it's cell writes plus one full render, which is how the old C editor gets its speed. - When the cursor crosses the top/bottom edge, the viewport jumps a quarter-screen like the old editor (editor.c moves half), so holding down-arrow at the bottom repaints once per 12 lines instead of every line. Verified on Tulip Desktop with a 100-line file: page-down lands the viewport at the computed quarter-position (row 0 = line013), 13 more down-arrows produce exactly one jump (line026), and typing after the jumps lands on the correct row. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 7a3bdc0 commit b4b1e8e

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

tulip/shared/py/pye_tulip.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ def _colorize(line):
8585
return "".join(out)
8686

8787

88-
# pye's display_window with one change: unmarked lines are written through
89-
# _colorize() for editor.c-style syntax highlighting. Marked (selected) lines
90-
# keep the plain selection style, and scrbuf still caches the raw text.
88+
# pye's display_window with three changes:
89+
# - unmarked lines are written through _colorize() for editor.c-style syntax
90+
# highlighting (marked lines keep the plain selection style; scrbuf still
91+
# caches the raw text)
92+
# - when the cursor crosses the top/bottom edge, the viewport jumps a
93+
# quarter-screen like the old C editor, so continued line-by-line movement
94+
# doesn't scroll (and repaint) every line
95+
# - scrolls/pages/full redraws freeze TFB pixel rendering (tfb_stop) and
96+
# flush once at the end, instead of re-rendering rows on every write
9197
def _display_window(self):
9298
Editor = _pye.Editor
9399
self.cur_line = min(self.total_lines - 1, max(self.cur_line, 0))
@@ -97,8 +103,29 @@ def _display_window(self):
97103
elif self.vcol < self.margin:
98104
self.margin = max(self.vcol - (Editor.width >> 2), 0)
99105
if not (self.top_line <= self.cur_line < self.top_line + Editor.height):
106+
if self.cur_line >= self.top_line + Editor.height: # crossed the bottom
107+
self.row = Editor.height - 1 - (Editor.height >> 2)
108+
else: # crossed the top
109+
self.row = Editor.height >> 2
100110
self.top_line = max(self.cur_line - self.row, 0)
101111
self.row = self.cur_line - self.top_line
112+
big = (
113+
getattr(self, "_tulip_top", None) != self.top_line
114+
or (Editor.scrbuf and Editor.scrbuf[0] == (False, "\x00"))
115+
)
116+
self._tulip_top = self.top_line
117+
if big:
118+
tulip.tfb_stop()
119+
try:
120+
_display_window_rows(self)
121+
finally:
122+
if big:
123+
tulip.tfb_start()
124+
tulip.tfb_update()
125+
126+
127+
def _display_window_rows(self):
128+
Editor = _pye.Editor
102129
self.cursor(False)
103130
line = self.top_line
104131
if self.mark is None:

0 commit comments

Comments
 (0)