Skip to content

Commit 0003623

Browse files
committed
LineContents:replaceTags(): make insertion of remaining tags not previously found in the line optional; automatically create tag section at the beginning of the line if insertion of remaining tags was requested at index 1
1 parent 67bb4ec commit 0003623

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

l0/ASSFoundation/LineContents.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ return function(ASS, ASSFInst, yutilsMissingMsg, createASSClass, re, util, unico
199199
return tags
200200
end
201201

202-
function LineContents:replaceTags(tagList, start, end_, relative) -- TODO: transform and reset support
202+
function LineContents:replaceTags(tagList, start, end_, relative, insertRemaining) -- TODO: transform and reset support
203+
insertRemaining = default(insertRemaining, true)
203204
if type(tagList)=="table" then
204205
if tagList.class == ASS.Section.Tag then
205206
tagList = ASS.TagList(tagList)
@@ -243,7 +244,15 @@ return function(ASS, ASSFInst, yutilsMissingMsg, createASSClass, re, util, unico
243244
end
244245

245246
-- insert remaining tags (not replaced) into the first processed section
246-
self:insertTags(toInsert, start or 1, nil, not relative)
247+
-- to easily allow for the function to be used to insert tags (overwriting existing ones)
248+
-- create tag section at index 1 when it was requested as the start of the replacement
249+
-- but doesn't yet exist
250+
if insertRemaining then
251+
start = start or 1
252+
if start == 1 and not relative and not ASS:instanceOf(self.sections[1], ASS.Section.Tag) then
253+
self:insertSections(ASS.Section.Tag(toInsert), 1)
254+
else self:insertTags(toInsert, start, nil, not relative) end
255+
end
247256
end
248257

249258
function LineContents:removeTags(tags, start, end_, relative)

0 commit comments

Comments
 (0)