Commit graph

54 commits

Author SHA1 Message Date
Kovid Goyal
dfed4dc311
Fix multiline chars being torn by resize and ED 22
Removing multicell chars cleared only their text and the is_multicell flag,
leaving their other multicell fields. Code that did not check is_multicell
then mistook the removed cells for parts of multicell chars, so chars were
placed after unrelated rows and rewrap copied unrelated lines below such a
cell as the lower rows of a multiline char, tearing chars. Now all the
multicell fields are cleared and rewrap checks is_multicell.

The marker that preserves a blank cursor line during a resize was assumed
to be at the start of the line, but rewrap can place it after the lower
rows of multiline chars from the lines above, so removing it changed the
char at the start of the line instead, tearing multiline chars there. Now
the marker is removed where it is, just before the cursor.

When moving the screen into the scrollback for ED 22, the number of lines
to move was computed from the visual lines, which are lines from the
scrollback when it is scrolled. So too many lines were moved, adding blank
lines to the scrollback, or too few, tearing multiline chars. Now the lines
of the screen are used.
2026-11-13 19:43:59 +05:30
Kovid Goyal
0f19d55463
Fix infinite loops when making space for chars next to multiline chars
When looking for space free of the lower rows of multiline chars, with the
cursor on the last line below the bottom margin, a linefeed does not move
the cursor, so move_cursor_past_multicell() looped forever. Now it makes
space at the end of the line in that case.

move_cursor_past_multicell() also removed only the multicell char under the
cursor, not other chars in the cells the char being drawn would occupy. So
a wide char, for example one widened by VS16 at the end of a line, could
overwrite the first cells of a multiline char, leaving fragments of it.
Inserting chars before such a fragment looped forever, as the end of the
fragment was computed from its width ignoring its scale, so the loop went
backwards. Now all multicell chars in those cells are removed, and the end
of a char is computed from its scale and width and is always after the
current cell.

Also a char widened at the end of the line that was moved to cells
overlapping its original cell had its second cell cleared.
2026-11-13 19:43:52 +05:30
Kovid Goyal
cfd2b23dca
Fix out of bounds accesses with partially scrolled off multiline chars
Scrolling down (CSI T) could cut off the lower rows of a scale > 1 text
sizing character at the bottom of the screen. Adding a combining char to
it then wrote past the end of the line buffer in add_combining_char and
rewrapping on resize read past the end of the line buffer in
copy_multiline_extra_lines.

Multiline chars that are cut off at the edge of the screen or of the
history buffer, by scrolling or by inserting lines, are partially
scrolled off and are rendered as such, so they are kept. Code walking the rows of a multiline char now only visits
the adjacent rows that actually continue the char, rather than trusting
the y and scale of a cell, so it stays in bounds and does not modify
unrelated cells for partial or torn chars.

Chars that would be torn, i.e. left with rows from unrelated lines
adjacent to their remaining part, are removed. This happens when
scrolling with margins, when a partial char is moved away from the edge
of the screen by scrolling or deleting lines, when inserting lines pushes
the lower rows of a char straddling the bottom margin out of the scroll
region, and when a partial char
cut off at the bottom is no longer at the bottom after a resize. Rewrap
drops partial chars, as it already did for chars with missing top rows,
placing cursors that were on them where the char would have been.

The checks for torn chars are skipped unless a multiline char has been
drawn in the screen, and chars cut off at the bottom of the screen,
which can only be created by scrolling down or inserting lines, are
tracked so that
linefeeds do not need to scan for them.

A hard reset now clears the alternate screen as well, so that the flag
tracking whether multiline chars have been used can be reset.

Also fix the lower rows of multiline chars being lost on rewrap when the
lines after the char were continuations that fit on its first row.
2026-11-13 10:43:13 +05:30
rudolf-blue
e1250cf8fb Fix erase in line and display orphaning halves of multicell characters 2026-10-08 23:59:56 -04:00
Kovid Goyal
c02f932641
Fix an out of bounds memory access when drawing a multi line character with cursor below bottom margin 2026-09-24 18:49:35 +05:30
Kovid Goyal
7d2fbaadcc
Text sizing protocol: Fix a buffer overflow
When a natural width (no explicit ``w`` key) text sizing escape code
contains a grapheme cluster longer than four codepoints
2026-08-23 07:52:17 +05:30
Kovid Goyal
7f0b072f0d
autoformat 2026-08-05 05:32:56 +05:30
copilot-swe-agent[bot]
a31f9e52f2
Refactor kitty_tests: move __init__.py code to base.py, update all imports 2026-08-05 05:32:54 +05:30
distsystem
875ca70a55 Fix crash in overlay line drawing on uninitialized linebuf view
screen_draw_overlay_line accessed self->linebuf->line->cpu_cells
without ever calling linebuf_init_line on the shared view. Render
paths that initialize a stack-local Line via render_line_for_virtual_y
left the view's cpu_cells as NULL (the value set by alloc_line via
PyType_GenericAlloc), and the multicell-trim loop then dereferenced
NULL + xstart * sizeof(CPUCell), producing a SIGSEGV at a small
address (e.g. 0x1e for xstart=2). The crash was reachable any time
an IME pre-edit overlay was rendered with the cursor not in column 0
on a screen whose linebuf->line had not been re-pointed by some
unrelated prior call.

