diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index ea7f59b5..4a656482 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -3350,9 +3350,15 @@ namespace nana{ namespace widgets line_px_( editor.line_height() ) {} + color selection_text_color(bool has_focused) const + { + return (has_focused ? editor_.scheme_->selection_text : editor_.scheme_->foreground).get_color(); + } + void write_selection(const point& text_pos, unsigned text_px, const wchar_t* text, std::size_t len, bool has_focused) { - graph_.palette(true, editor_.scheme_->selection_text.get_color()); + graph_.palette(true, selection_text_color(has_focused)); + graph_.rectangle(::nana::rectangle{ text_pos, { text_px, line_px_ } }, true, has_focused ? editor_.scheme_->selection.get_color() : editor_.scheme_->selection_unfocused.get_color()); graph_.string(text_pos, text, len); @@ -3360,7 +3366,7 @@ namespace nana{ namespace widgets void rtl_string(point strpos, const wchar_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected, bool has_focused) { - editor_._m_draw_parse_string(parser_, true, strpos, editor_.scheme_->selection_text.get_color(), str, len); + editor_._m_draw_parse_string(parser_, true, strpos, selection_text_color(has_focused), str, len); //Draw selected part paint::graphics graph({ glyph_selected, line_px_ }); @@ -3369,7 +3375,7 @@ namespace nana{ namespace widgets int sel_xpos = static_cast(str_px - (glyph_front + glyph_selected)); - graph.palette(true, editor_.scheme_->selection_text.get_color()); + graph.palette(true, selection_text_color(has_focused)); graph.string({ -sel_xpos, 0 }, str, len); graph_.bitblt(nana::rectangle(strpos.x + sel_xpos, strpos.y, glyph_selected, line_px_), graph); }; @@ -3457,9 +3463,11 @@ namespace nana{ namespace widgets //A text editor feature, it draws an extra block at end of line if the end of line is in range of selection. bool extra_space = false; + //Create a flag for indicating whether the whole line is selected const bool text_selected = (sbegin == text_ptr && send == text_ptr+ text_len); + //The text is not selected or the whole line text is selected - if (!focused || (!sbegin || !send) || text_selected || !attributes_.enable_caret) + if ((!sbegin || !send) || text_selected) { for (auto & ent : reordered) {