I am working on a plugin that helps you edit and fix your code.
I made a 'replace keyword' system but when a keyword is replaced in another script source, an extra line comes in the source.
local rptext = ui.Frame.Replace.Text local withtext = ui.Frame.With.Text local lines = {} for line in string.gmatch(item.Source, "[^\n]*") do if string.find(line,rptext) then local modifiedline = string.gsub(line,rptext,withtext) table.insert(lines, modifiedline) else table.insert(lines, line) end end item.Source = table.concat(lines,'\n')
i was trying to find the cause of the issue for a long time but it's kind of hard, i will make an update if i find out about it. what i could find out was that it seems to match some character after some non-empty newlines which returns nil when put into string.byte
.
the solution for your case is to just string.split
, there really is no need for gmatch
, split the string by newlines:
local rptext = ui.Frame.Replace.Text local withtext = ui.Frame.With.Text local lines = string.split(item.Source, "\n") for i, line in ipairs(lines) do lines[i] = string.gsub(line, rptext, withtext) end item.Source = table.concat(lines, "\n")
notice there is no reason to check if string.find
finds something, gsub
won't replace anything if it's not found, you are redundantly doing 2 pattern searches.
now let's get to feedback part, your plugin is absolute trash... like who can't just click Ctrl + H you self appointed programmer ;-;