Compartilhar via


O Objeto ISEEditor

Um objeto ISEEditor é uma instância da classe Microsoft.PowerShell.Host.ISE.ISEEditor. O painel do Console é um objeto ISEEditor . Cada objeto ISEFile possui um objeto ISEEditor associado. As seções a seguir listam os métodos e propriedades de um objeto ISEEditor .

Methods

Clear()

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Limpa o texto no editor.

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

EnsureVisible(int lineNumber)

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Rola o editor para que a linha correspondente ao valor especificado do parâmetro lineNumber fique visível. Ele lança uma exceção se o número de linha especificado estiver fora do intervalo de 1, último número de linha, que define os números de linha válidos.

  • Número da linha - O número da linha que deve ser tornada visível.
# Scrolls the text in the Script pane so that the fifth line is in view.
$psISE.CurrentFile.Editor.EnsureVisible(5)

Focus()

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Foca o editor no que se foca.

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

GetLineLength(int lineNumber )

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Obtém o comprimento da linha como um inteiro para a linha especificada pelo número da linha.

  • Número de linha - O número da linha cujo comprimento deve ser alcançado.
  • Retornos - O comprimento da linha na linha no número especificado.
# Gets the length of the first line in the text of the Command pane.
$psISE.CurrentPowerShellTab.ConsolePane.GetLineLength(1)

GoToMatch()

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

Move o caret para o caractere correspondente se a propriedade CanGoToMatch do objeto editor for $true, o que ocorre quando o caret está imediatamente antes de um parêntese de abertura, colchete ou colchete

  • (,[,{ - ou imediatamente após um parêntese de encerramento, colchete ou chaveiro - ),],}. O caret é colocado antes de um caractere de abertura ou após um caractere de encerramento. Se a propriedade CanGoToMatch for $false, então esse método não faz nada.
# Goes to the matching character if CanGoToMatch() is $true
$psISE.CurrentPowerShellTab.ConsolePane.GoToMatch()

InsertText( text )

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Substitui a seleção por texto ou insere texto na posição atual do caret.

  • texto - String - O texto a ser inserido.

Veja o exemplo de scripting mais adiante neste tópico.

Select( startLine, startColumn, endLine, endColumn )

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Seleciona o texto dos parâmetros startLine, startColumn, endLine e endColumn .

  • startLine - Integer - A linha onde a seleção começa.
  • startColumn - Integer - A coluna dentro da linha inicial onde a seleção começa.
  • endLine - Integer - A linha onde a seleção termina.
  • endColumn - Integer - A coluna dentro da linha final onde a seleção termina.

Veja o exemplo de scripting mais adiante neste tópico.

SelectCaretLine()

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Seleciona toda a linha de texto que atualmente contém o caret.

# 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 )

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Define a posição do caret no número da linha e no número da coluna. Ele lança uma exceção se o número da linha do caret ou o número da coluna do caret estiverem fora de seus respectivos intervalos válidos.

  • Número de linha - Integer - O número da linha do caret.
  • columnNumber - Integer - Número da coluna do caret.
# Set the CaretPosition.
$psISE.CurrentFile.Editor.SetCaretPosition(5,1)

ToggleOutliningExpansion()

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

Faz com que todas as seções do contorno se expandam ou colapsem.

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

Propriedades

CanGoToMatch

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

A propriedade booleana somente de leitura indica se o caret está ao lado de um parêntese, colchete ou colchete - (), [], {}. Se o caret estiver imediatamente antes do caractere de abertura ou imediatamente após o caractere de fechamento de um par, então esse valor de propriedade é $true. Caso contrário, é $false.

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

CaretColumn

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade somente leitura que recebe o número da coluna correspondente à posição do caret .

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

CaretLine

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade somente leitura que recebe o número da linha que contém o carète.

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

CaretLineText

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade somente leitura que recebe a linha completa de texto que contém o caret (caret).

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

LineCount

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade de somente leitura que recebe a contagem de linhas do editor.

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

SelectedText

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade de somente leitura que recebe o texto selecionado do editor.

Veja o exemplo de scripting mais adiante neste tópico.

Texto

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade de leitura/escrita que recebe ou define o texto no editor.

Veja o exemplo de scripting mais adiante neste tópico.

Exemplo de Scripting

# 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())

Consulte Também