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.