diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-06-17 23:26:26 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-06-17 23:26:26 +0400 |
commit | 05ce388f358b1cfa7bc7c63e29bd772efbf25d39 (patch) | |
tree | a176fe91e6409a60cbd1c93fcb489136f5c56bb0 /source/blender/blenkernel | |
parent | 48bf0ef2edbde0b098cf1f3717087821e0e743e3 (diff) |
Added functions to the BPy Text object for positioning the cursor and inserting text. It seems Text.write() actually inserts *then* moves to the end of the buffer, so it doesn't really append as it says in the docs. However, with these new functions both appending and inserting can be achieved.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 11 |
2 files changed, 10 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 45b4034549f..10223589859 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -66,6 +66,7 @@ void txt_move_eof (struct Text *text, short sel); void txt_move_bol (struct Text *text, short sel); void txt_move_eol (struct Text *text, short sel); void txt_move_toline (struct Text *text, unsigned int line, short sel); +void txt_move_to (struct Text *text, unsigned int line, unsigned int ch, short sel); void txt_pop_sel (struct Text *text); void txt_delete_char (struct Text *text); void txt_delete_word (struct Text *text); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 1c7b505752f..fbb94289166 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -829,6 +829,11 @@ void txt_move_eof (Text *text, short sel) void txt_move_toline (Text *text, unsigned int line, short sel) { + txt_move_to(text, line, 0, sel); +} + +void txt_move_to (Text *text, unsigned int line, unsigned int ch, short sel) +{ TextLine **linep, *oldl; int *charp, oldc; unsigned int i; @@ -845,10 +850,12 @@ void txt_move_toline (Text *text, unsigned int line, short sel) if ((*linep)->next) *linep= (*linep)->next; else break; } - *charp= 0; + if (ch>(*linep)->len) + ch= (*linep)->len; + *charp= ch; if(!sel) txt_pop_sel(text); - if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); + if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp); } /****************************/ |