Toggle Block Comment Plugin

Toggle Block Comment

Download | Discord Server

Toggle Block Comment

About

A simple plugin that allows you to quickly toggle comments around the text you have selected with a keyboard shortcut

Support My Work

If you liked my work and want to donate to me you can do so here


Source Code

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)

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.


Other Projects

Infinite Terrain
Suphi’s DataStore Module
Infinite Scripter
Mesh Editor
Toggle Block Comment
Toggle Decomposition Geometry
Tag Explorer
Suphi’s Linked List Module
Suphi’s Hybrid Linked List Module
Suphi’s RemoteFunction Module

8 Likes

As someone who likes to make parts of code and what not stop running, commenting out every line which is what I used to do is kinda a pain, now with this, well hopefully my work flow can increase, thanks for another wonderful resource!

Wow! this is actually a really useful plugin, especially with me who has a big habit of commenting out code to test if its causing errors.
Will definitely be using!

There’s a feature in studio like that already. Also with short cuts

Really? What are the shortcuts?

I don’t know, I am not at home at the moment, but I think it’s was smt like shift + /.
But you can see that in studio

1 Like

it is ctrl + /

30 :coefficients: limit

I like the commenting code into boxes like shown here

However since Ctrl + / exists and right click and toggle comment I don’t seem to find the reason to use it.


image

I’m assuming you can change the keybind for toggling comments or atleast set a separate one for ease of use, also it’s just more organized to use the comment boxes instead for multiple lines of code (atleast in my opinion)

Yeah I agree with you, It looks way cleaner but at the end of the day its faster to just use the built in toggle comment function. Rather than installing a whole new plugin that does pretty much the same but in a slightly different way.

2 Likes

Yeahh thats pretty true, but the cleaner the code the better :coefficients: