Autocompletion with indentation not working
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với phần triển khai TextArea_PreviewKeyDown được cung cấp, đặc biệt là document.Insert và việc định vị caret sau đó. Tái hiện hành vi của phím Enter bằng khai báo hàm được hiển thị và so sánh mức thụt lề thực tế của con trỏ với đầu ra được yêu cầu; issue không nêu tệp nào trong repository hoặc test nào cần chạy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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);
}
}
- Ngôn ngữ chính
- C#
- Star
- 2.1k
- Fork
- 496
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của icsharpcode/AvalonEdit
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
icsharpcode/AvalonEdit#454 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
icsharpcode/AvalonEdit#449 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
icsharpcode/AvalonEdit#446 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
icsharpcode/AvalonEdit#445 · 1 bình luận ·
-
Context menu ApplicationCommands.Cut still enabled when IsReadOnly = trueCó thể đã có người làm @JyslaFancy đã nhận 162 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
icsharpcode/AvalonEdit#444 ·
Tất cả issue của icsharpcode/AvalonEdit
Issue tương tự
-
type:task ux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
elsa-workflows/elsa-foundation#5253 ·
Maintainer thường phản hồi trong vòng 1 ngày