Changeset ac6d4e4 for editwin.c


Ignore:
Timestamp:
Sep 30, 2010, 8:07:17 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
385cce2
Parents:
9c3f334
git-author:
David Benjamin <davidben@mit.edu> (09/29/10 15:41:28)
git-committer:
David Benjamin <davidben@mit.edu> (09/30/10 20:07:17)
Message:
Cache the current column to avoid repeatly recomputing it

In particular, we appropriately update it when inserting characters.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r9c3f334 rac6d4e4  
    2727  int goal_column;
    2828  int topindex;
     29  int column;
    2930  int winlines, wincols, fillcol, wrapcol;
    3031  owl_window *win;
     
    5051static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x);
    5152static int oe_char_width(gunichar c, int column);
    52 static int oe_region_width(owl_editwin *e, int start, int end, int width);
     53static int oe_region_column(owl_editwin *e, int start, int end, int offset);
     54static int oe_region_width(owl_editwin *e, int start, int end, int offset);
    5355static int oe_find_display_line(owl_editwin *e, int *x, int index, int *hard);
    5456static void oe_insert_char(owl_editwin *e, gunichar c);
     
    100102  if (index != e->index) {
    101103    e->goal_column = -1;
     104    e->column = -1;
    102105  }
    103106  e->index = index;
     
    133136  e->killbuf = NULL;
    134137  e->goal_column = -1;
     138  e->column = -1;
    135139  e->topindex = 0;
    136140  e->excursions = NULL;
     
    646650static int owl_editwin_replace_internal(owl_editwin *e, int replace, const char *s)
    647651{
    648   int start, end, free, need, size, change;
     652  int start, end, free, need, size, change, oldindex;
    649653  oe_excursion *x;
    650654
     
    665669  change = start - end + strlen(s);
    666670  e->bufflen += change;
     671  oldindex = e->index;
    667672  e->index += strlen(s);
     673  if (e->column != -1)
     674    e->column = oe_region_column(e, oldindex, e->index, e->column);
    668675
    669676  /* fix up the mark */
     
    11461153int owl_editwin_current_column(owl_editwin *e)
    11471154{
    1148   oe_excursion x;
    1149   int lineindex;
    1150 
    1151   oe_save_excursion(e, &x);
    1152   owl_editwin_move_to_beginning_of_line(e);
    1153   lineindex = e->index;
    1154   oe_restore_excursion(e, &x);
    1155   return oe_region_width(e, lineindex, e->index, 0);
     1155  if (e->column == -1) {
     1156    oe_excursion x;
     1157    int lineindex;
     1158
     1159    oe_save_excursion(e, &x);
     1160    owl_editwin_move_to_beginning_of_line(e);
     1161    lineindex = e->index;
     1162    oe_restore_excursion(e, &x);
     1163    e->column = oe_region_width(e, lineindex, e->index, 0);
     1164  }
     1165  return e->column;
    11561166}
    11571167
     
    12721282    return;
    12731283  }
     1284}
     1285
     1286static int oe_region_column(owl_editwin *e, int start, int end, int offset)
     1287{
     1288  const char *p;
     1289  int column = offset;
     1290
     1291  for(p = e->buff + start;
     1292      p < e->buff + end;
     1293      p = g_utf8_find_next_char(p, NULL)) {
     1294    gunichar c = g_utf8_get_char(p);
     1295    if (c == '\n')
     1296      column = 0;
     1297    else
     1298      column += oe_char_width(c, column);
     1299  }
     1300  return column;
    12741301}
    12751302
Note: See TracChangeset for help on using the changeset viewer.