diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-10-02 10:07:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-10-02 10:07:35 +0300 |
commit | 09082e15d00457bc22826c7d419a6dfb6c9905bd (patch) | |
tree | 5cc49033ab474373401f738384a963739be4600d /source/blender | |
parent | 4053fa9fcbe37900e8035079d76cbea6ca1f2461 (diff) |
Fix text editor auto-complete mouse interaction
- Remove MMB for activating an auto-complete item (use LMB instead).
- Update on cursor motion.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_text/text_autocomplete.c | 50 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 2 |
2 files changed, 22 insertions, 30 deletions
diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c index 74cf3c866d3..e754c143718 100644 --- a/source/blender/editors/space_text/text_autocomplete.c +++ b/source/blender/editors/space_text/text_autocomplete.c @@ -49,13 +49,13 @@ /** \name Public API * \{ */ -int text_do_suggest_select(SpaceText *st, ARegion *region) +bool text_do_suggest_select(SpaceText *st, ARegion *region, const int mval[2]) { + const int lheight = TXT_LINE_HEIGHT(st); SuggItem *item, *first, *last /* , *sel */ /* UNUSED */; TextLine *tmp; int l, x, y, w, h, i; int tgti, *top; - const int mval[2] = {0, 0}; if (!st || !st->text) { return 0; @@ -84,12 +84,10 @@ int text_do_suggest_select(SpaceText *st, ARegion *region) text_update_character_width(st); x = TXT_BODY_LEFT(st) + (st->runtime.cwidth_px * (st->text->curc - st->left)); - y = region->winy - st->runtime.lheight_px * l - 2; + y = region->winy - lheight * l - 2; w = SUGG_LIST_WIDTH * st->runtime.cwidth_px + U.widget_unit; - h = SUGG_LIST_SIZE * st->runtime.lheight_px + 0.4f * U.widget_unit; - - // XXX getmouseco_areawin(mval); + h = SUGG_LIST_SIZE * lheight + 0.4f * U.widget_unit; if (mval[0] < x || x + w < mval[0] || mval[1] < y - h || y < mval[1]) { return 0; @@ -101,7 +99,7 @@ int text_do_suggest_select(SpaceText *st, ARegion *region) } /* Work out the target item index in the visible list */ - tgti = (y - mval[1] - 4) / st->runtime.lheight_px; + tgti = (y - mval[1] - 4) / lheight; if (tgti < 0 || tgti > SUGG_LIST_SIZE) { return 1; } @@ -296,7 +294,6 @@ static void confirm_suggestion(Text *text) /* -------------------------------------------------------------------- */ /** \name Auto Complete Operator - * * \{ */ static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) @@ -336,11 +333,8 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW); int draw = 0, tools = 0, swallow = 0, scroll = 1; - Text *text = CTX_data_edit_text(C); int retval = OPERATOR_RUNNING_MODAL; - (void)text; - if (st->doplugins && texttool_text_is_active(st->text)) { if (texttool_suggest_first()) { tools |= TOOL_SUGG_LIST; @@ -351,33 +345,31 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e } switch (event->type) { + case MOUSEMOVE: { + if (text_do_suggest_select(st, region, event->mval)) { + draw = 1; + } + swallow = 1; + break; + } case LEFTMOUSE: if (event->val == KM_PRESS) { - if (text_do_suggest_select(st, region)) { - swallow = 1; - } - else { + if (text_do_suggest_select(st, region, event->mval)) { if (tools & TOOL_SUGG_LIST) { - texttool_suggest_clear(); + ED_text_undo_push_init(C); + confirm_suggestion(st->text); + text_update_line_edited(st->text->curl); + ED_undo_push(C, op->type->name); + swallow = 1; + draw = 1; } if (tools & TOOL_DOCUMENT) { texttool_docs_clear(); doc_scroll = 0; + draw = 1; } retval = OPERATOR_FINISHED; } - draw = 1; - } - break; - case MIDDLEMOUSE: - if (event->val == KM_PRESS) { - if (text_do_suggest_select(st, region)) { - ED_text_undo_push_init(C); - confirm_suggestion(st->text); - text_update_line_edited(st->text->curl); - ED_undo_push(C, op->type->name); - swallow = 1; - } else { if (tools & TOOL_SUGG_LIST) { texttool_suggest_clear(); @@ -386,7 +378,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e texttool_docs_clear(); doc_scroll = 0; } - retval = OPERATOR_FINISHED; + retval = OPERATOR_CANCELLED; } draw = 1; } diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index e3c0e436ac4..a33af56e11a 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -91,7 +91,7 @@ int text_get_char_pos(const struct SpaceText *st, const char *line, int cur); void text_drawcache_tag_update(struct SpaceText *st, int full); void text_free_caches(struct SpaceText *st); -int text_do_suggest_select(struct SpaceText *st, struct ARegion *region); +bool text_do_suggest_select(struct SpaceText *st, struct ARegion *region, const int mval[2]); void text_pop_suggest_list(void); int text_get_visible_lines(const struct SpaceText *st, struct ARegion *region, const char *str); |