@@ -186,11 +186,12 @@ local style = {
186
186
}
187
187
188
188
local state = {
189
- list = {},
190
- selected = 1 ,
191
- hidden = true ,
192
- flag_update = false ,
193
- keybinds = nil ,
189
+ list = {}, -- list of items
190
+ selected = 1 , -- currently selected item
191
+ scroll_offset = 0 ,
192
+ hidden = true , -- whether the browser is hidden
193
+ flag_update = false , -- should we redraw the browser when next opened
194
+ keybinds = nil , -- array of dynamic deybinds
194
195
195
196
parser = nil ,
196
197
directory = nil ,
@@ -710,18 +711,13 @@ local function update_ass()
710
711
local start = 1
711
712
local finish = start + o .num_entries - 1
712
713
713
- -- handling cursor positioning
714
- local mid = math.ceil (o .num_entries / 2 )+ 1
715
- if state .selected + mid > finish then
716
- local offset = state .selected - finish + mid
717
-
718
- -- if we've overshot the end of the list then undo some of the offset
719
- if finish + offset > # state .list then
720
- offset = offset - ((finish + offset ) - # state .list )
714
+ -- handling the offset caused by scrolling
715
+ if state .scroll_offset > 0 then
716
+ if finish + state .scroll_offset > # state .list then
717
+ state .scroll_offset = # state .list - finish
721
718
end
722
-
723
- start = start + offset
724
- finish = finish + offset
719
+ start = start + state .scroll_offset
720
+ finish = finish + state .scroll_offset
725
721
end
726
722
727
723
-- making sure that we don't overstep the boundaries
@@ -832,6 +828,12 @@ local function scroll(n, wrap)
832
828
end
833
829
834
830
if state .multiselect_start then drag_select (original_pos , state .selected ) end
831
+
832
+ -- moves the scroll window down so that the selected item is in the middle of the screen
833
+ state .scroll_offset = state .selected - (math.ceil (o .num_entries / 2 )- 1 )
834
+ if state .scroll_offset < 0 or (state .scroll_offset + o .num_entries ) > # state .list then
835
+ state .scroll_offset = 0
836
+ end
835
837
update_ass ()
836
838
end
837
839
@@ -863,13 +865,30 @@ end
863
865
864
866
-- update the selected item based on the mouse position
865
867
local function update_mouse_pos (_ , mouse_pos )
868
+ if not mouse_pos then mouse_pos = mp .get_property_native (" mouse-pos" ) end
866
869
if not mouse_pos .hover then return end
867
870
local scale = mp .get_property_number (" osd-height" , 0 ) / 720
871
+
872
+ -- this will currently not work with different sized headers
873
+ -- for some reason the scaling calculation works differently for the header
868
874
local header_offset = 65
869
- state .selected = math.ceil ((mouse_pos .y - header_offset ) / (25 * scale ))
875
+ if state .scroll_offset > 0 then
876
+ header_offset = header_offset + o .font_size_wrappers * scale
877
+ end
878
+
879
+ state .selected = math.ceil ((mouse_pos .y - header_offset ) / (o .font_size_body * scale )) + state .scroll_offset
870
880
update_ass ()
871
881
end
872
882
883
+ -- scrolls the view window when using mouse mode
884
+ local function wheel (direction )
885
+ state .scroll_offset = state .scroll_offset + direction
886
+ if state .scroll_offset < 0 or (state .scroll_offset + o .num_entries ) > # state .list then
887
+ state .scroll_offset = 0
888
+ end
889
+ update_mouse_pos ()
890
+ end
891
+
873
892
---- ----------------------------------------------------------------------------------------------------
874
893
---- -------------------------------------Directory Movement---------------------------------------------
875
894
---- ----------------------------------------------------------------------------------------------------
0 commit comments