Add Comment
Organize Your Roblox Code
DISCLAIMER
This plugin breaks when you have 2+ scripts named the same.
I will work on fixing this when I have a little more time however for now,
you will have to rename scripts.
(You can always change them back after)
About
This plugin is a simple code-organizer.
As a VSCode programmer, we have a wide access to
extensions which aren’t available on Roblox.
However, for the people who don’t use VSCode or the
times when we cant use VSCode, we don’t have access
to these extensions!
As for this reason, I made this plugin.
Heavily inspired from CommentDivider
Make sure to go and show the original author some love!
How To Use
Due to Roblox not really supporting UserInputService
on plugins, I’ve chosen to make this per-player.
This means you have to setup your own key-binds for the functions.
For people who don't know how to set custom key-binds
Firstly, go to File > Advanced > Customize Shortcuts…
Then from here, search “Add” in the search box.
Assuming you have enabled and installed the plugin,
the following 3 options should show.
From here, just set the key-binds to your liking!
I recommend:
[Alt + Y] for Empty Divider
[Alt + X] for Divider
[Shift + Alt + X] for Header
How to use / Example:
Links
That’s It!
Thank you for reading this post. This is my
first every plugin that I’ve created.
I’m pretty sure this hasn’t already been made
but if it has, please link it down below!
Feel free to leave any ideas and/or comments,
I’ll read them when I have chance to!
If you want to change the amount of “dashes” that
show, as there’s no config UI at the moment,
you’ll have to edit the source code and save it as
a local plugin.
Source Code
local ScriptEditorService = game:GetService("ScriptEditorService")
local StudioService = game:GetService("StudioService")
local lineLength = 80
local selectedLine, selectedLineText
local selectionConnection
local function empty(): string
return ("-"):rep(lineLength + 6)
end
local function divider(text: string): string
text = text:gsub("^[\t]+", "")
local padding = math.floor((lineLength - #text - 2) / 2)
return `-- {("-"):rep(padding)} {text} {("-"):rep(lineLength - padding - #text - 2)} --`
end
local function header(text: string): string
text = text:gsub("^[\t]+", "")
local indent = selectedLineText:match("^%s+") and #selectedLineText:match("^%s+") or 0
local tab = (" "):rep(indent)
local line = ("-"):rep(lineLength)
local padding = math.floor((lineLength - #text) / 2)
return (`-- {line} --\n%s-- {(" "):rep(padding)}{text}{(" "):rep(lineLength - padding - #text)} --\n%s-- {line} --`):format(tab, tab)
end
local function getActiveDocument()
if not StudioService.ActiveScript then return end
for _, document in ScriptEditorService:GetScriptDocuments() do
if not document:IsCommandBar() and document.Name:match("[^.]+$") == StudioService.ActiveScript.Name then
return document
end
end
end
local function updateSelection()
local scriptDocument = getActiveDocument()
if scriptDocument then
if selectionConnection then selectionConnection:Disconnect() end
local function setSelection(positionLine)
local lineText = scriptDocument:GetLine(positionLine)
selectedLine = positionLine
selectedLineText = lineText
end
selectionConnection = scriptDocument.SelectionChanged:Connect(setSelection)
setSelection(scriptDocument:GetSelection())
end
end
local function replaceLineWithText(replaceText)
updateSelection()
local scriptDocument = getActiveDocument()
if scriptDocument and selectedLine then
local indent = selectedLineText:match("^%s+") and #selectedLineText:match("^%s+") or 0
scriptDocument:EditTextAsync(string.rep(" ", indent) .. replaceText, selectedLine, 1, selectedLine, #replaceText + indent)
end
end
updateSelection()
StudioService:GetPropertyChangedSignal("ActiveScript"):Connect(updateSelection)
local emptyAction = plugin:CreatePluginAction("Empty", "Add Empty Divider", "Adds an empty divider")
local dividerAction = plugin:CreatePluginAction("Divider", "Add Divider", "Adds a divider")
local headerAction = plugin:CreatePluginAction("Header", "Add Header", "Adds a header")
emptyAction.Triggered:Connect(function()
replaceLineWithText(empty())
end)
dividerAction.Triggered:Connect(function()
replaceLineWithText(divider(selectedLineText))
end)
headerAction.Triggered:Connect(function()
replaceLineWithText(header(selectedLineText))
end)