Autocompletion with indentation not working
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comience con la implementación proporcionada de TextArea_PreviewKeyDown, especialmente con document.Insert y el posicionamiento posterior del cursor. Reproduzca el comportamiento de la tecla Enter con la declaración de función mostrada y compare la indentación real del cursor con la salida solicitada; el issue no menciona ningún archivo del repositorio ni ninguna prueba que ejecutar.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I am to new avalonEdit and using it for my custom language, the lanuguage does not use { } for block instead it uses some keyword use as end. So i tried to implement feature that will automatically complete block for user and indent cursor, now the completion is working but indentation not working.
When user type in
function name()
and press enter i want to have
function name()
|
end function
instead i am getting
function name()
|
end function
| representing cursor
Below is implementation the insertion working perfectly
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Document;
public class AutocompleteHandler
{
private TextEditor editor;
private const string TriggerWord = "function";
private const string ClosingBlock = "end function";
public AutocompleteHandler(TextEditor editor)
{
this.editor = editor;
this.editor.TextArea.PreviewKeyDown += TextArea_PreviewKeyDown;
}
private void TextArea_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
int currentOffset = editor.CaretOffset;
TextDocument document = editor.Document;
// Get the current line
DocumentLine currentLine = document.GetLineByOffset(currentOffset);
int lineOffset = currentLine.Offset;
string lineText = document.GetText(currentLine);
// Check if the line contains the trigger word followed by a valid function declaration
if (IsValidFunctionDeclaration(lineText))
{
// Insert the closing block
string indentation = GetLineIndentation(lineText);
string closingBlockText = $"{indentation}{ClosingBlock}";
// Update the content of the text in the editor
document.Insert(currentOffset, $"\n\n{closingBlockText}");
// Adjust cursor position
int cursorLine = currentLine.LineNumber + 1; // Line number of the inserted closing block
int cursorColumn = indentation.Length + 4; // Cursor column position in the middle of the block
editor.TextArea.Caret.Line = cursorLine;
editor.TextArea.Caret.Column = cursorColumn;
editor.TextArea.Caret.BringCaretToView();
// Mark the event as handled
e.Handled = true;
}
}
}
private bool IsValidFunctionDeclaration(string lineText)
{
// Remove leading and trailing whitespaces
lineText = lineText.Trim();
// Check if the line starts with the trigger word "function"
if (!lineText.StartsWith(TriggerWord, StringComparison.OrdinalIgnoreCase))
return false;
// Check if the line ends with either an empty parameter list "()"
// or a parameter list with at least one character inside
return lineText.EndsWith("()") || lineText.EndsWith(")");
}
private string GetLineIndentation(string lineText)
{
int indentationLength = lineText.TakeWhile(char.IsWhiteSpace).Count();
return lineText.Substring(0, indentationLength);
}
}
- Lenguaje dominante
- C#
- Estrellas
- 2.1k
- Forks
- 496
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de icsharpcode/AvalonEdit
-
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
icsharpcode/AvalonEdit#454 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
icsharpcode/AvalonEdit#449 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 48/100
icsharpcode/AvalonEdit#446 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
icsharpcode/AvalonEdit#445 · 1 comentario ·
-
Context menu ApplicationCommands.Cut still enabled when IsReadOnly = truePosiblemente ocupada @JyslaFancy la tomó hace 162 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
icsharpcode/AvalonEdit#444 ·
Todos los issues de icsharpcode/AvalonEdit
Issues similares
-
type:task ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
elsa-workflows/elsa-foundation#5253 ·
Los mantenedores suelen responder en 1 día