Is it possible to tell the line Im editing on?

So I am making a plugin that edits code in a script, the annoying part is that once I change the code, you go to either editing the first line, or second line, is there a way to change it? Along with get the line you were editing last?

You can use ScriptDocument:GetSelection() and ScriptDocument:ForceSetSelectionAsync().
It’ll return the start and end of the selected characters/lines.

3 Likes

So, :GetSelection() returns a lot of values, I couldnt figure out what all of them do, as the documentation doesnt go much in depth, so what are they? Otherwise, thanks so much lol

Yea, most of the API documentation on useful plugin stuff is vague or just has terrible examples.
Such as :GetSelection().
CursorLine is the current line the start of the selection is on, and the CursorChar is the character the cursor is starting at.
Take this example:
3
It’d return (12, 3, 12, 3) as the cursor is at the 12th line and 3rd character.
But this one would return (12, 3, 13, 3)
13 3
AnchorLine and AnchorChar is the end of the selection. In the first example there was no selection so the values were the same, but in the 2ed example there was a selection so the values are different.
The variable names they used here are fairly bad xd.

1 Like

Last question, does it return the values as a table? Or as individual values? Like this:

local Val1,Val2,Val3,Val4 = Document:GetSelection()

Or again, does it just return a table?

It returns as values. (why did roblox have to require atleast 30+ characters) :sob:

1 Like

Ok thanks :]

Also on the subject, any way to get the currently open document? I checked the ScriptEditorService documents but I couldnt figure it out

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.