> Since you asked. :-) 2nd iteration.
this is the current situation: http://leuven.economists.nl/lyx/sel1.png the attached patch gives this: http://leuven.economists.nl/lyx/sel2.png
Index: src/TextMetrics.cpp =================================================================== --- src/TextMetrics.cpp (revision 24087) +++ src/TextMetrics.cpp (working copy) @@ -2025,8 +2025,8 @@ if (row_selection) { DocIterator beg = bv_->cursor().selectionBegin(); DocIterator end = bv_->cursor().selectionEnd(); - bool const beg_margin = beg.pit() < pit && i == 0; - bool const end_margin = end.pit() > pit && i == nrows - 1; + bool const beg_margin = beg.pit() < pit || row.sel_beg == cur.textRow().pos(); + bool const end_margin = end.pit() > pit || row.sel_end == cur.textRow().endpos(); beg.pit() = pit; beg.pos() = row.sel_beg; end.pit() = pit; @@ -2082,17 +2082,23 @@ // draw the margins if (drawOnBegMargin) { - if (text_->isRTL(buffer, beg.paragraph())) - pi.pain.fillRectangle(x + x1, y1, width() - x1, y2 - y1, Color_selection); - else - pi.pain.fillRectangle(x, y1, x1, y2 - y1, Color_selection); + if (text_->isRTL(buffer, beg.paragraph())) { + int lm = bv_->leftMargin(); + pi.pain.fillRectangle(x + x1, y1, width() - lm - x1, y2 - y1, Color_selection); + } else { + int rm = bv_->rightMargin(); + pi.pain.fillRectangle(rm, y1, x1 - rm, y2 - y1, Color_selection); + } } if (drawOnEndMargin) { - if (text_->isRTL(buffer, beg.paragraph())) - pi.pain.fillRectangle(x, y1, x2, y2 - y1, Color_selection); - else - pi.pain.fillRectangle(x + x2, y1, width() - x2, y2 - y1, Color_selection); + if (text_->isRTL(buffer, beg.paragraph())) { + int rm = bv_->rightMargin(); + pi.pain.fillRectangle(x + rm, y1, x2 - rm, y2 - y1, Color_selection); + } else { + int lm = bv_->leftMargin(); + pi.pain.fillRectangle(x + x2, y1, width() - lm - x2, y2 - y1, Color_selection); + } } // if we are on a boundary from the beginning, it's probably