diff options
Diffstat (limited to 'src/glibext/gbufferview.c')
-rw-r--r-- | src/glibext/gbufferview.c | 112 |
1 files changed, 26 insertions, 86 deletions
diff --git a/src/glibext/gbufferview.c b/src/glibext/gbufferview.c index 2deeffe..9f17e24 100644 --- a/src/glibext/gbufferview.c +++ b/src/glibext/gbufferview.c @@ -84,7 +84,7 @@ static void g_buffer_view_finalize(GBufferView *); static void on_buffer_size_changed(const GCodeBuffer *, bool, size_t, size_t, GBufferView *); /* Réagit à un changement de contenu d'une ligne donnée. */ -static void on_buffer_line_changed(GCodeBuffer *, GBufferLine *, GBufferSegment *, GBufferView *); +static void on_buffer_line_changed(GCodeBuffer *, GBufferLine *, line_segment *, GBufferView *); /* Déplace le curseur au sein d'une vue de tampon. */ static bool _g_buffer_view_move_caret(GBufferView *, const GBufferLine *, size_t, GdkRectangle *, bool, GdkScrollDirection, const bool *); @@ -362,7 +362,7 @@ static void on_buffer_size_changed(const GCodeBuffer *buffer, bool added, size_t * * ******************************************************************************/ -static void on_buffer_line_changed(GCodeBuffer *buffer, GBufferLine *line, GBufferSegment *segment, GBufferView *view) +static void on_buffer_line_changed(GCodeBuffer *buffer, GBufferLine *line, line_segment *segment, GBufferView *view) { const vmpa2t *addr; /* Localisation de ligne */ @@ -588,31 +588,22 @@ const vmpa2t *g_buffer_view_compute_caret(GBufferView *view, gint x, gint y, con gint remaining; /* Copie de travail modifiable */ size_t index; /* Indice de ligne de tampon */ GBufferLine *line; /* Ligne à la position courante*/ - GBufferSegment *segment; /* Segment présent sur la place*/ + const line_segment *segment; /* Segment présent sur la place*/ GBufferViewClass *class; /* Classe pour les vues */ remaining = x; line = g_buffer_view_find_line_and_segment_at(view, &remaining, y, &index, display, &segment); + /* FIXME : unref() ! */ if (line == NULL) return NULL; if (segment == NULL) printf(" -- no segment\n"); if (segment == NULL) return NULL; - - - - printf("\n[BASE] orig = %d tronc = %d reste = %d dernier = %d largeur = %d\n", - x, x - remaining, remaining, g_buffer_segment_get_caret_position(segment, remaining), - g_buffer_segment_get_width(segment)); - - printf(" '%s'\n", g_buffer_segment_get_text(segment, false)); - - class = G_BUFFER_VIEW_GET_CLASS(view); - caret->x = /*view->left_text +*/ (x - remaining) + g_buffer_segment_get_caret_position(segment, remaining); + caret->x = /*view->left_text +*/ (x - remaining) + get_caret_position_from_line_segment(segment, remaining); caret->y = (index - view->first) * class->line_height; @@ -647,10 +638,7 @@ const vmpa2t *g_buffer_view_compute_caret_full(GBufferView *view, GBufferLine *l gint offset; /* Point de travail modifiable */ line_width_summary summary; /* Résumé concis des largeurs */ gint base; /* Position absolue de segment */ - GBufferSegment *segment; /* Segment visé par le pointeur*/ - - - + bool status; /* Bilan de la localisation */ class = G_BUFFER_VIEW_GET_CLASS(view); @@ -661,13 +649,13 @@ const vmpa2t *g_buffer_view_compute_caret_full(GBufferView *view, GBufferLine *l g_width_tracker_get_local_width_summary(view->tracker, index, &summary); - segment = g_buffer_line_get_segment_at(line, &summary, display, &base, &offset, GDK_SCROLL_LEFT, true); - if (segment == NULL) return NULL; + /* Traitement pour mise à jour de l'abscisse uniquement */ + status = g_buffer_line_get_coord_at(line, &summary, display, &base, &offset, + GDK_SCROLL_LEFT, true, (col_coord_t []) { { 0 } }); + if (!status) return NULL; caret->x = class->left_text + base + offset; - printf("caret Y : %zu -> %zu\n", view->first, index); - caret->y = (index - view->first) * class->line_height; caret->width = 2; @@ -702,9 +690,8 @@ static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line gint offset; /* Point de travail modifiable */ line_width_summary summary; /* Résumé concis des largeurs */ gint base; /* Position absolue de segment */ - GBufferSegment *segment; /* Segment visé par le pointeur*/ - - + col_coord_t coord; /* Coordonnées en interne */ + const line_segment *segment; /* Bribe de texte trouvée */ offset = caret->x; @@ -713,64 +700,29 @@ static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line g_width_tracker_get_local_width_summary(view->tracker, index, &summary); - segment = g_buffer_line_get_segment_at(line, &summary, display, &base, &offset, dir, false); - - if (segment == NULL) printf(" ===== NO SEG...\n"); - - if (segment == NULL) return false; - - - printf(" ====== FIRST SEG :: %p ('%s')\n", segment, g_buffer_segment_get_text(segment, false)); - - - + /* Déplacement au sein du segment courant ? */ + result = g_buffer_line_get_coord_at(line, &summary, display, &base, &offset, dir, false, &coord); + if (result) + { + segment = g_buffer_line_get_segment_from_coord(line, &coord); - //if (dir == GDK_SCROLL_LEFT || dir == GDK_SCROLL_RIGHT) - result = g_buffer_segment_move_caret(segment, &offset, ctrl, dir); - //else - //result = true; + result = move_caret_on_line_segment(segment, &offset, ctrl, dir); - printf(" ====== MOVE 1 ? %d\n", result); + } - /////////////////// + /* Tentative de déplacement chez le segment voisin ? */ if (!result) { base = 0; - segment = g_buffer_line_find_near_segment(line, segment, &summary, display, dir, &offset); - - - printf(" ====== NEAR SEG :: %p ('%s')\n", segment, segment ? g_buffer_segment_get_text(segment, false) : NULL); - - if (segment != NULL) - { - - result = true; - //result = g_buffer_segment_move_caret(segment, &offset, ctrl, dir); - - /* - if (result) - caret->x -= COL_MARGIN; - */ - - printf(" ====== MOVE 2 ? %d (offset=%d)\n", result, offset); - - - } - + result = g_buffer_line_find_near_coord(line, &coord, &summary, display, dir, &offset); } - - if (result) - printf(" ====== NEW CARET: %d -> %d\n", caret->x, G_BUFFER_VIEW_GET_CLASS(view)->left_text + base + offset); - else - printf(" ====== NO NEW CARET!\n"); - - + /* Mise à jour éventuelle */ if (result) caret->x = G_BUFFER_VIEW_GET_CLASS(view)->left_text + base + offset; @@ -804,7 +756,6 @@ const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, b line_width_summary summary; /* Résumé concis des largeurs */ - bool computed; /* Récursivité pris en compte */ gint left_pos; /* Retour à la ligne */ gint right_pos; /* Position d'extrème droite */ BufferLineColumn i; /* Boucle de parcours */ @@ -833,8 +784,6 @@ const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, b g_width_tracker_get_local_width_summary(view->tracker, index, &summary); - computed = false; - switch (dir) { case GDK_SCROLL_UP: @@ -933,17 +882,6 @@ BufferLineColumn g_buffer_line_get_merge_start(const GBufferLine *line) } - /* - printf(" --- CARET --- moved = %d index = %d result = %p\n", - moved, index, result); - */ - - - /* - if (result && !computed) - result = g_buffer_view_compute_caret_full(view, caret->x, caret->y, caret, display, NULL); - */ - return result; } @@ -990,7 +928,7 @@ bool g_buffer_view_unhighlight_segments(GBufferView *view) bool g_buffer_view_highlight_segments(GBufferView *view, gint x, gint y, const bool *display) { bool need_redraw; /* Besoin d'actualisation ? */ - GBufferSegment *segment; /* Segment sélectionnable */ + const line_segment *segment; /* Segment sélectionnable */ if (view->highlighted != NULL) need_redraw = g_buffer_view_unhighlight_segments(view); @@ -1199,6 +1137,8 @@ GBufferLine *g_buffer_view_find_line_at(GBufferView *view, gint y, size_t *idx) if (index <= view->last) result = g_code_buffer_find_line_by_index(view->buffer, index); + else + result = NULL; if (result != NULL && idx != NULL) *idx = index; @@ -1225,7 +1165,7 @@ GBufferLine *g_buffer_view_find_line_at(GBufferView *view, gint y, size_t *idx) * * ******************************************************************************/ -GBufferLine *g_buffer_view_find_line_and_segment_at(GBufferView *view, gint *x, gint y, size_t *idx, const bool *display, GBufferSegment **segment) +GBufferLine *g_buffer_view_find_line_and_segment_at(GBufferView *view, gint *x, gint y, size_t *idx, const bool *display, const line_segment **segment) { GBufferLine *result; /* Ligne trouvée à retourner */ size_t index; /* Indice de la ligne trouvée */ |