public static TextWord Split(ref TextWord word, int pos) { TextWord textWord = new TextWord(word.document, word.line, word.offset + pos, word.length - pos, word.color, word.hasDefaultColor); word = new TextWord(word.document, word.line, word.offset, pos, word.color, word.hasDefaultColor); return(textWord); }
public TextWord GetWord(int column) { TextWord textWord; int length = 0; List <TextWord> .Enumerator enumerator = this.words.GetEnumerator(); try { while (enumerator.MoveNext()) { TextWord current = enumerator.Current; if (column >= length + current.Length) { length += current.Length; } else { textWord = current; return(textWord); } } return(null); } finally { ((IDisposable)enumerator).Dispose(); } return(textWord); }
public HighlightColor GetColorForPosition(int x) { HighlightColor syntaxColor; if (this.Words != null) { int length = 0; List <TextWord> .Enumerator enumerator = this.Words.GetEnumerator(); try { while (enumerator.MoveNext()) { TextWord current = enumerator.Current; if (x >= length + current.Length) { length += current.Length; } else { syntaxColor = current.SyntaxColor; return(syntaxColor); } } return(new HighlightColor(Color.Black, false, false)); } finally { ((IDisposable)enumerator).Dispose(); } return(syntaxColor); } return(new HighlightColor(Color.Black, false, false)); }
/// <summary> /// Splits the <paramref name="word"/> into two parts: the part before <paramref name="pos"/> is assigned to /// the reference parameter <paramref name="word"/>, the part after <paramref name="pos"/> is returned. /// </summary> public static TextWord Split(ref TextWord word, int pos) { #if DEBUG_EX if (word.Type != TextWordType.Word) { throw new ArgumentException("word.Type must be Word"); } if (pos <= 0) { throw new ArgumentOutOfRangeException("pos", pos, "pos must be > 0"); } if (pos >= word.Length) { throw new ArgumentOutOfRangeException("pos", pos, "pos must be < word.Length"); } #endif TextWord after = new TextWord(word._document, word._line, word.Offset + pos, word.Length - pos, word.SyntaxColor, word.HasDefaultColor); word = new TextWord(word._document, word._line, word.Offset, pos, word.SyntaxColor, word.HasDefaultColor); return(after); }
/// <summary> /// Splits the <paramref name="word"/> into two parts: the part before <paramref name="pos"/> is assigned to /// the reference parameter <paramref name="word"/>, the part after <paramref name="pos"/> is returned. /// </summary> public static TextWord Split(ref TextWord word, int pos) { #if DEBUG if (word.Type != TextWordType.Word) throw new ArgumentException("word.Type must be Word"); if (pos <= 0) throw new ArgumentOutOfRangeException("pos", pos, "pos must be > 0"); if (pos >= word.Length) throw new ArgumentOutOfRangeException("pos", pos, "pos must be < word.Length"); #endif TextWord after = new TextWord(word.document, word.line, word.offset + pos, word.length - pos, word.color, word.hasDefaultColor); word = new TextWord(word.document, word.line, word.offset, pos, word.color, word.hasDefaultColor); return after; }
string GetStyle(TextWord word) { if (word.SyntaxColor == null || word.SyntaxColor.ToString() == currentDefaultTextColor.ToString()) return null; string style = "color: " + ColorToString(word.Color) + ";"; if (word.Bold) { style += " font-weight: bold;"; } if (word.Italic) { style += " font-style: italic;"; } if (word.SyntaxColor.HasBackground) { style += " background-color: " + ColorToString(word.SyntaxColor.BackgroundColor) + ";"; } return style; }
/// <summary> /// pushes the curWord string on the word list, with the /// correct color. /// </summary> void PushCurWord(IDocument document, ref HighlightColor markNext, List <TextWord> words) { // Svante Lidman : Need to look through the next prev logic. if (currentLength > 0) { if (words.Count > 0 && activeRuleSet != null) { TextWord prevWord = null; int pInd = words.Count - 1; while (pInd >= 0) { if (!((TextWord)words[pInd]).IsWhiteSpace) { prevWord = (TextWord)words[pInd]; if (prevWord.HasDefaultColor) { PrevMarker marker = (PrevMarker)activeRuleSet.PrevMarkers[document, currentLine, currentOffset, currentLength]; if (marker != null) { prevWord.SyntaxColor = marker.Color; // document.Caret.ValidateCaretPos(); // document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset))); } } break; } pInd--; } } if (inSpan) { HighlightColor c = null; bool hasDefaultColor = true; if (activeSpan.Rule == null) { c = activeSpan.Color; } else { c = GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength); hasDefaultColor = false; } if (c == null) { c = activeSpan.Color; if (c.Color == Color.Transparent) { c = this.DefaultTextColor; } hasDefaultColor = true; } words.Add(new TextWord(document, currentLine, currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor)); } else { HighlightColor c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength); if (c == null) { words.Add(new TextWord(document, currentLine, currentOffset, currentLength, this.DefaultTextColor, true)); } else { words.Add(new TextWord(document, currentLine, currentOffset, currentLength, c, false)); } } if (activeRuleSet != null) { NextMarker nextMarker = (NextMarker)activeRuleSet.NextMarkers[document, currentLine, currentOffset, currentLength]; if (nextMarker != null) { if (nextMarker.MarkMarker && words.Count > 0) { TextWord prevword = ((TextWord)words[words.Count - 1]); prevword.SyntaxColor = nextMarker.Color; } markNext = nextMarker.Color; } else { markNext = null; } } currentOffset += currentLength; currentLength = 0; } }
private int GetWordInt(TextWord word) { try { return Convert.ToInt32(word.Word); } catch { return Int32.MinValue; } }
static TextWord() { TextWord.spaceWord = new TextWord.SpaceTextWord(); TextWord.tabWord = new TextWord.TabTextWord(); }
private void PushCurWord(IDocument document, ref HighlightColor markNext, List <TextWord> words) { if (this.currentLength > 0) { if (words.Count > 0 && this.activeRuleSet != null) { TextWord item = null; int count = words.Count - 1; while (count >= 0) { if (words[count].IsWhiteSpace) { count--; } else { item = words[count]; if (!item.HasDefaultColor) { break; } PrevMarker prevMarker = (PrevMarker)this.activeRuleSet.PrevMarkers[document, this.currentLine, this.currentOffset, this.currentLength]; if (prevMarker == null) { break; } item.SyntaxColor = prevMarker.Color; break; } } } if (!this.inSpan) { HighlightColor highlightColor = (markNext != null ? markNext : this.GetColor(this.activeRuleSet, document, this.currentLine, this.currentOffset, this.currentLength)); if (highlightColor != null) { words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, highlightColor, false)); } else { words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, this.DefaultTextColor, true)); } } else { HighlightColor color = null; bool flag = true; if (this.activeSpan.Rule != null) { color = this.GetColor(this.activeRuleSet, document, this.currentLine, this.currentOffset, this.currentLength); flag = false; } else { color = this.activeSpan.Color; } if (color == null) { color = this.activeSpan.Color; if (color.Color == Color.Transparent) { color = this.DefaultTextColor; } flag = true; } words.Add(new TextWord(document, this.currentLine, this.currentOffset, this.currentLength, (markNext != null ? markNext : color), flag)); } if (this.activeRuleSet != null) { NextMarker nextMarker = (NextMarker)this.activeRuleSet.NextMarkers[document, this.currentLine, this.currentOffset, this.currentLength]; if (nextMarker == null) { markNext = null; } else { if (nextMarker.MarkMarker && words.Count > 0) { TextWord textWord = words[words.Count - 1]; textWord.SyntaxColor = nextMarker.Color; } markNext = nextMarker.Color; } } this.currentOffset += this.currentLength; this.currentLength = 0; } }
/// <summary> /// Colourises the given token and adds it to the document. /// </summary> /// <param name="document">The document being highlighted.</param> /// <param name="j">The token to highlight.</param> protected void HandleToken(IDocument document, IToken j) { LineSegment lsgLine = document.GetLineSegment(j.Line - 1); HighlightColor hclColour = GetColorFor(GetTokenClass(j.Type)); TextWord twdWord = new TextWord(document, lsgLine, j.CharPositionInLine, j.Text.Length, hclColour, false); Int32 i = 0; for (; i < lsgLine.Words.Count; i++) if (lsgLine.Words[i].Offset > j.CharPositionInLine) { lsgLine.Words.Insert(i, twdWord); break; } if (lsgLine.Words.Count == i) lsgLine.Words.Add(twdWord); }