AvalonEdit을 사용하여 사용자 지정 하이퍼 링크를 만들려고합니다. 나는 구문을 인식 (샘플 기준) 발전기를 만들었습니다와 나는 열린 우리당을 설정할 수 있습니다AvalonEdit을 사용한 사용자 지정 하이퍼 링크
- :
public class LinkGenerator : VisualLineElementGenerator { readonly static Regex imageRegex = new Regex(@"<mylink>", RegexOptions.IgnoreCase); public LinkGenerator() {} Match FindMatch(int startOffset) { // fetch the end offset of the VisualLine being generated int endOffset = CurrentContext.VisualLine.LastDocumentLine.EndOffset; TextDocument document = CurrentContext.Document; string relevantText = document.GetText(startOffset, endOffset - startOffset); return imageRegex.Match(relevantText); } /// Gets the first offset >= startOffset where the generator wants to construct /// an element. /// Return -1 to signal no interest. public override int GetFirstInterestedOffset(int startOffset) { Match m = FindMatch(startOffset); return m.Success ? (startOffset + m.Index) : -1; } /// Constructs an element at the specified offset. /// May return null if no element should be constructed. public override VisualLineElement ConstructElement(int offset) { Match m = FindMatch(offset); // check whether there's a match exactly at offset if (m.Success && m.Index == 0) { var line = new VisualLineLinkText(CurrentContext.VisualLine, m.Length); line.NavigateUri = new Uri("http://google.com"); return line; } return null; } }
그러나 내가 알아낼 수없는 것 두 가지 문제가 있습니다
"MyLink"라고 말하는 텍스트를 단순화하기 위해 VisualLineLinkText 생성자로 전달할 대상은 무엇입니까?
클릭 동작을 재정의 할 수 있도록 RequestNavigateEventArgs를받을 이벤트 핸들러를 어디에 두어야합니까?
"Jump To Definition"스타일의 네비게이션은 정확하게 달성하려고 노력하고 있습니다. VisualLineText 사용시 "일치"가 발생하는 곳을 알 수 없습니다. 어떻게하면 하이라이팅 엔진에 연결할 수 있습니까? – themightylc
위의 의견을 무시하십시오. 구문 강조 CreateInstance Sub에서 발생합니다. – themightylc