ISEEditor对象

ISEEditor 对象是 Microsoft.PowerShell.Host.ISE.ISEEditor 类的一个实例。 控制台面板是一个 ISEEditor 对象。 每个 ISEFile 对象都有一个关联的 ISEEditor 对象。 以下章节列出 了ISEEditor 对象的方法和属性。

Methods

Clear()

支持Windows PowerShell ISE 2.0及更高版本。

在编辑器中清除文本。

# Clears the text in the Console pane.
$psISE.CurrentPowerShellTab.ConsolePane.Clear()

EnsureVisible(int lineNumber)

支持Windows PowerShell ISE 2.0及更高版本。

滚动编辑器,使得对应指定 lineNumber 参数值的行显示出来。 如果指定的行号超出定义有效行号的1,最后一个行号范围,它会抛出异常。

  • 线号 - 将要显示的行号。
# Scrolls the text in the Script pane so that the fifth line is in view.
$psISE.CurrentFile.Editor.EnsureVisible(5)

Focus()

支持Windows PowerShell ISE 2.0及更高版本。

将焦点设定在编辑器身上。

# Sets focus to the Console pane.
$psISE.CurrentPowerShellTab.ConsolePane.Focus()

GetLineLength(int lineNumber )

支持Windows PowerShell ISE 2.0及更高版本。

获得由行号指定的行的整数行长。

  • 线数 - 要获得长度的线的编号。
  • 返回 ——指定行号处行的行长。
# Gets the length of the first line in the text of the Command pane.
$psISE.CurrentPowerShellTab.ConsolePane.GetLineLength(1)

GoToMatch()

Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。

如果编辑对象的 CanGoToMatch 属性为 $true,当插入符紧邻开头括号、括号或大括号时,插入点将插入符移动到匹配字符

  • ([{ - 或紧接在括号、括号或大括号之后 - ),,]} 插入符置于开头字符之前或闭尾字符之后。 如果 CanGoToMatch 属性为 $false,则该方法不做任何事。
# Goes to the matching character if CanGoToMatch() is $true
$psISE.CurrentPowerShellTab.ConsolePane.GoToMatch()

InsertText( text )

支持Windows PowerShell ISE 2.0及更高版本。

用文本替换选区,或在当前插入槽位置插入文本。

  • text - 字符串 - 要插入的文本。

请参见本主题后面的 脚本示例

Select( startLine, startColumn, endLine, endColumn )

支持Windows PowerShell ISE 2.0及更高版本。

startLinestartColumnendLineendColumn 参数中选择文本。

  • startLine - 整数 - 选择开始的线。
  • startColumn - 整数 - 起始行中选择开始的列。
  • endLine - 整数 - 选择结束的行。
  • endColumn - 整数 - 选择结束的末行内的列。

请参见本主题后面的 脚本示例

SelectCaretLine()

支持Windows PowerShell ISE 2.0及更高版本。

选择当前包含插入符的整行文本。

# First, set the caret position on line 5.
$psISE.CurrentFile.Editor.SetCaretPosition(5,1)
# Now select that entire line of text
$psISE.CurrentFile.Editor.SelectCaretLine()

SetCaretPosition( lineNumber, columnNumber )

支持Windows PowerShell ISE 2.0及更高版本。

在行号和列号处设置插入点位置。 如果插入点行号或插入点列号超出各自有效范围,则会抛出异常。

  • lineNumber - 整数 - 插入点的行号。
  • columnNumber - 整数 - 插入点列号。
# Set the CaretPosition.
$psISE.CurrentFile.Editor.SetCaretPosition(5,1)

ToggleOutliningExpansion()

Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。

会导致所有轮廓部分膨胀或塌陷。

# Toggle the outlining expansion
$psISE.CurrentFile.Editor.ToggleOutliningExpansion()

属性

CanGoToMatch

Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。

仅读布尔属性用于表示圆圈旁边是括号、括号还是括号 - ()[]{}。 如果插入点紧邻开始字符或紧接于结尾字符,则该性质值为 $true。 否则为 $false

# Test to see if the caret is next to a parenthesis, bracket, or brace
$psISE.CurrentFile.Editor.CanGoToMatch

卡雷特栏

支持Windows PowerShell ISE 2.0及更高版本。

只读属性,获得对应圆滑点位置的列号。

# Get the CaretColumn.
$psISE.CurrentFile.Editor.CaretColumn

CaretLine

支持Windows PowerShell ISE 2.0及更高版本。

只读属性,获得包含插入点的行号。

# Get the CaretLine.
$psISE.CurrentFile.Editor.CaretLine

CaretLine正文

支持Windows PowerShell ISE 2.0及更高版本。

只读属性,获取包含插入符号的完整文本行。

# Get all of the text on the line that contains the caret.
$psISE.CurrentFile.Editor.CaretLineText

LineCount

支持Windows PowerShell ISE 2.0及更高版本。

只读属性,从编辑器获取行数。

# Get the LineCount.
$psISE.CurrentFile.Editor.LineCount

SelectedText

支持Windows PowerShell ISE 2.0及更高版本。

只读属性,从编辑器获取选定文本。

请参见本主题后面的 脚本示例

文本

支持Windows PowerShell ISE 2.0及更高版本。

就是在编辑器中获取或设置文本的读写属性。

请参见本主题后面的 脚本示例

脚本示例

# This illustrates how you can use the length of a line to
# select the entire line and shows how you can make it lowercase.
# You must run this in the Console pane. It will not run in the Script pane.
# Begin by getting a variable that points to the editor.
$myEditor = $psISE.CurrentFile.Editor
# Clear the text in the current file editor.
$myEditor.Clear()

# Make sure the file has five lines of text.
$myEditor.InsertText("LINE1 `n")
$myEditor.InsertText("LINE2 `n")
$myEditor.InsertText("LINE3 `n")
$myEditor.InsertText("LINE4 `n")
$myEditor.InsertText("LINE5 `n")

# Use the GetLineLength method to get the length of the third line.
$endColumn = $myEditor.GetLineLength(3)
# Select the text in the first three lines.
$myEditor.Select(1, 1, 3, $endColumn + 1)
$selection = $myEditor.SelectedText
# Clear all the text in the editor.
$myEditor.Clear()
# Add the selected text back, but in lower case.
$myEditor.InsertText($selection.ToLower())

另请参阅