Overwrite mode added, toggled with INSERTKEY
This commit is contained in:
@@ -81,6 +81,7 @@ void txt_do_redo (struct Text *text);
|
||||
void txt_split_curline (struct Text *text);
|
||||
void txt_backspace_char (struct Text *text);
|
||||
int txt_add_char (struct Text *text, char add);
|
||||
int txt_replace_char (struct Text *text, char add);
|
||||
void txt_find_panel (struct SpaceText *st, int again);
|
||||
void run_python_script (struct SpaceText *st);
|
||||
int jumptoline_interactive (struct SpaceText *st);
|
||||
|
||||
@@ -2140,6 +2140,34 @@ int txt_add_char (Text *text, char add)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int txt_replace_char (Text *text, char add)
|
||||
{
|
||||
char del;
|
||||
|
||||
if (!text) return 0;
|
||||
if (!text->curl) return 0;
|
||||
|
||||
/* If text is selected or we're at the end of the line just use txt_add_char */
|
||||
if (text->curc==text->curl->len || text->sell!=text->curl || text->selc!=text->curc || add=='\n') {
|
||||
return txt_add_char(text, add);
|
||||
}
|
||||
|
||||
del= text->curl->line[text->curc];
|
||||
text->curl->line[text->curc]= (unsigned char) add;
|
||||
text->curc++;
|
||||
txt_pop_sel(text);
|
||||
|
||||
txt_make_dirty(text);
|
||||
txt_clean_text(text);
|
||||
|
||||
/* Should probably create a new op for this */
|
||||
if(!undoing) {
|
||||
txt_undo_add_charop(text, UNDO_DEL, del);
|
||||
txt_undo_add_charop(text, UNDO_INSERT, add);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void indent(Text *text)
|
||||
{
|
||||
int len, num;
|
||||
|
||||
@@ -281,7 +281,7 @@ typedef struct SpaceText {
|
||||
int tabnumber;
|
||||
int currtab_set;
|
||||
int showsyntax;
|
||||
int unused_padd;
|
||||
int overwrite;
|
||||
|
||||
float pix_per_line;
|
||||
|
||||
|
||||
@@ -634,10 +634,11 @@ static void set_cursor_to_pos (SpaceText *st, int x, int y, int sel)
|
||||
}
|
||||
|
||||
static void draw_cursor(SpaceText *st) {
|
||||
int h, x, i;
|
||||
int h, x, i, w;
|
||||
Text *text= st->text;
|
||||
TextLine *linef, *linel;
|
||||
int charf, charl;
|
||||
char ch[2];
|
||||
|
||||
if (text->curl==text->sell && text->curc==text->selc) {
|
||||
x= text_draw(st, text->curl->line, st->left, text->curc, 0, 0, 0, NULL);
|
||||
@@ -645,9 +646,19 @@ static void draw_cursor(SpaceText *st) {
|
||||
if (x) {
|
||||
h= txt_get_span(text->lines.first, text->curl) - st->top;
|
||||
|
||||
BIF_ThemeColor(TH_HILITE);
|
||||
|
||||
glRecti(x-1, curarea->winy-st->lheight*(h)-2, x+1, curarea->winy-st->lheight*(h+1)-2);
|
||||
if (st->overwrite) {
|
||||
ch[0]= (unsigned char) text->curl->line[text->curc];
|
||||
if (ch[0]=='\0') ch[0]=' ';
|
||||
ch[1]= '\0';
|
||||
w= BMF_GetStringWidth(spacetext_get_font(st), ch);
|
||||
BIF_ThemeColor(TH_SHADE2);
|
||||
glRecti(x, curarea->winy-st->lheight*(h)-2, x+w, curarea->winy-st->lheight*(h+1)-2);
|
||||
BIF_ThemeColor(TH_HILITE);
|
||||
glRecti(x, curarea->winy-st->lheight*(h+1)-3, x+w, curarea->winy-st->lheight*(h+1)-1);
|
||||
} else {
|
||||
BIF_ThemeColor(TH_HILITE);
|
||||
glRecti(x-1, curarea->winy-st->lheight*(h)-2, x+1, curarea->winy-st->lheight*(h+1)-2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int span= txt_get_span(text->curl, text->sell);
|
||||
@@ -1594,7 +1605,7 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
||||
}
|
||||
}
|
||||
} else if (ascii) {
|
||||
if (txt_add_char(text, ascii)) {
|
||||
if ((st->overwrite && txt_replace_char(text, ascii)) || txt_add_char(text, ascii)) {
|
||||
if (st->showsyntax) get_format_string(st);
|
||||
pop_space_text(st);
|
||||
do_draw= 1;
|
||||
@@ -1894,6 +1905,10 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
||||
pop_space_text(st);
|
||||
st->currtab_set = setcurr_tab(text);
|
||||
break;
|
||||
case INSERTKEY:
|
||||
st->overwrite= !st->overwrite;
|
||||
do_draw= 1;
|
||||
break;
|
||||
case DOWNARROWKEY:
|
||||
txt_move_down(text, G.qual & LR_SHIFTKEY);
|
||||
set_tabs(text);
|
||||
|
||||
@@ -6011,6 +6011,8 @@ static void init_textspace(ScrArea *sa)
|
||||
st->lheight= 12;
|
||||
st->showlinenrs= 0;
|
||||
st->tabnumber = 4;
|
||||
st->showsyntax= 0;
|
||||
st->overwrite= 0;
|
||||
st->currtab_set = 0;
|
||||
|
||||
st->top= 0;
|
||||
|
||||
Reference in New Issue
Block a user