Fix by initializing the view at the overlay row on entry. Add a
test_draw_overlay_line method on Screen so the behavior can be
exercised directly from a regression test.
2026-04-18 13:10:07 +08:00
Kovid Goyal
b52a9031ca
Fix selections test failing due to pixel scroll
Note this only fixes the test, there is still the actual issue of
the selection not being rendered for the top most line if that line is
partially scrolled offscreen
2026-01-08 12:40:40 +05:30
Kovid Goyal
6db24b66fa
Dont rewrap text in the alternate screen buffer
Avoids flicker during live resize with no resize_debounce_time. See
https://github.com/kovidgoyal/kitty/discussions/9142 for discussion.
2025-11-26 10:29:12 +05:30
Kovid Goyal
75f10d140f
Fix off-by-one in code to nuke incomplete multicell chars in line
Fixes #8758
2025-06-27 11:35:18 +05:30
Kovid Goyal
68b4c3dd6d
Fix ambiguous width and private use characters not being rendered when used with variable width text-sizing protocol escape codes 2025-05-12 05:21:51 +05:30
Kovid Goyal
4c2bd8ffb1
Implement zero width roundtripped chars in multicell segmentation as well 2025-04-11 09:34:21 +05:30
Kovid Goyal
f57f3d9909
Fix #8464 2025-03-21 19:55:45 +05:30
Kovid Goyal
15f711d6b5
Start work on horizontal align for multicells 2025-02-19 07:50:40 +05:30
Kovid Goyal
bedc2ea1b9
Reduce num of bits used for x/y multicell 2025-02-19 05:53:07 +05:30
Kovid Goyal
b4b2b44c92
Multicell selections: Clamp to line
When the end point of the selection is within a multicell character of
the same size and vertical position as the start point, clamp the
selection line to the start line to avoid un-intuitive multiline
selections.

Fixes #8310
2025-02-15 13:11:46 +05:30
Kovid Goyal
dc5c9b5bf4
Another test 2025-02-15 11:38:49 +05:30
Kovid Goyal
0e820f5d9c
ANSI output: Preserve use of natural_width
Keeps semantics of the text the same when roundtripping rather than
visual appearance.
2025-02-15 11:03:20 +05:30
Kovid Goyal
888b8a3bfb
Use same algorithm for multicell selection expansion and text extraction 2025-02-15 10:43:32 +05:30
Kovid Goyal
077116e027
Fix a typo causing corruption of multiline chars split between history buffer and line buffer on resize 2025-02-11 11:55:15 +05:30
Kovid Goyal
8bf8f5dc46
Finish up testing for multicell URL detection 2025-02-03 10:56:50 +05:30
Kovid Goyal
64e3b641ce
Get basic multicell URL detection working 2025-02-03 10:56:50 +05:30
Kovid Goyal
6a19918687
More work on multicell URL detection 2025-02-03 10:56:50 +05:30
Kovid Goyal
f599144913
Fix multicell marking of hyperlinks 2025-02-03 10:56:50 +05:30
Kovid Goyal
2423c2166e
More tests for multicell selections 2025-02-03 10:56:50 +05:30
Kovid Goyal
922d08516b
... 2025-02-03 10:56:50 +05:30
Kovid Goyal
ac1aaab077
More work of selections as text 2025-02-03 10:56:50 +05:30
Kovid Goyal
ac32f91a2e
Implement rendering of selections that intersect multicell cells 2025-02-03 10:56:49 +05:30
Kovid Goyal
dc5037ff37
Add tests for multicell char split between history and line buffers 2025-02-03 10:56:49 +05:30
Kovid Goyal
97449dfddb
Cursor tracking tests
Also fix extra x movement for tracked cursors
2025-02-03 10:56:49 +05:30
Kovid Goyal
b3c39f4921
Finish up the redraw multicell tests 2025-02-03 10:56:49 +05:30
Kovid Goyal
001cc8009e
More multicell rewrap tests 2025-02-03 10:56:49 +05:30
Kovid Goyal
decafb0d3f
More multicell wrap tests 2025-02-03 10:56:49 +05:30
Kovid Goyal
cf5f6e97e8
Add some basic tests for multicell rewrap 2025-02-03 10:56:49 +05:30
Kovid Goyal
5b0e1b5b5c
Fix wrap marker when continuing to a new line with a multicell command 2025-02-03 10:56:48 +05:30
Kovid Goyal
bbcb7dc24c
Fix cursor rendering when on first cell of multicell 2025-02-03 10:56:47 +05:30
Kovid Goyal
f67c58034c
Add tests for ch_and_idx 2025-02-03 10:56:47 +05:30
Kovid Goyal
87dea95a0e
Fix rendering of scaled emoji 2025-02-03 10:56:45 +05:30
Kovid Goyal
27bcd96071
Tests for combining char on multicell 2025-02-03 10:56:45 +05:30
Kovid Goyal
06c428ba7b
Fix drawing multiple chars where the second or later char is on a multicell 2025-02-03 10:56:45 +05:30
Kovid Goyal
4a0086b241
Fix vertical_align serialization 2025-02-03 10:56:45 +05:30
Kovid Goyal
8030cbd361
Allow more subscales 2025-02-03 10:56:44 +05:30
Kovid Goyal
b1c80d212f
Allow non-width multicell code to fill multiple cells using native width algo 2025-02-03 10:56:44 +05:30
Kovid Goyal
844d538e40
When drawing text, skip past multiline chars 2025-02-03 10:56:44 +05:30
Kovid Goyal
35946f9386
Improve performance of processing wide chars
Store multi cell data in the CPUCell rather than in TextCache.
This sends the CPUCell size back to 12 but in benchmarks ASCII
performance is untouched and Unicode performace goes back to what it was
before multicell
2025-02-03 10:56:44 +05:30
Kovid Goyal
383e1f8f57
Work on scaled rendering for box drawing chars 2025-02-03 10:56:43 +05:30
Kovid Goyal
394404a1ab
Add multicell tests for various edit operations 2025-02-03 10:56:43 +05:30
Kovid Goyal
e10df382f8
Tests for erasing characters 2025-02-03 10:56:43 +05:30