Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_text/text_autocomplete.c
| Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | static void get_suggest_prefix(Text *text, int offset) | ||||
| } | } | ||||
| line = text->curl->line; | line = text->curl->line; | ||||
| i = text_find_identifier_start(line, text->curc + offset); | i = text_find_identifier_start(line, text->curc + offset); | ||||
| len = text->curc - i + offset; | len = text->curc - i + offset; | ||||
| texttool_suggest_prefix(line + i, len); | texttool_suggest_prefix(line + i, len); | ||||
| } | } | ||||
| static void confirm_suggestion(Text *text, TextUndoBuf *utxt) | static void confirm_suggestion(Text *text) | ||||
| { | { | ||||
| SuggItem *sel; | SuggItem *sel; | ||||
| int i, over = 0; | int i, over = 0; | ||||
| const char *line; | const char *line; | ||||
| if (!text) { | if (!text) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (!texttool_text_is_active(text)) { | if (!texttool_text_is_active(text)) { | ||||
| return; | return; | ||||
| } | } | ||||
| sel = texttool_suggest_selected(); | sel = texttool_suggest_selected(); | ||||
| if (!sel) { | if (!sel) { | ||||
| return; | return; | ||||
| } | } | ||||
| line = text->curl->line; | line = text->curl->line; | ||||
| i = text_find_identifier_start(line, text->curc /* - skipleft */); | i = text_find_identifier_start(line, text->curc /* - skipleft */); | ||||
| over = text->curc - i; | over = text->curc - i; | ||||
| // for (i = 0; i < skipleft; i++) | // for (i = 0; i < skipleft; i++) | ||||
| // txt_move_left(text, 0); | // txt_move_left(text, 0); | ||||
| BLI_assert(memcmp(sel->name, &line[i], over) == 0); | BLI_assert(memcmp(sel->name, &line[i], over) == 0); | ||||
| txt_insert_buf(text, utxt, sel->name + over); | txt_insert_buf(text, sel->name + over); | ||||
| // for (i = 0; i < skipleft; i++) | // for (i = 0; i < skipleft; i++) | ||||
| // txt_move_right(text, 0); | // txt_move_right(text, 0); | ||||
| texttool_text_clear(); | texttool_text_clear(); | ||||
| } | } | ||||
| /* -- */ | /* -- */ | ||||
| static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| SpaceText *st = CTX_wm_space_text(C); | SpaceText *st = CTX_wm_space_text(C); | ||||
| Text *text = CTX_data_edit_text(C); | Text *text = CTX_data_edit_text(C); | ||||
| st->doplugins = true; | st->doplugins = true; | ||||
| op->customdata = text_autocomplete_build(text); | op->customdata = text_autocomplete_build(text); | ||||
| if (texttool_suggest_first()) { | if (texttool_suggest_first()) { | ||||
| ED_area_tag_redraw(CTX_wm_area(C)); | ED_area_tag_redraw(CTX_wm_area(C)); | ||||
| if (texttool_suggest_first() == texttool_suggest_last()) { | if (texttool_suggest_first() == texttool_suggest_last()) { | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| confirm_suggestion(st->text, utxt); | confirm_suggestion(st->text); | ||||
| text_update_line_edited(st->text->curl); | text_update_line_edited(st->text->curl); | ||||
| text_autocomplete_free(C, op); | text_autocomplete_free(C, op); | ||||
| ED_undo_push(C, op->type->name); | ED_undo_push(C, op->type->name); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | case LEFTMOUSE: | ||||
| retval = OPERATOR_FINISHED; | retval = OPERATOR_FINISHED; | ||||
| } | } | ||||
| draw = 1; | draw = 1; | ||||
| } | } | ||||
| break; | break; | ||||
| case MIDDLEMOUSE: | case MIDDLEMOUSE: | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| if (text_do_suggest_select(st, ar)) { | if (text_do_suggest_select(st, ar)) { | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| confirm_suggestion(st->text, utxt); | confirm_suggestion(st->text); | ||||
| text_update_line_edited(st->text->curl); | text_update_line_edited(st->text->curl); | ||||
| ED_undo_push(C, op->type->name); | ED_undo_push(C, op->type->name); | ||||
| swallow = 1; | swallow = 1; | ||||
| } | } | ||||
| else { | else { | ||||
| if (tools & TOOL_SUGG_LIST) { | if (tools & TOOL_SUGG_LIST) { | ||||
| texttool_suggest_clear(); | texttool_suggest_clear(); | ||||
| } | } | ||||
| Show All 21 Lines | case ESCKEY: | ||||
| } | } | ||||
| retval = OPERATOR_CANCELLED; | retval = OPERATOR_CANCELLED; | ||||
| } | } | ||||
| break; | break; | ||||
| case RETKEY: | case RETKEY: | ||||
| case PADENTER: | case PADENTER: | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| if (tools & TOOL_SUGG_LIST) { | if (tools & TOOL_SUGG_LIST) { | ||||
| TextUndoBuf *utxt = ED_text_undo_push_init(C); | ED_text_undo_push_init(C); | ||||
| confirm_suggestion(st->text, utxt); | confirm_suggestion(st->text); | ||||
| text_update_line_edited(st->text->curl); | text_update_line_edited(st->text->curl); | ||||
| ED_undo_push(C, op->type->name); | ED_undo_push(C, op->type->name); | ||||
| swallow = 1; | swallow = 1; | ||||
| draw = 1; | draw = 1; | ||||
| } | } | ||||
| if (tools & TOOL_DOCUMENT) { | if (tools & TOOL_DOCUMENT) { | ||||
| texttool_docs_clear(); | texttool_docs_clear(); | ||||
| doc_scroll = 0; | doc_scroll = 0; | ||||
| ▲ Show 20 Lines • Show All 210 Lines • Show Last 20 Lines | |||||