diff --git a/source/blender/editors/space_console/space_console.cc b/source/blender/editors/space_console/space_console.cc index d8fbf3d1295..ac40af94170 100644 --- a/source/blender/editors/space_console/space_console.cc +++ b/source/blender/editors/space_console/space_console.cc @@ -183,13 +183,11 @@ static bool console_drop_string_poll(bContext * /*C*/, wmDrag *drag, const wmEve static void console_drop_string_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop) { - const std::string *str = static_cast(drag->poin); /* NOTE(@ideasman42): Only a single line is supported, multiple lines could be supported * but this implies executing all lines except for the last. While we could consider that, * there are some security implications for this, so just drop one line for now. */ - const size_t eol = str->find('\n'); - RNA_string_set( - drop->ptr, "text", (eol == std::string::npos) ? str->c_str() : str->substr(0, eol).c_str()); + std::string str = WM_drag_get_string_firstline(drag); + RNA_string_set(drop->ptr, "text", str.c_str()); } /* this region dropbox definition */ diff --git a/source/blender/editors/space_text/space_text.cc b/source/blender/editors/space_text/space_text.cc index 64153352aef..d0241fe6939 100644 --- a/source/blender/editors/space_text/space_text.cc +++ b/source/blender/editors/space_text/space_text.cc @@ -339,8 +339,8 @@ static bool text_drop_string_poll(bContext * /*C*/, wmDrag *drag, const wmEvent static void text_drop_string_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop) { - const std::string *str = static_cast(drag->poin); - RNA_string_set(drop->ptr, "text", str->c_str()); + const std::string &str = WM_drag_get_string(drag); + RNA_string_set(drop->ptr, "text", str.c_str()); } /* this region dropbox definition */ diff --git a/source/blender/windowmanager/WM_api.hh b/source/blender/windowmanager/WM_api.hh index 36c7425a798..b1350bcf643 100644 --- a/source/blender/windowmanager/WM_api.hh +++ b/source/blender/windowmanager/WM_api.hh @@ -1496,6 +1496,9 @@ bool WM_drag_has_path_file_type(const wmDrag *drag, int file_type); */ int /* #eFileSel_File_Types */ WM_drag_get_path_file_type(const wmDrag *drag); +const std::string &WM_drag_get_string(const wmDrag *drag); +std::string WM_drag_get_string_firstline(const wmDrag *drag); + /* Set OpenGL viewport and scissor */ void wmViewport(const rcti *winrct); void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct); diff --git a/source/blender/windowmanager/intern/wm_dragdrop.cc b/source/blender/windowmanager/intern/wm_dragdrop.cc index c77ad9bc8c5..4bf890c5f23 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.cc +++ b/source/blender/windowmanager/intern/wm_dragdrop.cc @@ -922,6 +922,24 @@ int WM_drag_get_path_file_type(const wmDrag *drag) return path_data->file_types[0]; } +const std::string &WM_drag_get_string(const wmDrag *drag) +{ + BLI_assert(drag->type == WM_DRAG_STRING); + const std::string *str = static_cast(drag->poin); + return *str; +} + +std::string WM_drag_get_string_firstline(const wmDrag *drag) +{ + BLI_assert(drag->type == WM_DRAG_STRING); + const std::string *str = static_cast(drag->poin); + const size_t str_eol = str->find('\n'); + if (str_eol != std::string::npos) { + return str->substr(0, str_eol); + } + return *str; +} + /* ************** draw ***************** */ static void wm_drop_operator_draw(const blender::StringRef name, int x, int y)