#Toggle Block Comment
1 messages · Page 1 of 1 (latest)
local StudioService = game:GetService("StudioService")
local ScriptEditorService = game:GetService("ScriptEditorService")
local pluginAction = plugin:CreatePluginAction("ToggleBlockComment", "Toggle Block Comment", "Toggle selection block commenting")
pluginAction.Triggered:Connect(function()
if StudioService.ActiveScript == nil then return end
local scriptDocument = ScriptEditorService:FindScriptDocument(StudioService.ActiveScript)
if scriptDocument == nil then return end
if scriptDocument:HasSelectedText() == false then return end
local text = scriptDocument:GetSelectedText()
local startLine, startCharacter = scriptDocument:GetSelectionStart()
local endLine, endCharacter = scriptDocument:GetSelectionEnd()
local cursorLine, cursorCharacter, anchorLine, anchorCharacter = scriptDocument:GetSelection()
local curserlarger = cursorLine > anchorLine or cursorLine == anchorLine and cursorCharacter > anchorCharacter
local shiftSelection = if cursorLine == anchorLine then 6 else 2
if text:sub(1, 4) == "--[[" and text:sub(-2, -1) == "]]" then
if curserlarger then cursorCharacter -= shiftSelection else anchorCharacter -= shiftSelection end
scriptDocument:EditTextAsync(text:sub(5, -3), startLine, startCharacter, endLine, endCharacter)
else
if curserlarger then cursorCharacter += shiftSelection else anchorCharacter += shiftSelection end
scriptDocument:EditTextAsync("--[[" .. text .. "]]", startLine, startCharacter, endLine, endCharacter)
end
scriptDocument:RequestSetSelectionAsync(cursorLine, cursorCharacter, anchorLine, anchorCharacter)
end)
whats the benefit over this?
This does not require you to comment the full line plus this works with my next plugin
holy shit you're a madman thats insane lol its always so annoying to block comment
goated
Why did this happen
Actually I figured it out
If you attempt to edit a package script without permission to modify it will throw this error
what is line 22
Isn't this the code?
If I paste it then its this
RequestSetSelectionAsync
it says invalid position
maybe should print the values passed in to make sure there set
I am just using your uploaded version so
I mean issue is only because the script attempting to be modify doesn't have the ability to be
I'm guessing getselected return nil then we try to pass nil into the function
but I'm not sure I'm confused
I mean it's fine it doesn't cause any issues and works as intended, just throws this error
I think there is a editable property I might be able to check
I was trying to look for that but was looking in ScriptEditorService
And didn't see one that seemed to be correct
But I've never looked at ScriptEditorService before
maybe check the script document class