Autocompletion with indentation not working
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Iniziare con l’implementazione fornita di TextArea_PreviewKeyDown, in particolare document.Insert e il successivo posizionamento del caret. Riprodurre il comportamento del tasto Invio con la dichiarazione della funzione mostrata e confrontare l’indentazione effettiva del cursore con l’output richiesto; l’issue non indica alcun file del repository né alcun test da eseguire.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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);
}
}
- Lingua principale
- C#
- Stelle
- 2.1k
- Fork
- 496
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di icsharpcode/AvalonEdit
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
icsharpcode/AvalonEdit#454 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
icsharpcode/AvalonEdit#449 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
icsharpcode/AvalonEdit#446 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 28/100
icsharpcode/AvalonEdit#445 · 1 commento ·
-
Context menu ApplicationCommands.Cut still enabled when IsReadOnly = trueForse già presa @JyslaFancy l’ha presa 162 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
icsharpcode/AvalonEdit#444 ·
Tutte le issue di icsharpcode/AvalonEdit
Issue simili
-
type:task ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
elsa-workflows/elsa-foundation#5253 ·
I maintainer di solito rispondono entro 1 giorno