@@ -65,23 +65,28 @@ function OrgMappings:archive()
65
65
end
66
66
67
67
function OrgMappings :set_tags ()
68
- local headline = Files .get_closest_headline ()
69
- local own_tags = headline :get_own_tags ()
70
- local tags = vim .fn .OrgmodeInput (' Tags: ' , utils .tags_to_string (own_tags ), Files .autocomplete_tags )
71
- return self :_set_headline_tags (headline , tags )
68
+ local headline = Headline :new (tree_utils .closest_headline ())
69
+ local _ , current_tags = headline :tags ()
70
+
71
+ local tags = vim .fn .OrgmodeInput (' Tags: ' , current_tags , Files .autocomplete_tags )
72
+
73
+ return headline :set_tags (tags )
72
74
end
73
75
74
76
function OrgMappings :toggle_archive_tag ()
75
- local headline = Files .get_closest_headline ()
76
- local own_tags = headline :get_own_tags ()
77
- if vim .tbl_contains (own_tags , ' ARCHIVE' ) then
78
- own_tags = vim .tbl_filter (function (tag )
77
+ local headline = Headline :new (tree_utils .closest_headline ())
78
+ local _ , current_tags = headline :tags ()
79
+
80
+ local parsed = utils .parse_tags_string (current_tags )
81
+ if vim .tbl_contains (parsed , ' ARCHIVE' ) then
82
+ parsed = vim .tbl_filter (function (tag )
79
83
return tag ~= ' ARCHIVE'
80
- end , own_tags )
84
+ end , parsed )
81
85
else
82
- table.insert (own_tags , ' ARCHIVE' )
86
+ table.insert (parsed , ' ARCHIVE' )
83
87
end
84
- return self :_set_headline_tags (headline , utils .tags_to_string (own_tags ))
88
+
89
+ return headline :set_tags (utils .tags_to_string (parsed ))
85
90
end
86
91
87
92
function OrgMappings :cycle ()
@@ -849,28 +854,6 @@ function OrgMappings:_adjust_date(amount, span, fallback)
849
854
return vim .api .nvim_feedkeys (utils .esc (fallback ), ' n' , true )
850
855
end
851
856
852
- function OrgMappings :_set_headline_tags (headline , tags_string )
853
- local tags = tags_string :gsub (' ^:+' , ' ' ):gsub (' :+$' , ' ' ):gsub (' :+' , ' :' )
854
- if tags ~= ' ' then
855
- tags = ' :' .. tags .. ' :'
856
- end
857
- local line_without_tags = headline .line
858
- :gsub (vim .pesc (utils .tags_to_string (headline :get_own_tags ())) .. ' %s*$' , ' ' )
859
- :gsub (' %s*$' , ' ' )
860
-
861
- local to_col = config .org_tags_column
862
- if to_col < 0 then
863
- local tags_width = vim .api .nvim_strwidth (tags )
864
- to_col = math.abs (to_col ) - tags_width
865
- end
866
-
867
- local line_width = vim .api .nvim_strwidth (line_without_tags )
868
- spaces = math.max (to_col - line_width , 1 )
869
-
870
- local new_line = string.format (' %s%s%s' , line_without_tags , string.rep (' ' , spaces ), tags ):gsub (' %s*$' , ' ' )
871
- return vim .fn .setline (headline .range .start_line , new_line )
872
- end
873
-
874
857
--- @return string | nil
875
858
function OrgMappings :_get_link_under_cursor ()
876
859
local found_link = nil
0 commit comments