1    type MultilineTextBox
2        def clear_selection =
3            selection = None
4    
5        let selection_z = Control.offset_z
6        let selection_token = selection@atom.subscribe { _ x -> case x of
7            None ->
8                selection_start.is_visible = false
9                selection_middle.is_visible = false
10               selection_end.is_visible = false
11   
12           Some (start, end) ->
13               let start_bounds = text_display.bounds start
14               let end_bounds = text_display.bounds end
15               selection_start.is_visible = true
16               let offset_y = text_display.line_height.as<f32> * 0.17 |> as<u32>
17               if start_bounds.up == end_bounds.up then
18                   selection_middle.is_visible = false
19                   selection_end.is_visible = false
20   
21                   let v = Vector3
22                       x = start_bounds.left as f32 + offset as f32
23                       y = start_bounds.up as f32 - offset_y as f32
24                       z = selection_z
25   
26                   selection_start.position = v
27                                   set_fixed_width (end_bounds.left - start_bounds.left)
28                                   set_fixed_height (end_bounds.down - end_bounds.up)
29               else
30                   selection_end.is_visible = true
31   
32                   let updated_start_x = if start.char == 0
33                                         then 0
34                                         else start_bounds.left
35   
36                   let start_v = Vector3
37                       x = updated_start_x as f32 + offset as f32
38                       y = start_bounds.up as f32 - offset_y as f32
39                       z = selection_z
40   
41                   selection_start.position = start_v
42                                   set_fixed_width (canvas.width - updated_start_x)
43                                   set_fixed_height (start_bounds.down - start_bounds.up)
44   
45                   let middle_height = end_bounds.up as i32 - start_bounds.down as i32
46                   if middle_height > 0 then
47                       selection_middle.is_visible = true
48                       let middle_v = Vector3
49                           x = offset as f32
50                           y = start_bounds.down as f32 - offset_y as f32
51                           z = selection_z
52   
53                       selection_middle.position = middle_v
54                                        set_fixed_width canvas.width
55                                        set_fixed_height middle_height.as<u32>
56                   else
57                       selection_middle.is_visible = false
58   
59                   let end_v = Vector3
60                       x = offset as f32
61                       y = end_bounds.up as f32 - offset_y as f32
62                       z = selection_z
63   
64                   selection_end.position = end_v
65                                 set_fixed_width end_bounds.left
66                                 set_fixed_height (end_bounds.down - end_bounds.up) }
67   
68       push_token selection_token
69