Changeset 16cfd12a


Ignore:
Timestamp:
Jul 11, 2009, 1:14:35 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7f0c26f
Parents:
8321cb7
git-author:
Karl Ramm <kcr@1ts.org> (06/13/09 16:27:21)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:35)
Message:
wrap words on insert character

ow, brain hurty.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r8321cb7 r16cfd12a  
    1212  int valid;
    1313  int index;
     14  int mark;
    1415  int goal_column;
    1516  int lock;
     
    2324  int allocated;
    2425  int index;
     26  int mark;
    2527  int goal_column;
    2628  int topindex;
     
    4648static int oe_count_glyphs(char *s);
    4749static int oe_char_width(gunichar c, int column);
     50static int oe_region_width(owl_editwin *e, int start, int end, int width);
    4851static int oe_find_display_line(owl_editwin *e, int *x, int index);
    4952static void oe_insert_char(owl_editwin *e, gunichar c);
     
    98101  e->allocated=INCR;
    99102  oe_set_index(e, 0);
     103  e->mark = 0;
    100104  e->goal_column = -1;
    101105  e->cursorx = -1;
     
    10461050}
    10471051
     1052static int oe_region_width(owl_editwin *e, int start, int end, int width)
     1053{
     1054  char *p;
     1055  for(p = e->buff + start;
     1056      p < e->buff + end;
     1057      p = g_utf8_find_next_char(p, NULL))
     1058    width += oe_char_width(g_utf8_get_char(p), width);
     1059
     1060  return width;
     1061}
     1062
    10481063static void oe_insert_char(owl_editwin *e, gunichar c)
    10491064{
     1065  oe_excursion x;
    10501066  char tmp[7];
     1067  int replaced = -1;
    10511068
    10521069  if (c == '\r') /* translate CRs to NLs */
    10531070    c = '\n';
    10541071
    1055   if (!g_unichar_iscntrl(c) || c == '\n' || c== '\n' ) {
     1072  if (!g_unichar_iscntrl(c) || c == '\n' || c== '\t' ) {
    10561073    memset(tmp, 0, 7);
    10571074
     
    10591076      return;
    10601077    }
     1078
     1079    if (e->cursorx != -1 && e->cursorx + oe_char_width(c, e->cursorx) > e->wrapcol) {
     1080      /* XXX this is actually wrong:
     1081       * + If the line has been been wrapped, we can be past the wrap column but
     1082       *   e->cursorx be much smaller.
     1083       * + If the user went back and inserted a bunch of stuff in the middle of
     1084       *   the line, there may be more than one word past the wrap column.
     1085       */
     1086      oe_save_excursion(e, &x);
     1087
     1088      if (c == ' ' || c == '\t') {
     1089        owl_editwin_point_move(e, -1);
     1090        replaced = -owl_editwin_move_if_in(e, -1, " \t");
     1091        if (!replaced) {
     1092          c = '\n';
     1093          replaced = -1;
     1094        }
     1095      } else {
     1096        while(!owl_editwin_at_beginning_of_line(e)) {
     1097          owl_editwin_point_move(e, -1);
     1098          if (owl_util_can_break_after(owl_editwin_get_char_at_point(e))) {
     1099            replaced = -owl_editwin_move_if_in(e, -1, " \t");
     1100            break;
     1101          }
     1102        }
     1103        if (owl_editwin_at_beginning_of_line(e))
     1104          replaced = -1;
     1105      }
     1106      if (replaced && !owl_editwin_at_beginning_of_line(e))
     1107        owl_editwin_point_move(e, 1);
     1108      if (replaced >= 0) {
     1109        owl_editwin_replace(e, replaced, "\n");
     1110      }
     1111     
     1112      oe_restore_excursion(e, &x);
     1113    }
     1114
     1115    if (replaced >= 0 && (c == ' ' || c == '\t'))
     1116      return; /* our work here is done */
    10611117
    10621118    g_unichar_to_utf8(c, tmp);
Note: See TracChangeset for help on using the changeset viewer.