@@ -799,10 +799,7 @@ impl Selection {
799
799
/// This avoids allocation if the intent is to render the rectangles
800
800
/// immediately.
801
801
pub fn geometry_with < B : Brush > ( & self , layout : & Layout < B > , mut f : impl FnMut ( Rect ) ) {
802
- // Ensure we add some visual indicator for selected empty
803
- // lines.
804
- // Make this configurable?
805
- const MIN_RECT_WIDTH : f64 = 8.0 ;
802
+ const NEWLINE_WHITESPACE_WIDTH_RATIO : f64 = 0.25 ;
806
803
if self . is_collapsed ( ) {
807
804
return ;
808
805
}
@@ -824,6 +821,17 @@ impl Selection {
824
821
let metrics = line. metrics ( ) ;
825
822
let line_min = metrics. min_coord as f64 ;
826
823
let line_max = metrics. max_coord as f64 ;
824
+ // Trailing whitespace to indicate that the newline character at the
825
+ // end of this line is selected. It's based on the ascent and
826
+ // descent so it doesn't change with the line height.
827
+ //
828
+ // TODO: the width of this whitespace should be the width of a space
829
+ // (U+0020) character.
830
+ let newline_whitespace = if line. break_reason ( ) == BreakReason :: Explicit {
831
+ ( metrics. ascent as f64 + metrics. descent as f64 ) * NEWLINE_WHITESPACE_WIDTH_RATIO
832
+ } else {
833
+ 0.0
834
+ } ;
827
835
if line_ix == line_start_ix || line_ix == line_end_ix {
828
836
// We only need to run the expensive logic on the first and
829
837
// last lines
@@ -838,22 +846,29 @@ impl Selection {
838
846
cur_x += advance;
839
847
} else {
840
848
if cur_x != start_x {
841
- let width = ( cur_x - start_x) . max ( MIN_RECT_WIDTH ) ;
842
- f ( Rect :: new ( start_x, line_min, start_x + width, line_max) ) ;
849
+ f ( Rect :: new ( start_x, line_min, cur_x, line_max) ) ;
843
850
}
844
851
cur_x += advance;
845
852
start_x = cur_x;
846
853
}
847
854
}
848
855
}
849
- if cur_x != start_x || ( cluster_count != 0 && line. metrics ( ) . advance == 0.0 ) {
850
- let width = ( cur_x - start_x) . max ( MIN_RECT_WIDTH ) ;
851
- f ( Rect :: new ( start_x, line_min, start_x + width, line_max) ) ;
856
+ let mut end_x = cur_x;
857
+ if line_ix != line_end_ix || ( cluster_count != 0 && metrics. advance == 0.0 ) {
858
+ end_x += newline_whitespace;
859
+ }
860
+ if end_x != start_x {
861
+ f ( Rect :: new ( start_x, line_min, end_x, line_max) ) ;
852
862
}
853
863
} else {
854
864
let x = metrics. offset as f64 ;
855
- let width = ( metrics. advance as f64 ) . max ( MIN_RECT_WIDTH ) ;
856
- f ( Rect :: new ( x, line_min, x + width, line_max) ) ;
865
+ let width = metrics. advance as f64 ;
866
+ f ( Rect :: new (
867
+ x,
868
+ line_min,
869
+ x + width + newline_whitespace,
870
+ line_max,
871
+ ) ) ;
857
872
}
858
873
}
859
874
}
0 commit comments