ISEEditor 物件是 Microsoft.PowerShell.Host.ISE.ISEEditor 類別的執行個體。[輸出] 窗格和 [命令] 窗格編輯器都是 ISEEditor 物件。每個 ISEFile 物件都有關聯的 ISEEditor 物件。下列各節列出 ISEEditor 物件的方法與屬性。
方法
Clear()
清除 editor.fre 中的文字。
# Clears the text in the Output pane. $psIse.CurrentPowerShellTab.Output.Clear()
EnsureVisible(int lineNumber)
捲動編輯器,讓與指定的 lineNumber 對應的行顯示出來。如果指定的 lineNumber 不在有效行數範圍的定義區間 (1, 最後一個行號) 內,這個方法會擲回例外狀況。
- lineNumber
- 要顯示出來的行號。
# Scrolls the text in the Script Pane so that the fifth line is in view. $psIse.CurrentFile.Editor.EnsureVisible(5)
Focus()
將焦點設定在編輯器上。
# Sets focus to the Output pane. $psISE.CurrentPowerShellTab.Output.Focus()
GetLineLength(int lineNumber)
取得 lineNumber 所指定之行的整數行長度。
- lineNumber
- 要取得長度的行。
- 傳回值
- 位於 lineNumber 之行的行長度。
# Gets the length of the first line in the text of the Command pane. $psIse.CurrentPowerShellTab.CommandPane.GetLineLength(1)
InsertText(string text)
以文字取代選取範圍,或在目前的插入號位置插入文字。
- text
- 要插入的文字。
請參閱本主題後面的Scripting Example。
Select(int startLine, int startColumn, int endLine, int endColumn)
選取從 startLine startColumn 到 endLine endColumn 的文字。
- startLine
- 選取範圍起始處的行。
- startColumn
- 選取範圍起始處的 startLine 內的欄。
- endLine
- 選取範圍終止處的行。
- endColumn
- 選取範圍終止處的 endLine 內的欄。
請參閱本主題後面的Scripting Example。
SetCaretPosition(int lineNumber, int columnNumber)
將插入號位置設定在 lineNumber columnNumber。如果 lineNumber 或 columnNumber 超出各自的有效範圍,這個方法會擲回例外狀況。
- lineNumber
- 插入號行號。
- columnNumber
- 插入號欄號。
# Set the CaretPosition. $firstfile=$psIse.CurrentFile $firstFile.Editor.SetCaretPosition(5,1)
屬性
CaretColumn
唯讀屬性,取得與插入號位置對應的欄號。
# Get the CaretColumn. $firstfile=$psIse.CurrentFile $firstFile.Editor.CaretColumn
CaretLine
唯讀屬性,取得含插入號的行號。
# Get the CaretLine. $firstfile=$psIse.CurrentFile $firstFile.Editor.CaretLine
LineCount
唯讀屬性,取得編輯器中的行數。
# Get the LineCount. $firstfile=$psIse.CurrentFile $firstFile.Editor.LineCount
SelectedText
唯讀屬性,取得編輯器中的所選文字。
請參閱本主題後面的Scripting Example。
Text
讀/寫屬性,取得編輯器中的文字。
請參閱本主題後面的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())
請參閱