@@ -7,6 +7,13 @@ local AgendaItem = require('orgmode.agenda.agenda_item')
7
7
local AgendaFilter = require (' orgmode.agenda.filter' )
8
8
local utils = require (' orgmode.utils' )
9
9
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
+
10
17
--- @param agenda_items AgendaItem[]
11
18
--- @return AgendaItem[]
12
19
local function sort_agenda_items (agenda_items )
@@ -18,7 +25,10 @@ local function sort_agenda_items(agenda_items)
18
25
if not a .headline_date .date_only then
19
26
return true
20
27
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 )
22
32
end
23
33
24
34
if a .is_same_day and not b .is_same_day then
@@ -37,7 +47,7 @@ local function sort_agenda_items(agenda_items)
37
47
return a .headline :get_priority_sort_value () > b .headline :get_priority_sort_value ()
38
48
end
39
49
40
- return a . headline_date : is_before ( b . headline_date )
50
+ return sort_by_date_or_category ( a , b )
41
51
end )
42
52
return agenda_items
43
53
end
@@ -139,8 +149,8 @@ function AgendaView:_build_items()
139
149
for _ , day in ipairs (dates ) do
140
150
local date = { day = day , agenda_items = {} }
141
151
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 )
144
154
if agenda_item .is_valid and self .filters :matches (item .headline ) then
145
155
table.insert (date .agenda_items , agenda_item )
146
156
end
0 commit comments