/*** Join two lines and strip spaces on the next ***/ void join_strip( Project p ) { LINE *ln; if((ln = p->edited->next) != NULL) { STRPTR data; ULONG i; inv_curs(p, FALSE); p->nbc = p->edited->size; for(i=0, data=ln->stream; TypeChar[*data] == SPACE && i<ln->size; i++, data++); reg_group_by(&p->undo); if(i != ln->size) { /* Do not add a blank if there is already one */ if( p->nbc > 0 && TypeChar[ p->edited->stream[ p->nbc-1 ] ] != SPACE ) add_char(&p->undo, p->edited, p->nbc, ' '); if( insert_str(&p->undo, p->edited, p->edited->size, data, ln->size-i) == 0 ) ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } /* ln can't be the first */ del_line(&p->undo, NULL, ln); p->max_lines--; reg_group_by(&p->undo); prop_adj(p); /* Refresh screen */ p->nbrc = p->nbrwc = x2pos(p->edited, p->nbc); REDRAW_CURLINE( p ); draw_info( p ); scroll_up(p, p->edited->next, p->ycurs, center_horiz(p)); inv_curs(p,TRUE); } }
/*** Remove the char under the cursor ***/ void del(Project p, BYTE word) { if(p->nbc < p->edited->size) { ULONG nbc = word ? forward_word(p->edited,p->nbc)-1 : p->nbc; rem_chars(&p->undo, p->edited, p->nbc, nbc); REDRAW_CURLINE(p); inv_curs(p, TRUE); } else if(p->edited->next) { /* Join current and next line: */ if( join_lines(&p->undo, p->edited, p->edited->next) ) { REDRAW_CURLINE(p); /* Is it needed to scroll display? */ if(p->ycurs < gui.botcurs) scroll_up(p,p->edited->next,p->ycurs,p->left_pos); /* Redraw the cursor: */ inv_curs(p,TRUE); p->max_lines--; prop_adj(p); } else ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } }
/*** Move cursor to absolute position ***/ void move_to_line(Project p, ULONG nbline, char dirtiness) { ULONG newtop; if(!p->ccp.select) inv_curs(p,FALSE); /* Get the new top line */ { register ULONG old_nbl = p->nbl; p->nbl = nbline; newtop = center_vert(p); p->nbl = old_nbl; } set_cursor_line(p, nbline, newtop); if(dirtiness == LINE_AS_IS) scroll_xy(p, center_horiz(p), newtop, TRUE); else { /* Some lines are modified: redraw in one pass */ if( newtop == p->top_line ) { REDRAW_CURLINE(p); if( dirtiness == LINES_DIRTY ) scroll_up(p, p->edited->next, p->ycurs, center_horiz(p)), prop_adj(p); else if( p->left_pos != (newtop = center_horiz(p)) ) scroll_xy(p, newtop, p->top_line, FALSE); } else if( dirtiness == LINE_DIRTY ) scroll_xy(p, center_horiz(p), newtop, TRUE); else set_top_line(p, newtop, center_horiz(p)); } /* Move cursor or selection */ if(p->ccp.select) move_selection(p, p->nbrwc, p->nbl); inv_curs(p,TRUE); draw_info( p ); }
/*** Set top-left visible corner ***/ void set_top_line(Project p, ULONG top, ULONG left) { LINE *ln; LONG nb = top-p->top_line; if(nb < 0) for(ln=p->show; nb++; ln=ln->prev); else for(ln=p->show; nb--; ln=ln->next); p->show = ln; p->top_line = top; p->left_pos = left; p->xcurs = (p->nbrc-p->left_pos) * XSIZE + gui.left; redraw_content(p, ln, gui.topcurs, gui.nbline); prop_adj( p ); }
/*** Refresh display, according to new window size ***/ void new_size(UBYTE Flags) { inv_curs(edit, FALSE); adjust_win(Wnd,NbProject>1); /* Adjust internal variables */ SetABPenDrMd(RP, pen.fg, pen.bg, JAM2); clear_brcorner(); prop_adj(edit); edit->left_pos = curs_visible(edit, edit->top_line); edit->xcurs = (edit->nbrc - edit->left_pos)*XSIZE + gui.left; if(Flags & EDIT_GUI) reshape_panel(edit); if(Flags & EDIT_AREA) redraw_content(edit,edit->show,gui.topcurs,gui.nbline); inv_curs(edit,TRUE); }
/*** Remove the char before the cursor ***/ void back_space(Project p, BYTE word) { if(p->nbc!=0) { ULONG nbc = word ? backward_word(p->edited,p->nbc-1) : p->nbc-1; rem_chars(&p->undo, p->edited, nbc, p->nbc-1); /* Set cursor position and redraws it */ inv_curs(p,FALSE); REDRAW_CURLINE(p); p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc=nbc); p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left; if( (nbc = center_horiz(p)) != p->left_pos ) scroll_xy(p, nbc, p->top_line, FALSE); inv_curs(p,TRUE); draw_info( p ); } else if(p->edited->prev != NULL) { p->edited = p->edited->prev; p->nbc = p->edited->size; /* Join previous and current line */ if( join_lines(&p->undo, p->edited, p->edited->next) ) { /* Move cursor to the end of previous line */ p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc); p->max_lines--; p->nbl--; /* Require to scroll the display? */ inv_curs(p, FALSE); if(p->ycurs>gui.topcurs) scroll_up(p, p->edited->next, p->ycurs-=YSIZE, center_horiz(p)); else p->top_line--, p->show = p->edited, p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left; SetAPen(RP, pen.fg); REDRAW_CURLINE(p); /* Redraw the cursor: */ inv_curs(p,TRUE); draw_info(p); prop_adj(p); } else ThrowError(Wnd, ErrMsg(ERR_NOMEM)); } }
/*** Remove an entire line ***/ void amiga_k(Project p) { LINE *del = p->edited; if(p->ccp.select) return; /* In there a next line, move cursor to */ if( del->next ) { p->edited=del->next; p->max_lines--; if(p->show==del) p->show=del->next; prop_adj(p); } /* Adjust cursor position */ inv_curs(p,FALSE); del_line(&p->undo, &p->the_line, del); p->nbrc = adjust_rc(p->edited, p->nbrwc, &p->nbc, FALSE); REDRAW_CURLINE(p); scroll_up(p, p->edited->next, p->ycurs, center_horiz(p)); inv_curs(p,TRUE); }
/*** Split line ***/ void split_curline( Project p ) { if( split_line(&p->undo, p->edited, p->nbc, &p->nbrwc, prefs.auto_indent) ) { register LINE *ln = p->edited; /* Redraw line where cursor is */ Move(RP,gui.left,p->ycurs); write_text(p, ln); /* A line has been added */ p->max_lines++; p->nbrwc = x2pos(ln,p->nbrwc); /* Scroll manually the display and redraw new line */ if(p->ycurs < gui.botcurs) { ScrollRaster(RP, 0, -YSIZE, gui.left,p->ycurs+YSIZE-BASEL,gui.right,gui.bottom); Move(RP,gui.left,p->ycurs+YSIZE); ln = ln->next; write_text(p, ln); prop_adj(p); } /* Go down one line */ curs_down(p); } else ThrowError(Wnd, ErrMsg(ERR_NOMEM)); }