#Toggle Block Comment

1 messages · Page 1 of 1 (latest)

west mortar
#
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)
harsh marsh
#

whats the benefit over this?

west mortar
glossy sonnet
#

How would I make it multi-lined?

#

I was thinking of variables

quasi halo
#

goated

toxic estuary
#

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

west mortar
toxic estuary
#

If I paste it then its this

#

RequestSetSelectionAsync

west mortar
#

it says invalid position

#

maybe should print the values passed in to make sure there set

toxic estuary
#

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

west mortar
#

I'm guessing getselected return nil then we try to pass nil into the function

#

but I'm not sure I'm confused

toxic estuary
#

I mean it's fine it doesn't cause any issues and works as intended, just throws this error

west mortar
#

I think there is a editable property I might be able to check

toxic estuary
#

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

west mortar
#

maybe check the script document class

toxic estuary
#

Doesn't seem like there is

west mortar
#

humm

#

if I remember I'll take a look at it