Fix backspacing of wide characters in wide-character unaware programs not working

Fixes #875
This commit is contained in:
Kovid Goyal
2018-09-07 10:08:25 +05:30
parent 60fcf7ab3d
commit 7f0674ac27
3 changed files with 20 additions and 1 deletions

View File

@@ -13,6 +13,8 @@ Changelog
font fallback for all subsequent characters that cannot be rendered in the
main font to fail (:iss:`799`)
- Fix backspacing of wide characters in wide-character unaware programs not working (:iss:`875`)
- Linux: Fix number pad arrow keys not working when Numlock is off (:iss:`857`)
- Wayland: Implement support for clipboard copy/paste (:iss:`855`)

View File

@@ -708,7 +708,15 @@ screen_is_cursor_visible(Screen *self) {
void
screen_backspace(Screen *self) {
screen_cursor_back(self, 1, -1);
unsigned int amount = 1;
if (self->cursor->x < self->columns && self->cursor->x > 1) {
// check if previous character is a wide character
linebuf_init_line(self->linebuf, self->cursor->y);
unsigned int xpos = self->cursor->x - 2;
GPUCell *gpu_cell = self->linebuf->line->gpu_cells + xpos;
if ((gpu_cell->attrs & WIDTH_MASK) == 2) amount = 2;
}
screen_cursor_back(self, amount, -1);
}
void

View File

@@ -222,6 +222,15 @@ class TestScreen(BaseTest):
for i in range(1, 5):
self.ae(str(s.line(i)), '12345')
def test_backspace_wide_characters(self):
s = self.create_screen()
s.draw('')
self.ae(s.cursor.x, 2)
s.backspace()
s.draw(' ')
s.backspace()
self.ae(s.cursor.x, 0)
def test_resize(self):
s = self.create_screen(scrollback=6)
s.draw(''.join([str(i) * s.columns for i in range(s.lines)]))