@@ -362,30 +362,15 @@ void GTextEditor::paint_event(GPaintEvent& event)
362
362
int first_visual_line_with_selection = -1 ;
363
363
int last_visual_line_with_selection = -1 ;
364
364
if (physical_line_has_selection) {
365
- if (selection.start ().line () < line_index) {
365
+ if (selection.start ().line () < line_index)
366
366
first_visual_line_with_selection = 0 ;
367
- } else {
368
- int visual_line_index = 0 ;
369
- line.for_each_visual_line ([&](const Rect&, const StringView& view, int start_of_visual_line) {
370
- if (selection.start ().column () >= start_of_visual_line && ((selection.start ().column () - start_of_visual_line) < view.length ()))
371
- return IterationDecision::Break;
372
- ++visual_line_index;
373
- return IterationDecision::Continue;
374
- });
375
- first_visual_line_with_selection = visual_line_index;
376
- }
377
- if (selection.end ().line () > line_index) {
367
+ else
368
+ first_visual_line_with_selection = line.visual_line_containing (selection.start ().column ());
369
+
370
+ if (selection.end ().line () > line_index)
378
371
last_visual_line_with_selection = line.m_visual_line_breaks .size ();
379
- } else {
380
- int visual_line_index = 0 ;
381
- line.for_each_visual_line ([&](const Rect&, const StringView& view, int start_of_visual_line) {
382
- if (selection.end ().column () >= start_of_visual_line && ((selection.end ().column () - start_of_visual_line) < view.length ()))
383
- return IterationDecision::Break;
384
- ++visual_line_index;
385
- return IterationDecision::Continue;
386
- });
387
- last_visual_line_with_selection = visual_line_index;
388
- }
372
+ else
373
+ last_visual_line_with_selection = line.visual_line_containing (selection.end ().column ());
389
374
}
390
375
391
376
int selection_start_column_within_line = selection.start ().line () == line_index ? selection.start ().column () : 0 ;
@@ -1416,3 +1401,15 @@ void GTextEditor::set_line_wrapping_enabled(bool enabled)
1416
1401
recompute_all_visual_lines ();
1417
1402
update ();
1418
1403
}
1404
+
1405
+ int GTextEditor::Line::visual_line_containing (int column) const
1406
+ {
1407
+ int visual_line_index = 0 ;
1408
+ for_each_visual_line ([&](const Rect&, const StringView& view, int start_of_visual_line) {
1409
+ if (column >= start_of_visual_line && ((column - start_of_visual_line) < view.length ()))
1410
+ return IterationDecision::Break;
1411
+ ++visual_line_index;
1412
+ return IterationDecision::Continue;
1413
+ });
1414
+ return visual_line_index;
1415
+ }
0 commit comments