ISEEditor 物件
ISEEditor 物件是 Microsoft.PowerShell.Host.ISE.ISEEditor 類別的實例。 控制檯窗格是 ISEEditor 物件。 每個 ISEFile 物件都有一個相關聯的 ISEEditor 物件。 下列各節列出 ISEEditor 物件的方法和屬性。
方法
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,最後一行號的範圍,則會擲回例外狀況,這會定義有效的行號。
lineNumber 要顯示的行號。
# 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 和更新版本支援。
取得行號所指定行的整數行長度。
lineNumber 要取得長度的行號。
傳回 指定行號之行的行長度。
# 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(文字 )
Windows PowerShell ISE 2.0 和更新版本支援。
以文字取代選取範圍,或在目前插入號位置插入文字。
文字 - 字串 要插入的文字。
請參閱本主題稍後的 腳本範例。
Select( startLine, startColumn, endLine, endColumn )
Windows PowerShell ISE 2.0 和更新版本支援。
從 startLine、startColumn、endLine及 endColumn 參數中選取文字。
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
CaretColumn
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
CaretLineText
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())
另請參閱
- ISEFile 物件
- PowerShellTab 物件
- Windows PowerShell ISE 腳本物件模型的 用途
- ISE 物件模型階層