diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-06-05 03:20:54 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-06-05 03:20:54 +0400 |
commit | a68975f4e14687207529fa7dcc6a397abe5680ac (patch) | |
tree | 6b422f025a8bddaa561532624ac69c0025e855e5 | |
parent | ec4b6ba3f3d80113e422aef721389aac74bc66c5 (diff) |
Whole word operations added:
* Alt-Left/Right: moves cursor/selection a word to the left/right
* Alt-/Ctrl-Delete/Backspace deletes whole words at a time
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 64 | ||||
-rw-r--r-- | source/blender/src/drawtext.c | 16 |
3 files changed, 82 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index ea1afc3754a..45b4034549f 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -59,6 +59,8 @@ void txt_move_up (struct Text *text, short sel); void txt_move_down (struct Text *text, short sel); void txt_move_left (struct Text *text, short sel); void txt_move_right (struct Text *text, short sel); +void txt_jump_left (struct Text *text, short sel); +void txt_jump_right (struct Text *text, short sel); void txt_move_bof (struct Text *text, short sel); void txt_move_eof (struct Text *text, short sel); void txt_move_bol (struct Text *text, short sel); @@ -66,6 +68,7 @@ void txt_move_eol (struct Text *text, short sel); void txt_move_toline (struct Text *text, unsigned int line, short sel); void txt_pop_sel (struct Text *text); void txt_delete_char (struct Text *text); +void txt_delete_word (struct Text *text); void txt_copy_sel (struct Text *text); void txt_sel_all (struct Text *text); void txt_sel_line (struct Text *text); @@ -80,6 +83,7 @@ void txt_do_undo (struct Text *text); void txt_do_redo (struct Text *text); void txt_split_curline (struct Text *text); void txt_backspace_char (struct Text *text); +void txt_backspace_word (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); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 337dba11d59..0556472993f 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -117,6 +117,7 @@ static void txt_pop_last(Text *text); static void txt_undo_add_op(Text *text, int op); static void txt_undo_add_block(Text *text, int op, char *buf); static void txt_delete_line(Text *text, TextLine *line); +static int txt_word_boundary(char ch); /***/ @@ -553,6 +554,17 @@ static void txt_make_dirty (Text *text) if (text->compiled) BPY_free_compiled_text(text); } +static int txt_word_boundary (char ch) +{ + if (ch < '0') return TRUE; + if (ch <= '9') return FALSE; + if (ch < 'A') return TRUE; + if (ch <= 'Z') return FALSE; + if (ch < 'a') return TRUE; + if (ch <= 'z') return FALSE; + return TRUE; +} + /****************************/ /* Cursor utility functions */ /****************************/ @@ -689,6 +701,32 @@ void txt_move_right(Text *text, short sel) if(!sel) txt_pop_sel(text); } +void txt_jump_left(Text *text, short sel) +{ + TextLine *l; + int c; + if (!text) return; + if (!text->curl) return; + do { + txt_move_left(text, sel); + l= sel ? text->sell : text->curl; + c= sel ? text->selc : text->curc; + } while (c>0 && c<l->len && !txt_word_boundary(l->line[c-1])); +} + +void txt_jump_right(Text *text, short sel) +{ + TextLine *l; + int c; + if (!text) return; + if (!text->curl) return; + do { + txt_move_right(text, sel); + l= sel ? text->sell : text->curl; + c= sel ? text->selc : text->curc; + } while (c>0 && c<l->len && !txt_word_boundary(l->line[c-1])); +} + void txt_move_bol (Text *text, short sel) { TextLine **linep; @@ -2063,6 +2101,20 @@ void txt_delete_char (Text *text) if(!undoing) txt_undo_add_charop(text, UNDO_DEL, c); } +void txt_delete_word (Text *text) +{ + int i; + char ch; + if (!text) return; + if (!text->curl) return; + i= text->curc; + do { + ch= text->curl->line[i]; + txt_delete_char(text); + i= text->curc; + } while (i<text->curl->len && !txt_word_boundary(ch)); +} + void txt_backspace_char (Text *text) { char c='\n'; @@ -2103,6 +2155,18 @@ void txt_backspace_char (Text *text) if(!undoing) txt_undo_add_charop(text, UNDO_BS, c); } +void txt_backspace_word (Text *text) +{ + int i; + if (!text) return; + if (!text->curl) return; + i= text->curc; + do { + txt_backspace_char(text); + i= text->curc; + } while (i>0 && !txt_word_boundary(text->curl->line[i-1])); +} + int txt_add_char (Text *text, char add) { int len; diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c index 31bdea0e07e..cdb6e90a3ed 100644 --- a/source/blender/src/drawtext.c +++ b/source/blender/src/drawtext.c @@ -1892,14 +1892,22 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) pop_space_text(st); break; case BACKSPACEKEY: - txt_backspace_char(text); + if (G.qual & (LR_ALTKEY | LR_CTRLKEY)) { + txt_backspace_word(text); + } else { + txt_backspace_char(text); + } set_tabs(text); if (st->showsyntax) get_format_string(st); do_draw= 1; pop_space_text(st); break; case DELKEY: - txt_delete_char(text); + if (G.qual & (LR_ALTKEY | LR_CTRLKEY)) { + txt_delete_word(text); + } else { + txt_delete_char(text); + } if (st->showsyntax) get_format_string(st); do_draw= 1; pop_space_text(st); @@ -1918,6 +1926,8 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) case LEFTARROWKEY: if (G.qual & LR_COMMANDKEY) txt_move_bol(text, G.qual & LR_SHIFTKEY); + else if (G.qual & LR_ALTKEY) + txt_jump_left(text, G.qual & LR_SHIFTKEY); else txt_move_left(text, G.qual & LR_SHIFTKEY); set_tabs(text); @@ -1927,6 +1937,8 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) case RIGHTARROWKEY: if (G.qual & LR_COMMANDKEY) txt_move_eol(text, G.qual & LR_SHIFTKEY); + else if (G.qual & LR_ALTKEY) + txt_jump_right(text, G.qual & LR_SHIFTKEY); else txt_move_right(text, G.qual & LR_SHIFTKEY); set_tabs(text); |