brackethighlighter.cs
来自「全功能c#编译器」· CS 代码 · 共 100 行
CS
100 行
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using ICSharpCode.TextEditor.Document;
namespace ICSharpCode.TextEditor
{
public class Highlight
{
Point openBrace;
Point closeBrace;
public Point OpenBrace {
get {
return openBrace;
}
set {
openBrace = value;
}
}
public Point CloseBrace {
get {
return closeBrace;
}
set {
closeBrace = value;
}
}
public Highlight(Point openBrace, Point closeBrace)
{
this.openBrace = openBrace;
this.closeBrace = closeBrace;
}
}
public class BracketHighlightingSheme
{
char opentag;
char closingtag;
public char OpenTag {
get {
return opentag;
}
set {
opentag = value;
}
}
public char ClosingTag {
get {
return closingtag;
}
set {
closingtag = value;
}
}
public BracketHighlightingSheme(char opentag, char closingtag)
{
this.opentag = opentag;
this.closingtag = closingtag;
}
public Highlight GetHighlight(IDocument document, int offset)
{
char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, offset)));
Point endP = document.OffsetToPosition(offset);
if (word == opentag) {
if (offset < document.TextLength) {
int bracketOffset = TextUtilities.SearchBracketForward(document, offset + 1, opentag, closingtag);
if (bracketOffset >= 0) {
Point p = document.OffsetToPosition(bracketOffset);
return new Highlight(p, endP);
}
}
} else if (word == closingtag) {
if (offset > 0) {
int bracketOffset = TextUtilities.SearchBracketBackward(document, offset - 1, opentag, closingtag);
if (bracketOffset >= 0) {
Point p = document.OffsetToPosition(bracketOffset);
return new Highlight(p, endP);
}
}
}
return null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?