From 9e75d276e31caa581ad14f4561aed03c57e2b2c9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 1 May 2013 00:15:22 +0000 Subject: holding ctrl when using arrow keys in the text editor didn't navigate newlines. --- source/blender/blenkernel/BKE_text.h | 2 ++ source/blender/blenkernel/intern/text.c | 10 ++++++++++ source/blender/editors/space_text/text_ops.c | 24 ++++++++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 5e81fb85d76..8fd712bde72 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -101,6 +101,8 @@ void txt_uncomment (struct Text *text); void txt_move_lines (struct Text *text, const int direction); void txt_duplicate_line (struct Text *text); int txt_setcurr_tab_spaces(struct Text *text, int space); +bool txt_cursor_is_line_start(struct Text *text); +bool txt_cursor_is_line_end(struct Text *text); /* utility functions, could be moved somewhere more generic but are python/text related */ int text_check_bracket(const char ch); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 9b019776508..c5a509162ff 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -780,6 +780,16 @@ static void txt_curs_sel(Text *text, TextLine ***linep, int **charp) *linep = &text->sell; *charp = &text->selc; } +bool txt_cursor_is_line_start(Text *text) +{ + return (text->selc == 0); +} + +bool txt_cursor_is_line_end(Text *text) +{ + return (text->selc == text->sell->len); +} + /*****************************/ /* Cursor movement functions */ /*****************************/ diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index fec6847bb79..30f3c1623c9 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1855,10 +1855,16 @@ static int text_move_cursor(bContext *C, int type, int select) break; case PREV_WORD: + if (txt_cursor_is_line_start(text)) { + txt_move_left(text, select); + } txt_jump_left(text, select, true); break; case NEXT_WORD: + if (txt_cursor_is_line_end(text)) { + txt_move_right(text, select); + } txt_jump_right(text, select, true); break; @@ -2005,14 +2011,24 @@ static int text_delete_exec(bContext *C, wmOperator *op) text_drawcache_tag_update(CTX_wm_space_text(C), 0); - if (type == DEL_PREV_WORD) + if (type == DEL_PREV_WORD) { + if (txt_cursor_is_line_start(text)) { + txt_backspace_char(text); + } txt_backspace_word(text); - else if (type == DEL_PREV_CHAR) + } + else if (type == DEL_PREV_CHAR) { txt_backspace_char(text); - else if (type == DEL_NEXT_WORD) + } + else if (type == DEL_NEXT_WORD) { + if (txt_cursor_is_line_end(text)) { + txt_delete_char(text); + } txt_delete_word(text); - else if (type == DEL_NEXT_CHAR) + } + else if (type == DEL_NEXT_CHAR) { txt_delete_char(text); + } text_update_line_edited(text->curl); -- cgit v1.2.3