@@ -7,6 +7,13 @@ local AgendaItem = require('orgmode.agenda.agenda_item')
77local AgendaFilter = require (' orgmode.agenda.filter' )
88local utils = require (' orgmode.utils' )
99
10+ local function sort_by_date_or_category (a , b )
11+ if not a .headline_date :is_same (b .headline_date ) then
12+ return a .headline_date :is_before (b .headline_date )
13+ end
14+ return a .index < b .index
15+ end
16+
1017--- @param agenda_items AgendaItem[]
1118--- @return AgendaItem[]
1219local function sort_agenda_items (agenda_items )
@@ -18,7 +25,10 @@ local function sort_agenda_items(agenda_items)
1825 if not a .headline_date .date_only then
1926 return true
2027 end
21- return false
28+ if not b .headline_date .date_only then
29+ return false
30+ end
31+ return sort_by_date_or_category (a , b )
2232 end
2333
2434 if a .is_same_day and not b .is_same_day then
@@ -37,7 +47,7 @@ local function sort_agenda_items(agenda_items)
3747 return a .headline :get_priority_sort_value () > b .headline :get_priority_sort_value ()
3848 end
3949
40- return a . headline_date : is_before ( b . headline_date )
50+ return sort_by_date_or_category ( a , b )
4151 end )
4252 return agenda_items
4353end
@@ -139,8 +149,8 @@ function AgendaView:_build_items()
139149 for _ , day in ipairs (dates ) do
140150 local date = { day = day , agenda_items = {} }
141151
142- for _ , item in ipairs (headline_dates ) do
143- local agenda_item = AgendaItem :new (item .headline_date , item .headline , day )
152+ for index , item in ipairs (headline_dates ) do
153+ local agenda_item = AgendaItem :new (item .headline_date , item .headline , day , index )
144154 if agenda_item .is_valid and self .filters :matches (item .headline ) then
145155 table.insert (date .agenda_items , agenda_item )
146156 end
0 commit comments