Plugin API for editor

It’s currently basically impossible to create plugins that interact with the script editor. The most we can do now is listen for changing .Source (using .Changed or game.ItemChanged) in case of embedded scripts. Changing the .Source of an open script will reset the mouse cursor to the beginning of the script, though.

It’d be nice if we could have an API like this:

Additions/modifications to the Plugin class:
	Function void Plugin:OpenScript(Instance script, int lineNumber = 1, int rowNumber = 1) [PluginSecurity]
		(This already exists, but without the rowNumber parameter)
	Function Objects Plugin:GetEditors() [PluginSecurity]
	Property Editor Plugin.FocusedEditor [PluginSecurity]
	Event Plugin.EditorOpened(Editor editor) [PluginSecurity]
	Event Plugin.EditorClosed(Editor editor) [PluginSecurity]
	
Class Editor : Instance
	Function void Editor:Close() [PluginSecurity]
		(Not sure if this is necessary and/or wanted)
	Event Editor.Closed() [PluginSecurity]
		(Not really necessary due to Plugin.EditorClosed)
Class ScriptEditor : Editor
	Property LuaSourceContainer Editor.Script
		The (Module/Local)Script that this editor has opened
		(nil in case it's not an embedded script)
	Property string Editor.LinkedSource
		The LinkedSource that this editor has opened
		("" in case it's not a LinkedSource)
	Property int Editor.CursorPosition
		(Notice how it isn't readonly)
	Property string Editor.Source
		(Notice how this also isn't readonly)
	Event Editor.InputBegan(Instance input, bool studioProcessedEvent)
	Event Editor.InputChanged(Instance input, bool studioProcessedEvent)
	Event Editor.InputEnded(Instance input, bool studioProcessedEvent)

Notes

  • I’ve added the new methods/events to the Plugin class
    Might make more sense if it gets its own service (e.g. EditorService)
    or if it got added to the Studio class (not in API dump because it’s a studio-only class)
    Just added them to Plugin because Plugin:OpenScript() already exists
    (nothing stops Roblox from deprecating that function though)
  • ScriptEditor.CursorPosition and ScriptEditor.Source could be made readonly with setter methods added in case there’s an issue with multithreading with the UI or so
  • I’ve added that Editor superclass, as maybe there’ll be other kind of editors (who knows?)
  • [EDIT] As As8D mentioned, like CursorPosition, selection ranges, highlights, … would be nice too

With an API like this, plugins would be able to really enhance the script editor. Examples would be (live) formatting scripts, displaying documentation (gamewindow GUIs) when the cursor is after a certain word, macros using the InputBegan/Changed/Ended events, …

I don’t expect this to be added anytime soon, but it would lead to some nice plugins.

17 Likes

Might be worth noting that besides just the CursorPosition, there’s also to take care of i.e. selection ranges, highlights and other nifty stuff.

3 Likes

This would also be great for freaks like me who like to precompile their code, support. :yum:

1 Like

This is kinda like sliced bread.
Or Reese’s Cups.
Or anything else that’s amazing and the best

2 Likes

Reece’s cups have wayyy to much sugar.

I tried eating one once, it killed my throat, and I had to have a big long drink of water afterwards. Didn’t touch them again.

p.s. yeah i like feature

1 Like

Pretty sure you might have just had a bad one - Reece’s cups are the best thing that ever happened to this planet. Aside from roblox of course :wink:

As for the thread, support. :slight_smile:

Nah you Americans just eat too much sugar :wink:

I’ve had some different variants of the Reece’s brand, had about the same rough level sweetness.

Just look at their packaging and see how many teaspoons of sugar there are.

Happy Bday, I got you a giant Reece’s cup for your birthday. :stuck_out_tongue:

Nonetheless they’re still the best thing that ever happened :smiley:

1 Like

Screams in terror and runs away

2 Likes