mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 22:11:38 +00:00
Add whitespace change detection utility and integrate into PatchTree. Enhanced PatchTree to count line changes specifically for Source properties, distinguishing between total and whitespace-only changes. Updated theme colors for visual representation of whitespace changes in the UI.
This commit is contained in:
parent
00872e65a4
commit
9bedbd70fd
4 changed files with 128 additions and 24 deletions
50
plugin/src/WhitespaceUtil.lua
Normal file
50
plugin/src/WhitespaceUtil.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
--[[
|
||||
Utility for detecting whitespace-only changes in source code.
|
||||
]]
|
||||
|
||||
local WhitespaceUtil = {}
|
||||
|
||||
local function SplitLines(str: string): { string }
|
||||
local lines = {}
|
||||
for line in string.gmatch(str .. "\n", "([^\n]*)\n") do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
local function NormalizeLine(line: string): string
|
||||
return string.gsub(string.gsub(line, "\r+$", ""), "[ \t]+$", "")
|
||||
end
|
||||
|
||||
-- Counts lines that differ between two strings (capped at 100)
|
||||
-- Returns: totalDiff, whitespaceDiff (lines that only differ in whitespace)
|
||||
-- Returns 10000, 10000 if exceeds 100 (frontend displays as "100+")
|
||||
function WhitespaceUtil.CountLineDifferences(current: string, incoming: string): (number, number)
|
||||
if type(current) ~= "string" or type(incoming) ~= "string" then
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
local currentLines = SplitLines(current)
|
||||
local incomingLines = SplitLines(incoming)
|
||||
local maxLines = math.max(#currentLines, #incomingLines)
|
||||
|
||||
local totalDiff, whitespaceDiff = 0, 0
|
||||
for i = 1, maxLines do
|
||||
local currentLine = currentLines[i] or ""
|
||||
local incomingLine = incomingLines[i] or ""
|
||||
|
||||
if currentLine ~= incomingLine then
|
||||
totalDiff += 1
|
||||
if NormalizeLine(currentLine) == NormalizeLine(incomingLine) then
|
||||
whitespaceDiff += 1
|
||||
end
|
||||
if totalDiff > 100 then
|
||||
return 10000, 10000
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return totalDiff, whitespaceDiff
|
||||
end
|
||||
|
||||
return WhitespaceUtil
|
||||
Loading…
Add table
Add a link
Reference in a new issue