diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index d2a10a35..4ebee6ec 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -215,7 +215,11 @@ namespace nana{ namespace widgets std::wstring text() const; /// Sets caret position through text coordinate. - void move_caret(const upoint&); + /** + * @param pos the text position + * @param reset indicates whether to reset the text position by the pos. If this parameter is true, the text position is set by pos. If the parameter is false, it only moves the UI caret to the specified position. + */ + void move_caret(const upoint& pos, bool reset = false); void move_caret_end(); void reset_caret_pixels() const; void reset_caret(); diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index e30248a8..b7a4cda0 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1840,8 +1840,11 @@ namespace nana{ namespace widgets //move_caret //Set caret position through text coordinate - void text_editor::move_caret(const upoint& crtpos) + void text_editor::move_caret(const upoint& crtpos, bool reset_caret) { + if (reset_caret) + points_.caret = crtpos; + if (!API::is_focus_ready(window_)) return; diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 12f42872..38d0d1c7 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -345,7 +345,7 @@ namespace drawerbase { auto editor = get_drawer_trigger().editor(); internal_scope_guard lock; if (editor) - editor->move_caret(pos); + editor->move_caret(pos, true); return *this; }