Skip to content
Myr

render: need character position, but prompt.cursor is byte position

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 109129e · Browse files · 1 file+19 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−3 removed

  • other:+19 added−3 removed

1 file+19 added−3 removed

modified:render.c+19 added-3 removed
1 unmodified line
23#include <stdlib.h>4#include <string.h>56#define LOG_MODULE "render"7#include "log.h"8#include "font.h"910struct render {11 cairo_scaled_font_t *scaled_font;
38 unmodified lines
50 cairo_show_text_glyphs(51 buf->cairo, text, -1, glyphs, num_glyphs,52 clusters, num_clusters, cluster_flags);5354 /* prompt->cursor is the *byte* position, but we need the55 * *character| position */56 int cursor_at_glyph = 0;57 size_t i = 0;58 while (i < prompt->cursor) {59 if ((unsigned char)prompt->text[i] >> 7) {60 i++;61 while (((unsigned char)prompt->text[i] & 0xc0) == 0x80)62 i++;63 } else64 i++;65 cursor_at_glyph++;66 }6768 int cursor_x;53 if (prompt->cursor == 0)69 if (cursor_at_glyph == 0)70 cursor_x = x;55 else if (prompt->cursor >= (size_t)num_glyphs)71 else if (cursor_at_glyph >= num_glyphs)72 cursor_x = x + extents.x_advance;73 else58 cursor_x = glyphs[prompt->cursor].x;74 cursor_x = glyphs[cursor_at_glyph].x;7576 cairo_set_line_width(buf->cairo, 1);77 cairo_move_to(buf->cairo, cursor_x - 0.5, y_base + 2);78 cairo_line_to(buf->cairo, cursor_x - 0.5, y_base + y_advance - 2);
93 unmodified lines