Skip to content

ScriptDocument

Not yet Class Scripting & Networking NotCreatable NotReplicated

Represents the ephemeral state of an open document in the Studio Script Editor, providing APIs for reading and editing code.

Not implemented yet

This class exists in the current Roblox API but is not implemented in Nova yet. Scripts that reference it will fail at runtime.

0 Nova members · 26 modern Roblox members not implemented yet

Description

A ScriptDocument instance is a proxy of the document of a Studio Script Editor. It's different from the LuaSourceContainer open in the editor in that it represents the ephemeral state of an open document, and its representation is in a format that's more suited for reading and editing code than executing it. In particular, ScriptDocument reflects any changes that have been made to the open script in Drafts Mode, which the source property doesn't.

The Script Editor itself exists and changes on a different thread than any DataModel, so the ScriptDocument replicates the open Script Editor, but it isn't the open editor. Because of the replication, there's sometimes a slight delay between changing the text in the editor and updating the ScriptDocument. The delay usually occurs because the DataModel is busy, and it's almost always extremely small, but it still exists.

The existence of a ScriptDocument indicates that a document is open in the Script Editor. All ScriptDocument instances have ScriptEditorService as its parent. Each instance adheres to the following encoding conventions:

  • All text in ScriptDocument is UTF-8 encoded.
  • All line indices are 1-indexed.
  • All character indices are 1-indexed and count UTF-8 bytes, not graphemes, so the same warning from TextBox.CursorPosition applies: many Unicode characters take more than one byte.
  • All ranges are inclusive of their start position and exclusive of their end position, so start == end implies an empty range.

All APIs for ScriptDocument are at Plugin level security.

Inheritance

Object → Instance → ScriptDocument

Methods

Member Signature Summary
CloseAsync ScriptDocument:CloseAsync(): Tuple Requests that the editor associated with this document close. Yields the current thread until the editor responds to the request.
EditTextAsync ScriptDocument:EditTextAsync(newText: string, startLine: int, startCharacter: int, endLine: int, endCharacter: int): Tuple Replaces the text in the specified range from (startLine, startColumn) to (endLine, endColumn) with newText.
ForceSetSelectionAsync ScriptDocument:ForceSetSelectionAsync(cursorLine: int, cursorCharacter: int, anchorLine: int? = nil, anchorCharacter: int? = nil): Tuple Asks the editor to set its cursor selection to the argument values.
GetInternalUri ScriptDocument:GetInternalUri(): string —
GetLine ScriptDocument:GetLine(lineIndex: int? = nil): string Returns the text of the specified line. When no argument is provided, returns the line of the current cursor position.
GetLineCount ScriptDocument:GetLineCount(): int Returns the number of lines in the document.
GetScript ScriptDocument:GetScript(): LuaSourceContainer Returns the underlying LuaSourceContainer instance, if one exists, otherwise nil.
GetSelectedText ScriptDocument:GetSelectedText(): string Gets the text selected in the editor, or an empty string if there is no selection.
GetSelection ScriptDocument:GetSelection(): Tuple Returns the last known selection of the Script Editor in the format: CursorLine, CursorChar, AnchorLine, AnchorChar. If the Script Editor has no selection, `CursorLine…
GetSelectionEnd ScriptDocument:GetSelectionEnd(): Tuple Gets the larger of the cursor position and anchor. If the editor has no selection, they are the same value.
GetSelectionStart ScriptDocument:GetSelectionStart(): Tuple Gets the smaller of the cursor position and anchor. If the editor has no selection, they are the same value.
GetText ScriptDocument:GetText(startLine: int? = nil, startCharacter: int? = nil, endLine: int? = nil, endCharacter: int? = nil): string Returns text from the open editor.
GetViewport ScriptDocument:GetViewport(): Tuple Returns the currently displayed line numbers in the editor change.
HasSelectedText ScriptDocument:HasSelectedText(): bool Returns whether or not the editor has any text selected.
IsCommandBar ScriptDocument:IsCommandBar(): bool Returns true if the ScriptDocument represents the Command bar.
MultiEditTextAsync ScriptDocument:MultiEditTextAsync(edits: Array): Tuple Applies a batch of text edits to the document as a single atomic operation. Yields the current thread until the editor responds.
RequestSetSelectionAsync ScriptDocument:RequestSetSelectionAsync(cursorLine: int, cursorCharacter: int, anchorLine: int? = nil, anchorCharacter: int? = nil): Tuple Asks the editor to set its cursor selection to the argument values.
ReviewableTextEditsAsync ScriptDocument:ReviewableTextEditsAsync(changes: Array): Tuple Applies a batch of line-based text edits that appear in the editor as reviewable inline diffs, allowing users to accept or reject each change.

Events

Member Signature Summary
SelectionChanged SelectionChanged(positionLine: int64, positionCharacter: int64, anchorLine: int64, anchorCharacter: int64) Fires when the ScriptDocument changes, including immediately after a text change.
ViewportChanged ViewportChanged(startLine: int64, endLine: int64) Fires when the displayed line numbers in the editor change.

Roblox reference: ScriptDocument

Generated from Nova's API dump and Roblox creator-docs. Nova-only members come from the engine's reflection metadata.