An ISEEditor object is an instance of the Microsoft.PowerShell.Host.ISE.ISEEditor class. The Output Pane and the Command Pane editors are ISEEditor objects. Each ISEFile object has an associated ISEEditor object. The following sections list the methods and properties of an ISEEditor object.
Methods
Clear()
Clears the text in the editor.fre
# Clears the text in the Output pane. $psIse.CurrentPowerShellTab.Output.Clear()
EnsureVisible(int lineNumber)
Scrolls the editor so that the line corresponding to specified lineNumber is visible. It throws an exception if the specified lineNumber is outside the interval (1,last line number) which defines the range of valid line numbers.
- lineNumber
- Number of the line that is to be made visible.
# Scrolls the text in the Script Pane so that the fifth line is in view. $psIse.CurrentFile.Editor.EnsureVisible(5)
Focus()
Sets the focus to the editor.
# Sets focus to the Output pane. $psISE.CurrentPowerShellTab.Output.Focus()
GetLineLength(int lineNumber)
Gets the integer line length for the line specified by lineNumber.
- lineNumber
- Number of the line to get the length of.
- Returns
- The line length for the line at lineNumber.
# Gets the length of the first line in the text of the Command pane. $psIse.CurrentPowerShellTab.CommandPane.GetLineLength(1)
InsertText(string text)
Replaces the selection with text or inserts text at the current caret position.
- text
- Text to insert.
See the Scripting Example later in this topic.
Select(int startLine, int startColumn, int endLine, int endColumn)
Selects the text from startLine, startColumn to endLine, endColumn.
- startLine
- Line where the selection starts.
- startColumn
- Column within startLine where the selection starts.
- endLine
- Line where the selection ends.
- endColumn
- Column within endLine where the selection ends.
See the Scripting Example later in this topic.
SetCaretPosition(int lineNumber, int columnNumber)
Sets the caret position at lineNumber and columnNumber. It throws an exception if either the lineNumber or the columnNumber are out of their respective valid ranges.
- lineNumber
- Caret line number.
- columnNumber
- Caret column number.
# Set the CaretPosition. $firstfile=$psIse.CurrentFile $firstFile.Editor.SetCaretPosition(5,1)
Properties
CaretColumn
Read-only property that gets the column number corresponding to the position of the caret.
# Get the CaretColumn. $firstfile=$psIse.CurrentFile $firstFile.Editor.CaretColumn
CaretLine
Read-only property that gets the number of the line that contains the caret.
# Get the CaretLine. $firstfile=$psIse.CurrentFile $firstFile.Editor.CaretLine
LineCount
Read-only property that gets the line count for the editor.
# Get the LineCount. $firstfile=$psIse.CurrentFile $firstFile.Editor.LineCount
SelectedText
Read-only property that gets the selected text from the editor.
See the Scripting Example later in this topic.
Text
Read/write property that gets the text in the editor.
See the Scripting Example later in this topic.
Scripting Example
# This illustrates how you can use the length of a line to select the entire line and shows how you can make it lowercase. $myfile=$psIse.CurrentFile # Start with clearing the text in the current file editor. $myfile.Editor.Clear() # Make sure the file has at least two lines of text. $myfile.Editor.InsertText("LINE1 `n") $myfile.Editor.InsertText("LINE2 `n") $myfile.Editor.InsertText("LINE3 `n") $myfile.Editor.InsertText("LINE4 `n") $myfile.Editor.InsertText("LINE5 `n") # You can use the GetLineLength method to get the length of the third line. $endColumn= $myfile.Editor.GetLineLength(3) # Select the text in the first three lines. $myfile.Editor.Select(1,1,3,$endColumn + 1) $selection = $myfile.Editor.SelectedText # Clear all the text in the editor. $myfile.Editor.Clear() # Add the selected text back, but in lower case. $myFile.Editor.InsertText($selection.ToLower())
See Also