Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-03-16 08:01:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-03-16 08:03:32 +0300
commitce009c80197e7d9b1466f8d15534c44a4b2a7608 (patch)
tree546e544001055fc093e24c0f117e379907fa29a2 /source/blender/editors/space_console/console_ops.c
parent4c58cb8bd9d524cd388abfebfcca3a618fd8e0d4 (diff)
PyConsole: double-click to select word
patch T43641 by @v-disp with own edits
Diffstat (limited to 'source/blender/editors/space_console/console_ops.c')
-rw-r--r--source/blender/editors/space_console/console_ops.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index 8263268898f..92731c2f135 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -262,6 +262,40 @@ static int console_line_insert(ConsoleLine *ci, char *str)
return len;
}
+/**
+ * Take an absolute index and give the line/column info.
+ *
+ * \note be sure to call console_scrollback_prompt_begin first
+ */
+static bool console_line_column_from_index(
+ SpaceConsole *sc, const int pos,
+ ConsoleLine **r_cl, int *r_cl_offset, int *r_col)
+{
+ ConsoleLine *cl;
+ int offset = 0;
+
+ for (cl = sc->scrollback.last; cl; cl = cl->prev) {
+ offset += cl->len + 1;
+ if (offset >= pos) {
+ break;
+ }
+ }
+
+ if (cl) {
+ offset -= 1;
+ *r_cl = cl;
+ *r_cl_offset = offset;
+ *r_col = offset - pos;
+ return true;
+ }
+ else {
+ *r_cl = NULL;
+ *r_cl_offset = -1;
+ *r_col = -1;
+ return false;
+ }
+}
+
/* static funcs for text editing */
/* similar to the text editor, with some not used. keep compatible */
@@ -1134,3 +1168,57 @@ void CONSOLE_OT_select_set(wmOperatorType *ot)
ot->cancel = console_modal_select_cancel;
ot->poll = ED_operator_console_active;
}
+
+static int console_selectword_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ ConsoleLine cl_dummy = {NULL};
+ ConsoleLine *cl;
+ int ret = OPERATOR_CANCELLED;
+ int pos, offset, n;
+
+ pos = console_char_pick(sc, ar, event->mval);
+
+ console_scrollback_prompt_begin(sc, &cl_dummy);
+
+ if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) {
+ int sel[2] = {n, n};
+
+ BLI_str_cursor_step_utf8(
+ cl->line, cl->len,
+ &sel[0], STRCUR_DIR_NEXT,
+ STRCUR_JUMP_DELIM, true);
+
+ BLI_str_cursor_step_utf8(
+ cl->line, cl->len,
+ &sel[1], STRCUR_DIR_PREV,
+ STRCUR_JUMP_DELIM, true);
+
+ sel[0] = offset - sel[0];
+ sel[1] = offset - sel[1];
+
+ if ((sel[0] != sc->sel_start) || (sel[1] != sc->sel_end)) {
+ sc->sel_start = sel[0];
+ sc->sel_end = sel[1];
+ ED_area_tag_redraw(CTX_wm_area(C));
+ ret = OPERATOR_FINISHED;
+ }
+ }
+
+ console_scrollback_prompt_end(sc, &cl_dummy);
+ return ret;
+}
+
+void CONSOLE_OT_select_word(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select Word";
+ ot->description = "Select word at cursor position";
+ ot->idname = "CONSOLE_OT_select_word";
+
+ /* api callbacks */
+ ot->invoke = console_selectword_invoke;
+ ot->poll = ED_operator_console_active;
+}