CodeHighlighter
Configurable lexical highlighting for keywords, numbers, calls and colored regions.
CodeHighlighter is a ready lexical implementation for TextEdit rather than a C# compiler or semantic analyzer. Assign a separate instance to each editor, configure token colors, then add keywords and comment/string regions. No complete language rule set is loaded automatically.
KeywordColors and MemberKeywordColors map exact case-sensitive words to Color. MemberKeywordColors applies to unqualified words; a word after a dot uses MemberVariableColor. Important limitation: opaque black with alpha 1 is the unset-color marker in keyword tables and is not applied even when HasKeywordColor returns true. Use a custom SyntaxHighlighter for that exact color.
Keyword tables are shared with supplied dictionaries and getter results. In-place edits do not invalidate the cache; ClearKeywordColors also clears the caller’s shared table. Prefer Add/Remove methods or separately prepared tables. Call EmitChanged after changing rules; after mutating a shared table, call ClearHighlightingCache before EmitChanged.
AddColorRegion defines literal opening/closing symbols. An empty closer always makes a region line-only; lineOnly true does so even with a closer. Longer openers are checked before shorter ones. ColorRegions uses "opener closer" keys but does not preserve lineOnly: reading and reassigning the table can turn a line-only region into a multiline region. Use AddColorRegion for exact configuration.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
CodeHighlighterConstructor
public CodeHighlighter();Creates a lexical highlighter with empty keyword and region tables. Attach an editor and configure a palette; not a complete syntax configuration for a particular language.
Properties7
ColorRegionsProperty
public Reckfell.Collections.Dictionary ColorRegions { get; set; }Snapshot Dictionary of regions: keys are "opener closer", or only "opener" for a line-only region; values are Color. Assignment replaces regions without sharing the container. Does not encode explicit lineOnly with a nonempty closer; use AddColorRegion for that.
FunctionColorProperty
public Color FunctionColor { get; set; }Lexical color for names before an opening call parenthesis. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
KeywordColorsProperty
public Reckfell.Collections.Dictionary KeywordColors { get; set; }Shared Dictionary mapping exact words to Color. Assignment replaces the table and clears the resource cache. In-place changes to the shared dictionary do not clear the cache. Opaque black with alpha 1 is not applied as a keyword color. Use EmitChanged to refresh the editor.
MemberKeywordColorsProperty
public Reckfell.Collections.Dictionary MemberKeywordColors { get; set; }Shared Dictionary for unqualified member-word colors. A word after a dot does not use this rule; MemberVariableColor applies. Assignment clears the resource cache, but in-place shared-table changes do not. Opaque black with alpha 1 is treated as unset.
MemberVariableColorProperty
public Color MemberVariableColor { get; set; }Lexical color for words after a dot. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
NumberColorProperty
public Color NumberColor { get; set; }Lexical color for numbers. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
SymbolColorProperty
public Color SymbolColor { get; set; }Lexical color for symbol characters. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
Methods28
AddColorRegionvoid
public void AddColorRegion(string startKey, string endKey, Color color, bool lineOnly = false);Adds a literal comment/string region. Delimiters consist of symbol characters; use a nonempty opener without spaces. Openers must be unique: RemoveColorRegion before replacing. An empty closer always means line-only; lineOnly true limits to one line even with a closer. Longer openers are checked before shorter ones.
| Name | Type | Default |
|---|---|---|
startKey | string | — |
endKey | string | — |
color | Color | — |
lineOnly | bool | false |
startKeyUnique nonempty opening delimiter made of symbol characters.
endKeyClosing delimiter; an empty string forces the region to one line.
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.
lineOnlyDo not carry the region onto the next line even with a nonempty endKey.
AddKeywordColorvoid
public void AddKeywordColor(string keyword, Color color);Adds or replaces an exact case-sensitive keyword color and clears the resource cache. Not a regex. Notify the editor through EmitChanged after changing rules.
| Name | Type | Default |
|---|---|---|
keyword | string | — |
color | Color | — |
keywordExact case-sensitive keyword rather than a regex.
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.
AddMemberKeywordColorvoid
public void AddMemberKeywordColor(string memberKeyword, Color color);Adds or replaces an exact unqualified member-word color. Not intended for a name after a dot. Clears the resource cache; then notify the editor through EmitChanged.
| Name | Type | Default |
|---|---|---|
memberKeyword | string | — |
color | Color | — |
memberKeywordExact unqualified member word; the table setter takes a Dictionary of words and Color.
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.
ClearColorRegionsvoid
public void ClearColorRegions();Removes all colored regions and clears their multiline-state cache. Retains keyword tables.
ClearKeywordColorsvoid
public void ClearKeywordColors();Clears the shared keyword table and cache. If supplied externally, the original Dictionary also becomes empty.
ClearMemberKeywordColorsvoid
public void ClearMemberKeywordColors();Clears the shared member table and resource cache. An externally supplied Dictionary is cleared too.
GetColorRegionsReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary GetColorRegions();Snapshot Dictionary of regions: keys are "opener closer", or only "opener" for a line-only region; values are Color. Assignment replaces regions without sharing the container. Does not encode explicit lineOnly with a nonempty closer; use AddColorRegion for that.
Reckfell.Collections.DictionarySnapshot Dictionary of regions: keys are "opener closer", or only "opener" for a line-only region; values are Color. Assignment replaces regions without sharing the container. Does not encode explicit lineOnly with a nonempty closer; use AddColorRegion for that.
GetFunctionColorColor
public Color GetFunctionColor();Lexical color for names before an opening call parenthesis. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
ColorLexical color for names before an opening call parenthesis. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
GetKeywordColorColor
public Color GetKeywordColor(string keyword);Stored color of an existing keyword. Check HasKeywordColor first: a missing rule is an error rather than a way to obtain the theme color.
| Name | Type | Default |
|---|---|---|
keyword | string | — |
keywordExact case-sensitive keyword rather than a regex.
ColorStored color of an existing keyword. Check HasKeywordColor first: a missing rule is an error rather than a way to obtain the theme color.
GetKeywordColorsReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary GetKeywordColors();Shared Dictionary mapping exact words to Color. Assignment replaces the table and clears the resource cache. In-place changes to the shared dictionary do not clear the cache. Opaque black with alpha 1 is not applied as a keyword color. Use EmitChanged to refresh the editor.
Reckfell.Collections.DictionaryShared Dictionary mapping exact words to Color. Assignment replaces the table and clears the resource cache. In-place changes to the shared dictionary do not clear the cache. Opaque black with alpha 1 is not applied as a keyword color. Use EmitChanged to refresh the editor.
GetMemberKeywordColorColor
public Color GetMemberKeywordColor(string memberKeyword);Color of an existing member rule. Check HasMemberKeywordColor first; a missing key produces an error.
| Name | Type | Default |
|---|---|---|
memberKeyword | string | — |
memberKeywordExact unqualified member word; the table setter takes a Dictionary of words and Color.
ColorColor of an existing member rule. Check HasMemberKeywordColor first; a missing key produces an error.
GetMemberKeywordColorsReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary GetMemberKeywordColors();Shared Dictionary for unqualified member-word colors. A word after a dot does not use this rule; MemberVariableColor applies. Assignment clears the resource cache, but in-place shared-table changes do not. Opaque black with alpha 1 is treated as unset.
Reckfell.Collections.DictionaryShared Dictionary for unqualified member-word colors. A word after a dot does not use this rule; MemberVariableColor applies. Assignment clears the resource cache, but in-place shared-table changes do not. Opaque black with alpha 1 is treated as unset.
GetMemberVariableColorColor
public Color GetMemberVariableColor();Lexical color for words after a dot. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
ColorLexical color for words after a dot. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
GetNumberColorColor
public Color GetNumberColor();Lexical color for numbers. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
ColorLexical color for numbers. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
GetSymbolColorColor
public Color GetSymbolColor();Lexical color for symbol characters. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
ColorLexical color for symbol characters. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
HasColorRegionbool
public bool HasColorRegion(string startKey);Whether an exact region opener is registered. Does not test whether a text position is inside the region.
| Name | Type | Default |
|---|---|---|
startKey | string | — |
startKeyUnique nonempty opening delimiter made of symbol characters.
boolWhether an exact region opener is registered. Does not test whether a text position is inside the region.
HasKeywordColorbool
public bool HasKeywordColor(string keyword);Whether the table contains the key. true does not guarantee a visible color: opaque black with alpha 1 is the unset marker.
| Name | Type | Default |
|---|---|---|
keyword | string | — |
keywordExact case-sensitive keyword rather than a regex.
boolWhether the table contains the key. true does not guarantee a visible color: opaque black with alpha 1 is the unset marker.
HasMemberKeywordColorbool
public bool HasMemberKeywordColor(string memberKeyword);Whether the member table contains the key. Does not guarantee application to a qualified name after a dot.
| Name | Type | Default |
|---|---|---|
memberKeyword | string | — |
memberKeywordExact unqualified member word; the table setter takes a Dictionary of words and Color.
boolWhether the member table contains the key. Does not guarantee application to a qualified name after a dot.
RemoveColorRegionvoid
public void RemoveColorRegion(string startKey);Removes a region by its exact opening delimiter and clears the resource cache. Call EmitChanged after rule changes.
| Name | Type | Default |
|---|---|---|
startKey | string | — |
startKeyUnique nonempty opening delimiter made of symbol characters.
RemoveKeywordColorvoid
public void RemoveKeywordColor(string keyword);Removes a keyword rule and clears the resource cache. Removal is visible to every owner of a shared table. Does not delete the word from text.
| Name | Type | Default |
|---|---|---|
keyword | string | — |
keywordExact case-sensitive keyword rather than a regex.
RemoveMemberKeywordColorvoid
public void RemoveMemberKeywordColor(string memberKeyword);Removes a member rule from the shared table and clears the resource cache. Does not edit document text.
| Name | Type | Default |
|---|---|---|
memberKeyword | string | — |
memberKeywordExact unqualified member word; the table setter takes a Dictionary of words and Color.
SetColorRegionsvoid
public void SetColorRegions(Reckfell.Collections.Dictionary colorRegions);Snapshot Dictionary of regions: keys are "opener closer", or only "opener" for a line-only region; values are Color. Assignment replaces regions without sharing the container. Does not encode explicit lineOnly with a nonempty closer; use AddColorRegion for that.
| Name | Type | Default |
|---|---|---|
colorRegions | Reckfell.Collections.Dictionary | — |
colorRegionsDictionary mapping "opener closer" to Color; explicit lineOnly with a nonempty closer is not encoded.
SetFunctionColorvoid
public void SetFunctionColor(Color color);Lexical color for names before an opening call parenthesis. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
| Name | Type | Default |
|---|---|---|
color | Color | — |
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.
SetKeywordColorsvoid
public void SetKeywordColors(Reckfell.Collections.Dictionary keywords);Shared Dictionary mapping exact words to Color. Assignment replaces the table and clears the resource cache. In-place changes to the shared dictionary do not clear the cache. Opaque black with alpha 1 is not applied as a keyword color. Use EmitChanged to refresh the editor.
| Name | Type | Default |
|---|---|---|
keywords | Reckfell.Collections.Dictionary | — |
keywordsShared Dictionary with string keys and Color values; do not mutate in place without clearing the cache.
SetMemberKeywordColorsvoid
public void SetMemberKeywordColors(Reckfell.Collections.Dictionary memberKeyword);Shared Dictionary for unqualified member-word colors. A word after a dot does not use this rule; MemberVariableColor applies. Assignment clears the resource cache, but in-place shared-table changes do not. Opaque black with alpha 1 is treated as unset.
| Name | Type | Default |
|---|---|---|
memberKeyword | Reckfell.Collections.Dictionary | — |
memberKeywordExact unqualified member word; the table setter takes a Dictionary of words and Color.
SetMemberVariableColorvoid
public void SetMemberVariableColor(Color color);Lexical color for words after a dot. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
| Name | Type | Default |
|---|---|---|
color | Color | — |
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.
SetNumberColorvoid
public void SetNumberColor(Color color);Lexical color for numbers. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
| Name | Type | Default |
|---|---|---|
color | Color | — |
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.
SetSymbolColorvoid
public void SetSymbolColor(Color color);Lexical color for symbol characters. A text rule rather than compiler semantic classification. The setter clears the resource cache; call EmitChanged to refresh the editor.
| Name | Type | Default |
|---|---|---|
color | Color | — |
colorRule Color; for keyword/member words, opaque black with alpha 1 is treated as unset.