Skip to content

Commit fd2ed87

Browse files
committed
Adjust ace editor start line number to match function source start line
1 parent da7d8f0 commit fd2ed87

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lua/blobsprofiler/client/cl_blobsprofiler.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ blobsProfiler.viewPropertiesPopup = function(title, data, width, height)
108108
return propertiesFrame
109109
end
110110

111-
blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode, readOnly)
111+
blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode, readOnly, startLine)
112112
local dhtmlPanel = vgui.Create("DHTML", parentPanel)
113113
content = content or [[print("Hello world!")]]
114114
editorMode = editorMode or "Lua"
@@ -143,7 +143,8 @@ blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode
143143
editor.setOptions({
144144
showLineNumbers: true,
145145
tabSize: 2,
146-
readOnly: ]].. tostring(tobool(readOnly)) --[[ really? ]] ..[[
146+
readOnly: ]].. tostring(tobool(readOnly)) --[[ really? ]] ..[[,
147+
firstLineNumber: ]].. (startLine or 1 )..[[
147148
});
148149
149150
function getEditorValue() {
@@ -175,7 +176,11 @@ local function popupSourceView(sourceContent, frameTitle)
175176
sourceFrame:Center()
176177
sourceFrame:MakePopup()
177178

178-
local sourcePanel = blobsProfiler.generateAceEditorPanel(sourceFrame, sourceContent, "Lua", true)
179+
local startLine, endLine = frameTitle:match("Lines%: (%d+)%-(%d+)")
180+
startLine = tonumber(startLine)
181+
endLine = tonumber(endLine)
182+
183+
local sourcePanel = blobsProfiler.generateAceEditorPanel(sourceFrame, sourceContent, "Lua", true, startLine)
179184
sourcePanel:Dock(FILL)
180185

181186
sourcePanel.OnRemove = function()
@@ -228,8 +233,8 @@ net.Receive("blobsProfiler:sendSourceChunk", function()
228233
end
229234

230235
if allChunksReceived then
231-
local splitRequest = string.Explode(":", requestId)
232-
popupSourceView(combinedSource, splitRequest[1])
236+
--local splitRequest = string.Explode(":", requestId)
237+
popupSourceView(combinedSource, requestId)
233238

234239
receivedSource[requestId] = nil -- Clean up the request data
235240
end

lua/blobsprofiler/server/sv_blobsprofiler.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ net.Receive("blobsProfiler:requestSource", function(l, ply)
5959
findFile:Close()
6060

6161
local combinedSource = table.concat(fileContent)
62-
local requestID = filePath .. startLine .. ":" .. endLine -- Generate request ID
62+
local requestID = string.format("View source: %s (Lines: %i-%i)", filePath, startLine, (endLine == 0 and currentLine) or endLine) -- Generate request ID
6363
SendChunkedString(ply, requestID, combinedSource)
6464
end)
6565

0 commit comments

Comments
 (0)