From fb4f6e4d2b55a65ac9aad4fb01050ddc394ad539 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 13 Jul 2023 17:05:12 -0700 Subject: [PATCH 1/7] Updating to remove merge conflicts. --- .../keyconfig/keymap_data/blender_default.py | 14 ++ .../keymap_data/industry_compatible_data.py | 14 ++ scripts/startup/bl_ui/space_console.py | 2 + .../editors/space_console/console_draw.cc | 5 +- .../editors/space_console/console_intern.hh | 1 + .../editors/space_console/console_ops.cc | 161 +++++++++++++++++- .../editors/space_console/space_console.cc | 1 + 7 files changed, 192 insertions(+), 6 deletions(-) diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index e2c50eb7ab4..6b4801bc84b 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -3080,12 +3080,20 @@ def km_console(_params): items.extend([ ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("type", 'PREVIOUS_WORD')]}), + ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True, "shift": True, "repeat": True}, + {"properties": [("type", 'PREVIOUS_WORD'),("select", True)]}), ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("type", 'NEXT_WORD')]}), + ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True, "shift": True, "repeat": True}, + {"properties": [("type", 'NEXT_WORD'),("select", True)]}), ("console.move", {"type": 'HOME', "value": 'PRESS'}, {"properties": [("type", 'LINE_BEGIN')]}), + ("console.move", {"type": 'HOME', "value": 'PRESS', "shift": True}, + {"properties": [("type", 'LINE_BEGIN'),("select", True)]}), ("console.move", {"type": 'END', "value": 'PRESS'}, {"properties": [("type", 'LINE_END')]}), + ("console.move", {"type": 'END', "value": 'PRESS', "shift": True}, + {"properties": [("type", 'LINE_END'),("select", True)]}), ("wm.context_cycle_int", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "ctrl": True}, {"properties": [("data_path", 'space_data.font_size'), ("reverse", False)]}), ("wm.context_cycle_int", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "ctrl": True}, @@ -3096,8 +3104,12 @@ def km_console(_params): {"properties": [("data_path", 'space_data.font_size'), ("reverse", True)]}), ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "repeat": True}, {"properties": [("type", 'PREVIOUS_CHARACTER')]}), + ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "repeat": True, "shift": True}, + {"properties": [("type", 'PREVIOUS_CHARACTER'),("select", True)]}), ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "repeat": True}, {"properties": [("type", 'NEXT_CHARACTER')]}), + ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "repeat": True, "shift": True}, + {"properties": [("type", 'NEXT_CHARACTER'),("select", True)]}), ("console.history_cycle", {"type": 'UP_ARROW', "value": 'PRESS', "repeat": True}, {"properties": [("reverse", True)]}), ("console.history_cycle", {"type": 'DOWN_ARROW', "value": 'PRESS', "repeat": True}, @@ -3121,7 +3133,9 @@ def km_console(_params): ("console.copy_as_script", {"type": 'C', "value": 'PRESS', "shift": True, "ctrl": True}, None), ("console.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None), ("console.paste", {"type": 'V', "value": 'PRESS', "ctrl": True, "repeat": True}, None), + ("console.copy", {"type": 'DEL', "value": 'PRESS', "shift": True}, {"properties": [("delete", True)]}), ("console.select_set", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), + ("console.select_all", {"type": 'A', "value": 'PRESS', "ctrl": True}, None), ("console.select_word", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None), ("console.insert", {"type": 'TAB', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("text", '\t')]}), diff --git a/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py index 1d43887a5d7..db878f06750 100644 --- a/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py +++ b/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py @@ -1887,12 +1887,20 @@ def km_console(params): items.extend([ ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("type", 'PREVIOUS_WORD')]}), + ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True, "shift": True, "repeat": True}, + {"properties": [("type", 'PREVIOUS_WORD'),("select", True)]}), ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("type", 'NEXT_WORD')]}), + ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True, "shift": True, "repeat": True}, + {"properties": [("type", 'NEXT_WORD'),("select", True)]}), ("console.move", {"type": 'HOME', "value": 'PRESS'}, {"properties": [("type", 'LINE_BEGIN')]}), + ("console.move", {"type": 'HOME', "value": 'PRESS', "shift": True}, + {"properties": [("type", 'LINE_BEGIN'),("select", True)]}), ("console.move", {"type": 'END', "value": 'PRESS'}, {"properties": [("type", 'LINE_END')]}), + ("console.move", {"type": 'END', "value": 'PRESS', "shift": True}, + {"properties": [("type", 'LINE_END'),("select", True)]}), ("wm.context_cycle_int", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "ctrl": True}, {"properties": [("data_path", 'space_data.font_size'), ("reverse", False)]}), ("wm.context_cycle_int", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "ctrl": True}, @@ -1903,8 +1911,12 @@ def km_console(params): {"properties": [("data_path", 'space_data.font_size'), ("reverse", True)]}), ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "repeat": True}, {"properties": [("type", 'PREVIOUS_CHARACTER')]}), + ("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "repeat": True, "shift": True}, + {"properties": [("type", 'PREVIOUS_CHARACTER'),("select", True)]}), ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "repeat": True}, {"properties": [("type", 'NEXT_CHARACTER')]}), + ("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "repeat": True, "shift": True}, + {"properties": [("type", 'NEXT_CHARACTER'),("select", True)]}), ("console.history_cycle", {"type": 'UP_ARROW', "value": 'PRESS', "repeat": True}, {"properties": [("reverse", True)]}), ("console.history_cycle", {"type": 'DOWN_ARROW', "value": 'PRESS', "repeat": True}, @@ -1928,7 +1940,9 @@ def km_console(params): ("console.copy_as_script", {"type": 'C', "value": 'PRESS', "shift": True, "ctrl": True}, None), ("console.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None), ("console.paste", {"type": 'V', "value": 'PRESS', "ctrl": True, "repeat": True}, None), + ("console.copy", {"type": 'DEL', "value": 'PRESS', "shift": True}, {"properties": [("delete", True)]}), ("console.select_set", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), + ("console.select_all", {"type": 'A', "value": 'PRESS', "ctrl": True}, None), ("console.select_word", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None), ("console.insert", {"type": 'TAB', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("text", '\t')]}), diff --git a/scripts/startup/bl_ui/space_console.py b/scripts/startup/bl_ui/space_console.py index 9644d7d93dc..411a7df704f 100644 --- a/scripts/startup/bl_ui/space_console.py +++ b/scripts/startup/bl_ui/space_console.py @@ -92,6 +92,7 @@ class CONSOLE_MT_console(Menu): layout.separator() layout.operator("console.copy_as_script", text="Copy as Script") + layout.operator("console.copy", text="Cut").delete = True layout.operator("console.copy", text="Copy") layout.operator("console.paste", text="Paste") @@ -124,6 +125,7 @@ class CONSOLE_MT_context_menu(Menu): layout.separator() layout.operator("console.copy_as_script", text="Copy as Script") + layout.operator("console.copy", text="Cut").delete = True layout.operator("console.copy", text="Copy") layout.operator("console.paste", text="Paste") diff --git a/source/blender/editors/space_console/console_draw.cc b/source/blender/editors/space_console/console_draw.cc index 0b28051ff8f..905e7020138 100644 --- a/source/blender/editors/space_console/console_draw.cc +++ b/source/blender/editors/space_console/console_draw.cc @@ -217,8 +217,11 @@ static int console_textview_main__internal(SpaceConsole *sc, console_textview_draw_rect_calc(region, &tvc.draw_rect, &tvc.draw_rect_outer); + /* Nudge right by half a column or so to break selection mid-character. */ + const int m_pos[2] = {mval[0] + (int)(sc->lheight * UI_SCALE_FAC * 0.25f), mval[1]}; + console_scrollback_prompt_begin(sc, &cl_dummy); - ret = textview_draw(&tvc, do_draw, mval, r_mval_pick_item, r_mval_pick_offset); + ret = textview_draw(&tvc, do_draw, m_pos, r_mval_pick_item, r_mval_pick_offset); console_scrollback_prompt_end(sc, &cl_dummy); return ret; diff --git a/source/blender/editors/space_console/console_intern.hh b/source/blender/editors/space_console/console_intern.hh index d7b0e5bf4d2..8e1a3219506 100644 --- a/source/blender/editors/space_console/console_intern.hh +++ b/source/blender/editors/space_console/console_intern.hh @@ -52,6 +52,7 @@ void CONSOLE_OT_history_cycle(struct wmOperatorType *ot); void CONSOLE_OT_copy(struct wmOperatorType *ot); void CONSOLE_OT_paste(struct wmOperatorType *ot); void CONSOLE_OT_select_set(struct wmOperatorType *ot); +void CONSOLE_OT_select_all(struct wmOperatorType *ot); void CONSOLE_OT_select_word(struct wmOperatorType *ot); enum { LINE_BEGIN, LINE_END, PREV_CHAR, NEXT_CHAR, PREV_WORD, NEXT_WORD }; diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index 3d51b937308..95c54d65a25 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -101,6 +101,37 @@ static void console_select_update_primary_clipboard(SpaceConsole *sc) MEM_freeN(buf); } +/* Delete selected characters in the edit line. */ +static int console_delete_editable_selection(SpaceConsole *sc) +{ + if (sc->sel_start == sc->sel_end) { + return 0; + } + + ConsoleLine *cl = static_cast(sc->history.last); + if (!cl || sc->sel_start > cl->len) { + sc->sel_start = sc->sel_end; + return 0; + } + + int del_start = sc->sel_start; + int del_end = sc->sel_end; + + if (del_end > cl->len) { + /* Adjust range to only editable portion. */ + del_end = cl->len; + } + + const int len = del_end - del_start; + memmove(cl->line + cl->len - del_end, cl->line + cl->len - del_start, del_start); + cl->len -= len; + cl->line[cl->len] = 0; + cl->cursor = cl->len - del_start; + + sc->sel_start = sc->sel_end = cl->cursor; + return len; +} + /** \} */ /* so when we type - the view scrolls to the bottom */ @@ -361,11 +392,25 @@ static const EnumPropertyItem console_move_type_items[] = { static int console_move_exec(bContext *C, wmOperator *op) { + SpaceConsole *sc = CTX_wm_space_console(C); ConsoleLine *ci = console_history_verify(C); int type = RNA_enum_get(op->ptr, "type"); + bool select = RNA_boolean_get(op->ptr, "select"); + bool done = false; - int pos; + int old_pos = ci->cursor; + int pos = 0; + + if (!select && sc->sel_start != sc->sel_end) { + /* Clear selection if we are not extending it. */ + sc->sel_start = sc->sel_end; + if (sc->sel_end <= ci->len && sc->sel_start <= ci->len) { + /* If selection is in an editable section, do nothing else. */ + ED_area_tag_redraw(CTX_wm_area(C)); + return OPERATOR_FINISHED; + } + } switch (type) { case LINE_BEGIN: @@ -403,6 +448,19 @@ static int console_move_exec(bContext *C, wmOperator *op) break; } + if (select) { + if (sc->sel_start == sc->sel_end || sc->sel_start > ci->len || sc->sel_end > ci->len) { + sc->sel_start = ci->len - old_pos; + sc->sel_end = sc->sel_start; + } + if (pos > old_pos) { + sc->sel_start = ci->len - pos; + } + else { + sc->sel_end = ci->len - pos; + } + } + if (done) { ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); @@ -428,6 +486,9 @@ void CONSOLE_OT_move(wmOperatorType *ot) /* properties */ RNA_def_enum( ot->srna, "type", console_move_type_items, LINE_BEGIN, "Type", "Where to move cursor to"); + PropertyRNA *prop = RNA_def_boolean( + ot->srna, "select", false, "Select", "Whether to select while moving"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } #define TAB_LENGTH 4 @@ -463,6 +524,7 @@ static int console_insert_exec(bContext *C, wmOperator *op) } if (len != 0) { + console_delete_editable_selection(sc); console_line_insert(ci, str, len); } @@ -695,6 +757,14 @@ static int console_delete_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + /* If there is a selection just delete it and nothing else. */ + if (sc->sel_start != sc->sel_end && console_delete_editable_selection(sc) > 0) { + console_textview_update_rect(sc, region); + ED_area_tag_redraw(CTX_wm_area(C)); + console_scroll_bottom(region); + return OPERATOR_FINISHED; + } + switch (type) { case DEL_NEXT_CHAR: case DEL_NEXT_WORD: @@ -1046,7 +1116,7 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot) "Console output type"); } -static int console_copy_exec(bContext *C, wmOperator * /*op*/) +static int console_copy_exec(bContext *C, wmOperator *op) { SpaceConsole *sc = CTX_wm_space_console(C); char *buf = console_select_to_buffer(sc); @@ -1055,10 +1125,22 @@ static int console_copy_exec(bContext *C, wmOperator * /*op*/) } WM_clipboard_text_set(buf, false); + + if (RNA_boolean_get(op->ptr, "delete")) { + console_delete_editable_selection(sc); + ED_area_tag_redraw(CTX_wm_area(C)); + } + MEM_freeN(buf); return OPERATOR_FINISHED; } +static bool console_copy_poll(bContext *C) +{ + SpaceConsole *sc = CTX_wm_space_console(C); + return ED_operator_console_active(C) && sc && (sc->sel_start != sc->sel_end); +} + void CONSOLE_OT_copy(wmOperatorType *ot) { /* identifiers */ @@ -1067,10 +1149,16 @@ void CONSOLE_OT_copy(wmOperatorType *ot) ot->idname = "CONSOLE_OT_copy"; /* api callbacks */ - ot->poll = ED_operator_console_active; + ot->poll = console_copy_poll; ot->exec = console_copy_exec; /* properties */ + PropertyRNA *prop = RNA_def_boolean(ot->srna, + "delete", + false, + "Delete Selection", + "Whether to delete the selection after copying"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } static int console_paste_exec(bContext *C, wmOperator *op) @@ -1098,6 +1186,7 @@ static int console_paste_exec(bContext *C, wmOperator *op) WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, nullptr, nullptr); ci = console_history_verify(C); } + console_delete_editable_selection(sc); console_line_insert(ci, buf, buf_len); console_select_offset(sc, buf_len); } while (*buf_step ? ((void)buf_step++, true) : false); @@ -1138,7 +1227,6 @@ struct SetConsoleCursor { int sel_init; }; -/* TODO: cursor placement without selection. */ static void console_cursor_set_to_pos( SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const int mval[2], int /*sel*/) { @@ -1162,6 +1250,19 @@ static void console_cursor_set_to_pos( else { sc->sel_start = sc->sel_end = pos; } + + /* Move text cursor to the last selection point. */ + ConsoleLine *cl = static_cast(sc->history.last); + + if (cl != NULL) { + if (pos <= cl->len) { + console_line_cursor_set(cl, cl->len - pos); + } + else if (sc->sel_end > cl->len && sc->sel_start < cl->len) { + /* if mixed selection, move cursor to the start. */ + console_line_cursor_set(cl, cl->len - sc->sel_start); + } + } } static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event) @@ -1199,9 +1300,17 @@ static void console_cursor_set_exit(bContext *C, wmOperator *op) static int console_modal_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { SpaceConsole *sc = CTX_wm_space_console(C); - // ARegion *region = CTX_wm_region(C); SetConsoleCursor *scu; + ConsoleLine *cl = static_cast(sc->history.last); + if (cl != NULL) { + const int pos = console_char_pick(sc, CTX_wm_region(C), event->mval); + if (pos >= 0 && pos <= cl->len) { + /* Set text cursor immediately. */ + console_line_cursor_set(cl, cl->len - pos); + } + } + op->customdata = MEM_callocN(sizeof(SetConsoleCursor), "SetConsoleCursor"); scu = static_cast(op->customdata); @@ -1255,6 +1364,43 @@ void CONSOLE_OT_select_set(wmOperatorType *ot) ot->poll = ED_operator_console_active; } +static int console_modal_select_all_invoke(bContext *C, + wmOperator * /* op */, + const wmEvent * /* event */) +{ + SpaceConsole *sc = CTX_wm_space_console(C); + + int offset = strlen(sc->prompt); + + for (ConsoleLine *cl = static_cast(sc->scrollback.first); cl; cl = cl->next) { + offset += cl->len + 1; + } + + ConsoleLine *cl = static_cast(sc->history.last); + if (cl) { + offset += cl->len + 1; + } + + sc->sel_start = 0; + sc->sel_end = offset; + + ED_area_tag_redraw(CTX_wm_area(C)); + + return OPERATOR_FINISHED; +} + +void CONSOLE_OT_select_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Select All"; + ot->idname = "CONSOLE_OT_select_all"; + ot->description = "Select all the text"; + + /* api callbacks */ + ot->invoke = console_modal_select_all_invoke; + ot->poll = ED_operator_console_active; +} + static int console_selectword_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event) { SpaceConsole *sc = CTX_wm_space_console(C); @@ -1287,6 +1433,11 @@ static int console_selectword_invoke(bContext *C, wmOperator * /*op*/, const wmE console_scrollback_prompt_end(sc, &cl_dummy); + ConsoleLine *ci = static_cast(sc->history.last); + if (ci && sc->sel_start <= ci->len) { + console_line_cursor_set(ci, ci->len - sc->sel_start); + } + if (ret & OPERATOR_FINISHED) { console_select_update_primary_clipboard(sc); } diff --git a/source/blender/editors/space_console/space_console.cc b/source/blender/editors/space_console/space_console.cc index 9ff3637c225..64e8b4ef5c4 100644 --- a/source/blender/editors/space_console/space_console.cc +++ b/source/blender/editors/space_console/space_console.cc @@ -239,6 +239,7 @@ static void console_operatortypes() WM_operatortype_append(CONSOLE_OT_copy); WM_operatortype_append(CONSOLE_OT_paste); WM_operatortype_append(CONSOLE_OT_select_set); + WM_operatortype_append(CONSOLE_OT_select_all); WM_operatortype_append(CONSOLE_OT_select_word); } -- 2.30.2 From 1587b7375155210a04ee34fa77c07745aac35bda Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 18 Jul 2023 11:32:20 -0700 Subject: [PATCH 2/7] Ctrl-X = Cut --- scripts/presets/keyconfig/keymap_data/blender_default.py | 2 +- .../presets/keyconfig/keymap_data/industry_compatible_data.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index 6b4801bc84b..6c12e56c237 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -3132,8 +3132,8 @@ def km_console(_params): {"properties": [("interactive", True)]}), ("console.copy_as_script", {"type": 'C', "value": 'PRESS', "shift": True, "ctrl": True}, None), ("console.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None), + ("console.copy", {"type": 'X', "value": 'PRESS', "ctrl": True}, {"properties": [("delete", True)]}), ("console.paste", {"type": 'V', "value": 'PRESS', "ctrl": True, "repeat": True}, None), - ("console.copy", {"type": 'DEL', "value": 'PRESS', "shift": True}, {"properties": [("delete", True)]}), ("console.select_set", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), ("console.select_all", {"type": 'A', "value": 'PRESS', "ctrl": True}, None), ("console.select_word", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None), diff --git a/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py index db878f06750..9ff204e124b 100644 --- a/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py +++ b/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py @@ -1939,8 +1939,8 @@ def km_console(params): {"properties": [("interactive", True)]}), ("console.copy_as_script", {"type": 'C', "value": 'PRESS', "shift": True, "ctrl": True}, None), ("console.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None), + ("console.copy", {"type": 'X', "value": 'PRESS', "ctrl": True}, {"properties": [("delete", True)]}), ("console.paste", {"type": 'V', "value": 'PRESS', "ctrl": True, "repeat": True}, None), - ("console.copy", {"type": 'DEL', "value": 'PRESS', "shift": True}, {"properties": [("delete", True)]}), ("console.select_set", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), ("console.select_all", {"type": 'A', "value": 'PRESS', "ctrl": True}, None), ("console.select_word", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None), -- 2.30.2 From 404770ae85f977182f2ce3f091439325f0c1860c Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sun, 23 Jul 2023 18:00:36 -0700 Subject: [PATCH 3/7] Only move text cursor on press or release, not just moving --- .../editors/space_console/console_ops.cc | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index 95c54d65a25..87bb2e10582 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -1228,7 +1228,7 @@ struct SetConsoleCursor { }; static void console_cursor_set_to_pos( - SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const int mval[2], int /*sel*/) + SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const int mval[2], bool move_cursor) { int pos; pos = console_char_pick(sc, region, mval); @@ -1251,21 +1251,23 @@ static void console_cursor_set_to_pos( sc->sel_start = sc->sel_end = pos; } - /* Move text cursor to the last selection point. */ - ConsoleLine *cl = static_cast(sc->history.last); + if (move_cursor) { + /* Move text cursor to the last selection point. */ + ConsoleLine *cl = static_cast(sc->history.last); - if (cl != NULL) { - if (pos <= cl->len) { - console_line_cursor_set(cl, cl->len - pos); - } - else if (sc->sel_end > cl->len && sc->sel_start < cl->len) { - /* if mixed selection, move cursor to the start. */ - console_line_cursor_set(cl, cl->len - sc->sel_start); + if (cl != NULL) { + if (pos <= cl->len) { + console_line_cursor_set(cl, cl->len - pos); + } + else if (sc->sel_end > cl->len && sc->sel_start < cl->len) { + /* if mixed selection, move cursor to the start. */ + console_line_cursor_set(cl, cl->len - sc->sel_start); + } } } } -static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event) +static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event, bool move_cursor) { SpaceConsole *sc = CTX_wm_space_console(C); ARegion *region = CTX_wm_region(C); @@ -1279,12 +1281,8 @@ static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEven sel_prev[0] = sc->sel_start; sel_prev[1] = sc->sel_end; - console_cursor_set_to_pos(sc, region, scu, mval, true); - - /* only redraw if the selection changed */ - if (sel_prev[0] != sc->sel_start || sel_prev[1] != sc->sel_end) { - ED_area_tag_redraw(CTX_wm_area(C)); - } + console_cursor_set_to_pos(sc, region, scu, mval, move_cursor); + ED_area_tag_redraw(CTX_wm_area(C)); } static void console_cursor_set_exit(bContext *C, wmOperator *op) @@ -1321,7 +1319,7 @@ static int console_modal_select_invoke(bContext *C, wmOperator *op, const wmEven WM_event_add_modal_handler(C, op); - console_modal_select_apply(C, op, event); + console_modal_select_apply(C, op, event, true); return OPERATOR_RUNNING_MODAL; } @@ -1332,13 +1330,21 @@ static int console_modal_select(bContext *C, wmOperator *op, const wmEvent *even case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: - if (event->val == KM_RELEASE) { + if (event->val == KM_PRESS) { + /* Change text cursor on press down. */ + console_modal_select_apply(C, op, event, true); + break; + } + else if (event->val == KM_RELEASE) { + /* Change text cursor on release. */ + console_modal_select_apply(C, op, event, true); console_cursor_set_exit(C, op); return OPERATOR_FINISHED; } break; case MOUSEMOVE: - console_modal_select_apply(C, op, event); + /* No change to text cursor if just moving. */ + console_modal_select_apply(C, op, event, false); break; } -- 2.30.2 From c4cb6cfe18d37c9009db3b4eda9919c71a634d0c Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 24 Jul 2023 12:44:14 -0700 Subject: [PATCH 4/7] Do not move cursor while dragging into editable area. Do set on mouse release. --- .../editors/space_console/console_draw.cc | 2 +- .../editors/space_console/console_ops.cc | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/source/blender/editors/space_console/console_draw.cc b/source/blender/editors/space_console/console_draw.cc index 905e7020138..b9a914ed6b0 100644 --- a/source/blender/editors/space_console/console_draw.cc +++ b/source/blender/editors/space_console/console_draw.cc @@ -218,7 +218,7 @@ static int console_textview_main__internal(SpaceConsole *sc, console_textview_draw_rect_calc(region, &tvc.draw_rect, &tvc.draw_rect_outer); /* Nudge right by half a column or so to break selection mid-character. */ - const int m_pos[2] = {mval[0] + (int)(sc->lheight * UI_SCALE_FAC * 0.25f), mval[1]}; + const int m_pos[2] = {mval[0] + (tvc.lheight / 4), mval[1]}; console_scrollback_prompt_begin(sc, &cl_dummy); ret = textview_draw(&tvc, do_draw, m_pos, r_mval_pick_item, r_mval_pick_offset); diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index 87bb2e10582..64c0916525e 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -1227,11 +1227,13 @@ struct SetConsoleCursor { int sel_init; }; -static void console_cursor_set_to_pos( - SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const int mval[2], bool move_cursor) +static void console_cursor_set_to_pos(SpaceConsole *sc, + ARegion *region, + SetConsoleCursor *scu, + const wmEvent *event) { - int pos; - pos = console_char_pick(sc, region, mval); + int pos = console_char_pick(sc, region, event->mval); + bool dragging = event->type == MOUSEMOVE; if (scu->sel_init == INT_MAX) { scu->sel_init = pos; @@ -1251,38 +1253,36 @@ static void console_cursor_set_to_pos( sc->sel_start = sc->sel_end = pos; } - if (move_cursor) { - /* Move text cursor to the last selection point. */ - ConsoleLine *cl = static_cast(sc->history.last); + /* Move text cursor to the last selection point. */ + ConsoleLine *cl = static_cast(sc->history.last); - if (cl != NULL) { - if (pos <= cl->len) { - console_line_cursor_set(cl, cl->len - pos); - } - else if (sc->sel_end > cl->len && sc->sel_start < cl->len) { - /* if mixed selection, move cursor to the start. */ - console_line_cursor_set(cl, cl->len - sc->sel_start); - } + if (cl != NULL) { + if (dragging && sc->sel_end > cl->len && pos <= cl->len) { + /* Do not move cursor while dragging into the editable area. */ + } + else if (pos <= cl->len) { + console_line_cursor_set(cl, cl->len - pos); + } + else if (pos > cl->len && sc->sel_start < cl->len) { + /* Dragging out of editable area, move cursor to start of selection. */ + console_line_cursor_set(cl, cl->len - sc->sel_start); } } } -static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event, bool move_cursor) +static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event) { SpaceConsole *sc = CTX_wm_space_console(C); ARegion *region = CTX_wm_region(C); SetConsoleCursor *scu = static_cast(op->customdata); - int mval[2]; - int sel_prev[2]; + int sel_prev[2] = {sc->sel_start, sc->sel_end}; - mval[0] = event->mval[0]; - mval[1] = event->mval[1]; + console_cursor_set_to_pos(sc, region, scu, event); - sel_prev[0] = sc->sel_start; - sel_prev[1] = sc->sel_end; - - console_cursor_set_to_pos(sc, region, scu, mval, move_cursor); - ED_area_tag_redraw(CTX_wm_area(C)); + /* only redraw if the selection changed */ + if (sel_prev[0] != sc->sel_start || sel_prev[1] != sc->sel_end) { + ED_area_tag_redraw(CTX_wm_area(C)); + } } static void console_cursor_set_exit(bContext *C, wmOperator *op) @@ -1319,32 +1319,34 @@ static int console_modal_select_invoke(bContext *C, wmOperator *op, const wmEven WM_event_add_modal_handler(C, op); - console_modal_select_apply(C, op, event, true); + console_modal_select_apply(C, op, event); return OPERATOR_RUNNING_MODAL; } static int console_modal_select(bContext *C, wmOperator *op, const wmEvent *event) { + /* Move text cursor to the last selection point. */ + SpaceConsole *sc = CTX_wm_space_console(C); + ConsoleLine *cl = static_cast(sc->history.last); + switch (event->type) { case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: if (event->val == KM_PRESS) { - /* Change text cursor on press down. */ - console_modal_select_apply(C, op, event, true); + console_modal_select_apply(C, op, event); break; } else if (event->val == KM_RELEASE) { - /* Change text cursor on release. */ - console_modal_select_apply(C, op, event, true); + console_modal_select_apply(C, op, event); + ED_area_tag_redraw(CTX_wm_area(C)); console_cursor_set_exit(C, op); return OPERATOR_FINISHED; } break; case MOUSEMOVE: - /* No change to text cursor if just moving. */ - console_modal_select_apply(C, op, event, false); + console_modal_select_apply(C, op, event); break; } -- 2.30.2 From 12b0c80243db9fadf9ddd5987a37464a88f776c1 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 24 Jul 2023 18:05:02 -0700 Subject: [PATCH 5/7] Cursor movement while selection, clear selection, do op. --- source/blender/editors/space_console/console_ops.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index 64c0916525e..ba056a334a9 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -405,11 +405,6 @@ static int console_move_exec(bContext *C, wmOperator *op) if (!select && sc->sel_start != sc->sel_end) { /* Clear selection if we are not extending it. */ sc->sel_start = sc->sel_end; - if (sc->sel_end <= ci->len && sc->sel_start <= ci->len) { - /* If selection is in an editable section, do nothing else. */ - ED_area_tag_redraw(CTX_wm_area(C)); - return OPERATOR_FINISHED; - } } switch (type) { -- 2.30.2 From a89b6d93f25424eef8277003c62c56c31789c340 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 11 Aug 2023 16:04:23 -0700 Subject: [PATCH 6/7] Updated to incorporate changes requested by review. --- source/blender/editors/space_console/console_draw.cc | 6 +++++- source/blender/editors/space_console/console_ops.cc | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/space_console/console_draw.cc b/source/blender/editors/space_console/console_draw.cc index 5ca4a1442c1..4a8710453a1 100644 --- a/source/blender/editors/space_console/console_draw.cc +++ b/source/blender/editors/space_console/console_draw.cc @@ -218,7 +218,11 @@ static int console_textview_main__internal(SpaceConsole *sc, console_textview_draw_rect_calc(region, &tvc.draw_rect, &tvc.draw_rect_outer); /* Nudge right by half a column or so to break selection mid-character. */ - const int m_pos[2] = {mval[0] + (tvc.lheight / 4), mval[1]}; + int m_pos[2] = {mval[0], mval[1]}; + /* Mouse position is initialized with max int. */ + if (m_pos[0] != INT_MAX) { + m_pos[0] += tvc.lheight / 4; + } console_scrollback_prompt_begin(sc, &cl_dummy); ret = textview_draw(&tvc, do_draw, m_pos, r_mval_pick_item, r_mval_pick_offset); diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index d75c1d732aa..2ae03b539e1 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -107,6 +107,10 @@ static int console_delete_editable_selection(SpaceConsole *sc) return 0; } + if (sc->sel_start < 0) { + sc->sel_start = 0; + } + ConsoleLine *cl = static_cast(sc->history.last); if (!cl || sc->sel_start > cl->len) { sc->sel_start = sc->sel_end; -- 2.30.2 From 4de83d3ba0fd5458824dfbdd6af27e97576ab052 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 22 Aug 2023 17:21:17 -0700 Subject: [PATCH 7/7] Updating to the current state of main. --- source/blender/editors/space_console/console_draw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_console/console_draw.cc b/source/blender/editors/space_console/console_draw.cc index ef1f34ce2af..e2f4f9ad21e 100644 --- a/source/blender/editors/space_console/console_draw.cc +++ b/source/blender/editors/space_console/console_draw.cc @@ -217,7 +217,7 @@ static int console_textview_main__internal(SpaceConsole *sc, console_textview_draw_rect_calc(region, &tvc.draw_rect, &tvc.draw_rect_outer); - /* Nudge right by half a column or so to break selection mid-character. */ + /* Nudge right by half a column to break selection mid-character. */ int m_pos[2] = {mval[0], mval[1]}; /* Mouse position is initialized with max int. */ if (m_pos[0] != INT_MAX) { -- 2.30.2