@@ -23,11 +23,11 @@ local function install_notes_overlay(options)
2323 overlay .rescan ()
2424 overlay .overlay_command ({' enable' , ' notes.map_notes' })
2525
26- local overlay_state = overlay .get_state ()
27- if not overlay_state .config [' notes.map_notes' ].enabled then
26+ if not overlay .isOverlayEnabled (' notes.map_notes' ) then
2827 qerror (' can not enable notes.map_notes overlay' )
2928 end
3029
30+ local overlay_state = overlay .get_state ()
3131 return overlay_state .db [' notes.map_notes' ].widget
3232end
3333
@@ -83,6 +83,21 @@ function set_mouse_screen_pos(screen_pos)
8383
8484end
8585
86+ function get_visible_map_center ()
87+ local viewport = guidm .Viewport .get ()
88+
89+ local half_x = math.max (
90+ math.floor ((viewport .x1 + viewport .x2 ) / 2 ),
91+ 2
92+ )
93+ local half_y = math.max (
94+ math.floor ((viewport .y1 + viewport .y2 ) / 2 ),
95+ 2
96+ )
97+
98+ return half_x , half_y , viewport .z
99+ end
100+
86101function test .load_notes_overlay ()
87102 local notes_overlay = install_notes_overlay ()
88103 expect .ne (notes_overlay , nil )
@@ -108,8 +123,7 @@ function test.render_existing_notes()
108123
109124 local viewport = guidm .Viewport .get ()
110125
111- local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
112- local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
126+ local half_x , half_y = get_visible_map_center ()
113127
114128 local pos_1 = {x = half_x , y = half_y , z = viewport .z }
115129 local pos_2 = {x = half_x - 2 , y = half_y + 2 , z = viewport .z }
@@ -137,8 +151,7 @@ function test.edit_clicked_note()
137151
138152 local viewport = guidm .Viewport .get ()
139153
140- local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
141- local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
154+ local half_x , half_y , z = get_visible_map_center ()
142155
143156 local pos_1 = {x = half_x , y = half_y , z = viewport .z }
144157 local pos_2 = {x = half_x - 2 , y = half_y + 2 , z = viewport .z }
@@ -182,8 +195,7 @@ function test.delete_clicked_note()
182195
183196 local viewport = guidm .Viewport .get ()
184197
185- local half_x = math.floor ((viewport .x1 + viewport .x2 ) / 2 )
186- local half_y = math.floor ((viewport .y1 + viewport .y2 ) / 2 )
198+ local half_x , half_y = get_visible_map_center ()
187199
188200 local pos_1 = {x = half_x , y = half_y , z = viewport .z }
189201 local pos_2 = {x = half_x - 2 , y = half_y + 2 , z = viewport .z }
0 commit comments