Ensure cursor is correctly positioned after emoji presentation char + VS15

cursor should be on the cell immediately after the the char since the
variation selector makes the char one cell wide.
This commit is contained in:
Kovid Goyal 2019-05-13 20:18:41 +05:30
parent fe882dad15
commit 529337e00a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 27 additions and 0 deletions

View File

@ -373,6 +373,19 @@ draw_combining_char(Screen *self, char_type ch) {
if (xpos == self->columns - 1) move_widened_char(self, cpu_cell, gpu_cell, xpos, ypos);
else self->cursor->x++;
}
} else if (ch == 0xfe0e) {
CPUCell *cpu_cell = self->linebuf->line->cpu_cells + xpos;
GPUCell *gpu_cell = self->linebuf->line->gpu_cells + xpos;
if ((gpu_cell->attrs & WIDTH_MASK) == 0 && cpu_cell->ch == 0 && xpos > 0) {
xpos--;
if (self->cursor->x > 0) self->cursor->x--;
cpu_cell = self->linebuf->line->cpu_cells + xpos;
gpu_cell = self->linebuf->line->gpu_cells + xpos;
}
if ((gpu_cell->attrs & WIDTH_MASK) == 2 && cpu_cell->cc_idx[0] == VS15 && is_emoji_presentation_base(cpu_cell->ch)) {
gpu_cell->attrs = (gpu_cell->attrs & !WIDTH_MASK) | 1;
}
}
}
}

View File

@ -429,6 +429,20 @@ class TestScreen(BaseTest):
s.scroll(2, True)
self.ae(s.text_for_selection(), expected)
def test_variation_selectors(self):
s = self.create_screen()
s.draw('\U0001f610')
self.ae(s.cursor.x, 2)
s.carriage_return(), s.linefeed()
s.draw('\U0001f610\ufe0e')
self.ae(s.cursor.x, 1)
s.carriage_return(), s.linefeed()
s.draw('\u25b6')
self.ae(s.cursor.x, 1)
s.carriage_return(), s.linefeed()
s.draw('\u25b6\ufe0f')
self.ae(s.cursor.x, 2)
def test_serialize(self):
s = self.create_screen()
s.draw('ab' * s.columns)