Changeset 19f765d


Ignore:
Timestamp:
Jul 11, 2009, 1:14:33 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
d7043b4
Parents:
e20d8179
git-author:
Karl Ramm <kcr@1ts.org> (06/07/09 19:44:13)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:33)
Message:
Refactoring + cleanup.

Factor oe_display_line out of owl_editwin_redisplay so that I can
use it in oe_reframe.  I think this ends up making some of the cursor
placement stuff simpler as a side effect.

Also cleanup an unused variable in owl_editwin_point_move.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    re20d8179 r19f765d  
    291291}
    292292
     293static int oe_find_display_line(owl_editwin *e, int *x, int index)
     294{
     295  int width = 0, cw;
     296  gunichar c = -1;
     297  char *p;
     298
     299  while(1) {
     300    /* are we at the point? */
     301    if (x != NULL && index == e->index)
     302      *x = width;
     303
     304    /* get the current character */
     305    c = g_utf8_get_char(e->buff + index);
     306
     307    /* figure out how wide it is */
     308    if (c == 9) /* TAB */
     309      cw = TABSIZE - width % TABSIZE;
     310    else
     311      cw = mk_wcwidth(c);
     312    if (cw < 0) /* control characters */
     313        cw = 0;
     314
     315    if (width + cw > e->wincols)
     316      break;
     317    width += cw;
     318
     319    if (c == '\n') {
     320      ++index; /* skip the newline */
     321      break;
     322    }
     323
     324    /* find the next character */
     325    p = oe_next_point(e, e->buff + index);
     326    if (p == NULL) { /* we ran off the end */
     327      if (x != NULL && e->index > index)
     328        *x = width + 1;
     329      break;
     330    }
     331    index = p - e->buff;
     332  }
     333  return index;
     334}
     335
    293336static void oe_reframe(owl_editwin *e) {
    294337  e->topindex = 0; /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
     
    299342void owl_editwin_redisplay(owl_editwin *e, int update)
    300343{
    301   int x = -1, y = -1;  char *p;
    302   int width, line, index, lineindex, cw;
    303   gunichar c;
     344  int x = -1, y = -1, t;
     345  int line, index, lineindex;
    304346
    305347  werase(e->curswin);
     
    312354    index = e->topindex;
    313355    while(line < e->winlines) {
    314       width = 0;
    315356      lineindex = index;
    316       /* okay, we want to find no nore that e->wincols cells or a \n */
    317       /* then waddnstr it */
    318       /* and as a side effect, noting where the cursor should end up */
    319       while(1) {
    320         c = g_utf8_get_char(e->buff + index);
    321         if (index == e->index)
    322           y = line, x = width;
    323         if (c == 9) /* TAB */
    324           cw = 8 - width % 8;
    325         else
    326           cw = mk_wcwidth(c);
    327         if (width + cw > e->wincols)
    328           break;
    329         width += cw;
    330         p = oe_next_point(e, e->buff + index);
    331         if (p == NULL) /* we ran off the end */
    332           break;
    333         index = p - e->buff;
    334         if (c == '\n')
    335           break;
    336       }
     357      t = -1;
     358      index = oe_find_display_line(e, &t, lineindex);
     359      if (x == -1 && t != -1)
     360        x = t, y = line;
    337361      if (index - lineindex)
    338362        mvwaddnstr(e->curswin, line, 0,
    339363                   e->buff + lineindex,
    340364                   index - lineindex);
    341       if (p == NULL)
    342         break;
    343365      line++;
    344366    }
    345     if (x == -1) {
    346       if (p == NULL && c != '\n')
    347         y = line, x = width;
    348       else if (p == NULL)
    349         y = line + 1, x = 0;
    350       else
     367    if (x == -1)
    351368        e->topindex = -1; /* force a reframe */
    352     }
    353369  } while(x == -1);
    354370
    355   if (x != -1)
    356     wmove(e->curswin, y, x);
     371  wmove(e->curswin, y, x);
    357372  wnoutrefresh(e->curswin);
    358373  if (update == 1)
     
    668683{
    669684  char *p;
    670   int change, index, d = 0;
     685  int change, d = 0;
    671686
    672687  change = MAX(delta, - delta);
Note: See TracChangeset for help on using the changeset viewer.