Partilhar via


Objeto ISEEditor

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

Métodos

Clear()

Suportado no Windows PowerShell ISE 2.0 e posterior.

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 posterior.

Rola o editor para que a linha que corresponde ao valor do parâmetro lineNumber especificado 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.

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

Em foco()

Suportado no Windows PowerShell ISE 2.0 e posterior.

Define o foco para o editor.

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

GetLineLength(int lineNumber )

Suportado no Windows PowerShell ISE 2.0 e posterior.

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

lineNumber O número da linha da qual obter o comprimento.

Devolve O comprimento da linha no número de linha especificado.

# Gets the length of the first line in the text of the Command pane.
$psISE.CurrentPowerShellTab.ConsolePane.GetLineLength(1)

GoToMatch()

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

Move o cursor para o caractere correspondente se a propriedade CanGoToMatch do objeto editor for $true, o que ocorre quando o cursor está imediatamente antes de um parêntese de abertura, colchete ou chave - (,[,{ - ou imediatamente após um parêntese de fechamento, colchete ou chave - ),],}. O cursor é colocado antes de um caractere de abertura ou depois de um caractere de fechamento. Se a propriedade CanGoToMatch for $false, esse método não fará nada.

# Goes to the matching character if CanGoToMatch() is $true
$psISE.CurrentPowerShellTab.ConsolePane.GoToMatch()

InsertText( texto )

Suportado no Windows PowerShell ISE 2.0 e posterior.

Substitui a seleção por texto ou insere texto na posição de cursor atual.

text - String O texto a ser inserido.

Consulte o exemplo de script mais adiante neste tópico.

Selecionar( startLine, startColumn, endLine, endColumn )

Suportado no Windows PowerShell ISE 2.0 e posterior.

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.

Consulte o exemplo de script mais adiante neste tópico.

SelectCaretLine()

Suportado no Windows PowerShell ISE 2.0 e posterior.

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

# 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 posterior.

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

lineNumber - Integer O número da linha de acento circunflexo.

columnNumber - Integer O número da coluna do cursor.

# Set the CaretPosition.
$psISE.CurrentFile.Editor.SetCaretPosition(5,1)

ToggleOutliningExpansion()

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

Faz com que todas as seções de estrutura de tópicos sejam expandidas ou recolhidas.

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

Propriedades

CanGoToMatch

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

A propriedade Boolean somente leitura para indicar se o cursor está ao lado de um parêntese, colchete ou chave - (), [], {}. Se o cursor for imediatamente antes do caractere de abertura ou imediatamente após o caractere de fechamento de um par, esse valor de propriedade será $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 posterior.

A propriedade somente leitura que obtém o número da coluna que corresponde à posição do cursor.

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

CaretLine

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade somente leitura que obtém o número da linha que contém o cursor.

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

CaretLineText

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade somente leitura que obtém a linha completa de texto que contém o curso.

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

Contagem de linhas

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade somente leitura que obtém a contagem de linhas do editor.

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

SelectedText

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade somente leitura que obtém o texto selecionado do editor.

Consulte o exemplo de script mais adiante neste tópico.

Texto

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade read/write que obtém ou define o texto no editor.

Consulte o exemplo de script mais adiante neste tópico.

Exemplo de script

# 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