public bool Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); Verify.State.IsFalse(_isCompleted, "Field is already completed."); if (_offset == 0 && textSegment.Length > 0) { var term = textSegment.PeekChar(); if (term == '\n') { textSegment.Skip(1); _isCompleted = true; return(true); } } if (_offset < 40 && textSegment.Length > 0) { int c = Math.Min(textSegment.Length, 40 - _offset); textSegment.MoveTo(_buffer, _offset, c); _offset += c; } if (_offset == 40 && textSegment.Length > 0) { _offset = 0; _hashes.Add(new Hash(_buffer)); var separator = textSegment.ReadChar(); if (separator == '\n') { _isCompleted = true; return(true); } } return(false); }
public void Parse(ITextSegment textSegment) { while(textSegment.Length > 0) { if(_commitParser.Parse(textSegment)) { _commitParser.Reset(); } } }
public void Parse(ITextSegment textSegment) { while (textSegment.Length > 0) { if (_commitParser.Parse(textSegment)) { _commitParser.Reset(); } } }
private IEnumerable <ITextSegmentStyled> FindStyles(ITextView textView, ITextSegment textLine, int relativeIndex, int textColumnIndex) { foreach (var style in textView.GetTextStyles()) { var foundStyle = style.FindStyledTextSegment(textView, textLine, this, relativeIndex, 0, textColumnIndex); if (foundStyle != null) { yield return(foundStyle); } } }
public bool Parse(ITextSegment textSegment) { Assert.IsNotNull(textSegment); while (textSegment.Length > 0) { switch (_offset) { case -3: X = textSegment.ReadChar(); ++_offset; break; case -2: Y = textSegment.ReadChar(); ++_offset; break; case -1: textSegment.Skip(1); ++_offset; break; case 0: if (ParseFileName(textSegment, _to)) { ++_offset; if (X != 'C' && X != 'R') { ++_offset; return(true); } } break; case 1: if (ParseFileName(textSegment, _from)) { ++_offset; return(true); } break; } } return(false); }
private bool ReadHash(ITextSegment textSegment) { int count = Math.Min(textSegment.Length, 40 - _bufferOffset); if (count != 0) { textSegment.MoveTo(_buffer, _bufferOffset, count); _bufferOffset += count; } if (_bufferOffset == 40) { if (textSegment.Length > 0) { textSegment.Skip(1); return(true); } } return(false); }
public bool Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); Verify.State.IsFalse(_offset == 41, "Field is already completed."); if (_offset < 40) { int c = Math.Min(textSegment.Length, 40 - _offset); textSegment.MoveTo(_buffer, _offset, c); _offset += c; } if (_offset == 40 && textSegment.Length > 0) { _offset = 41; textSegment.Skip(1); return(true); } return(false); }
public void Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); while (textSegment.Length > 0) { if (_fields[_currentFieldIndex].Parse(textSegment)) { ++_currentFieldIndex; if (_currentFieldIndex == _fields.Length) { _log.Add(BuildRevision()); for (int i = 0; i < _fields.Length; ++i) { _fields[i].Reset(); } _currentFieldIndex = 0; } } } }
public bool Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); Verify.State.IsFalse(_isCompleted, "Field is already completed."); while (textSegment.Length > 0) { var c = textSegment.ReadChar(); if (c == '\n') { _isCompleted = true; return(true); } int value = c - '0'; if (value >= 0 && value <= 9) { _timestamp = _timestamp * 10 + value; } } return(false); }
private void UpdateLineOverflow(ITextSegment line, int width) { if (this._layoutLinesOverflow.ContainsKey(line)) { if (width < ClientSize.Width) { this._layoutLinesOverflow.Remove(line); } else { this._layoutLinesOverflow[line] = width; } } else { if (width > ClientSize.Width) { this._layoutLinesOverflow.Add(line, width); } } }
private static bool ParseFileName(ITextSegment textSegment, StringBuilder stringBuilder) { Assert.IsNotNull(textSegment); Assert.IsNotNull(stringBuilder); int terminator = textSegment.IndexOf('\0'); if (terminator == -1) { textSegment.MoveTo(stringBuilder, textSegment.Length); } else { if (terminator != 0) { textSegment.MoveTo(stringBuilder, terminator); } textSegment.Skip(1); RemoveTrailingSlash(stringBuilder); return(true); } return(false); }
public bool Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); Verify.State.IsFalse(_isCompleted, "Field is already completed."); if (textSegment.Length > 0) { int eol = textSegment.IndexOf('\n'); if (eol == -1) { textSegment.MoveTo(_line, textSegment.Length); } else { if (eol != 0) { textSegment.MoveTo(_line, eol); } textSegment.Skip(1); return(true); } } return(false); }
public bool SearchAndApplyTo(ITextView textView, ITextSegment textSegment, int index, int length, int textColumnIndex) { return(this.SearchAndApplyTo(textView, textSegment, index, length, true, textColumnIndex)); }
public virtual ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int index, int length, int textColumnIndex) { return(null); }
/// <summary> /// TODO: Make this threaded and make the text control not editable meanwhile /// </summary> public bool SearchAndApplyTo(ITextView textView, ITextSegment textSegment, int index, int length, bool changeWasFinalizer, int textColumnIndex) { var foundOne = false; var canSkip = false; var previousWasWhitespace = false; var textLine = textSegment as TextLine; var textStyles = new List <TextStyleBase>(textView.GetTextStyles()); string previousStyleType = null; var previousStyleIndex = -1; if (textLine == null) { return(false); } for (var i = index; i <= index + length && i < textSegment.GetLength(textColumnIndex); i++) { #region If whitespace found, enable word-jump-search and only search on first char per word var isWhitespace = i < index + length && Char.IsWhiteSpace(textSegment.GetText(textColumnIndex)[i]); if (canSkip) { if (isWhitespace == false) { if (previousWasWhitespace == false) { continue; } } else { previousWasWhitespace = true; continue; // Don't need to search on a whitespace. } } else if (isWhitespace) { canSkip = true; previousWasWhitespace = true; continue; // Don't need to search on a whitespace. } previousWasWhitespace = false; #endregion ITextSegmentStyled newStyledTextSegment = null; for (var s = 0; s < textStyles.Count; s++) { if (textStyles[s].UpdateOnlyOnFinalizingChange && changeWasFinalizer == false) { continue; } newStyledTextSegment = textStyles[s].FindStyledTextSegment(textView, textSegment, this.TextHandler, i, -1, textColumnIndex); if (newStyledTextSegment != null) { //textStyles.RemoveAt(s); break; } } if (newStyledTextSegment == null) { continue; } var found = false; foreach (var existingStyle in GetAll(textLine, i, newStyledTextSegment.Style.NameKey)) { if (existingStyle.Style.NameKey == newStyledTextSegment.Style.NameKey) { if (newStyledTextSegment.Index == existingStyle.Index && newStyledTextSegment.GetLength(textColumnIndex) == existingStyle.GetLength(textColumnIndex)) { found = true; break; } this.RemoveTextSegment(existingStyle); break; } } if (found == false) { foundOne = true; // TODO: Make this line actually work. (NOTE: what did I mean here? ;D) this.AddManualTextSegment(newStyledTextSegment, textLine.Index + newStyledTextSegment.Index, textColumnIndex); } if (previousStyleType != newStyledTextSegment.Style.NameKey && previousStyleIndex != newStyledTextSegment.Index) { // Decrease it so that we stay on the same location, in case there are several styles overlapping on the same spot. i--; } previousStyleType = newStyledTextSegment.Style.NameKey; previousStyleIndex = newStyledTextSegment.Index; } return(foundOne); }
public void Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); while (textSegment.Length > 0) { if (_line.Parse(textSegment)) { bool staged = false; bool unstaged = false; var conflictType = ConflictType.None; var stagedFileStatus = FileStatus.Unknown; var unstagedFileStatus = FileStatus.Unknown; var x = _line.X; var y = _line.Y; var to = _line.To; if (x == '?') { staged = false; unstaged = true; unstagedFileStatus = FileStatus.Added; ++_unstagedUntrackedCount; } else { if (x == 'C' || x == 'R') { var from = _line.From; if (x == 'C') { x = 'A'; stagedFileStatus = FileStatus.Added; } else { if (!_stagedFiles.ContainsKey(from)) { var file = new TreeFileData(from, FileStatus.Removed, ConflictType.None, StagedStatus.Staged); _stagedFiles.Add(from, file); ++_stagedRemovedCount; } x = 'A'; stagedFileStatus = FileStatus.Added; } } conflictType = GetConflictType(x, y); if (conflictType != ConflictType.None) { staged = false; unstaged = true; unstagedFileStatus = FileStatus.Unmerged; ++_unmergedCount; } else { if (x != ' ') { staged = true; stagedFileStatus = CharToFileStatus(x); AddStagedStats(stagedFileStatus, 1); } if (y != ' ') { unstaged = true; unstagedFileStatus = CharToFileStatus(y); AddUnstagedStats(unstagedFileStatus, 1); } } } if (staged) { var file = new TreeFileData(to, stagedFileStatus, ConflictType.None, StagedStatus.Staged); if (_stagedFiles.TryGetValue(to, out var existing)) { AddStagedStats(existing.FileStatus, -1); _stagedFiles[to] = file; } else { _stagedFiles.Add(to, file); } } if (unstaged) { var file = new TreeFileData(to, unstagedFileStatus, conflictType, StagedStatus.Unstaged); if (_unstagedFiles.TryGetValue(to, out var existing)) { if (existing.FileStatus == FileStatus.Removed) { --_unstagedRemovedCount; _unstagedFiles[to] = file; } } else { _unstagedFiles.Add(to, file); } } _line.Reset(); } } }
public abstract WordSegment GetWord(int globalIndex, ITextSegment insideSegment, bool strict, int textColumnIndex);
public unsafe void Render(IntPtr hdc, int vpx, int vpy, Size size) { #region Initialize GDI resources if (this._brushCurrentLine == null) { var colorWithoutTransparency = Color.FromArgb(this.TextView.LineHighlightColor.R, this.TextView.LineHighlightColor.G, this.TextView.LineHighlightColor.B); this._brushCurrentLine = new SafeHandleGDI(SafeNativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(colorWithoutTransparency))); } #endregion var styleSelection = this.TextView.GetTextStyle("Selection"); var styleDefault = this.TextView.GetTextStyle("Default"); var rs = new RendererState(this.TextView.GetTextRectangle(false), this.TextView.LineHeight); rs.TextView = this.TextView; rs.RenderState = new RenderState(this.TextView, styleDefault); rs.ViewportX = vpx - rs.TextRectangle.Left; rs.ViewportY = vpy; ITextSegmentStyled selectionSegment = null; ITextSegment firstVisibleLine = null; //var foundActiveLine = this.TextView.LineHighlightColor.A == Color.Transparent.A || this.TextView.LineHighlightColor == Color.Empty; var textColumnIndex = this.TextView.CurrentTextColumnIndex; var sri = new StyleRenderInfo(this.FocusedStyledSegment); // TODO: Paint some nice graphics for the current text column index, when it is stable enough. var clientSize = this.TextView.ClientSize; var lineCount = this.Strategy.Lines.Count; var firstCharIndex = this.TextView.GetFirstCharIndexFromLine(this.TextView.GetCurrentLine()); var lineIndexPhysical = 0; for (rs.LineIndexPhysical = 0; rs.LineIndexPhysical < lineCount; lineIndexPhysical++, rs.LineIndexPhysical++) { if (rs.Y > rs.ViewportY + size.Height) { // This line is after the viewport and does not need painting. break; } rs.Line = this.Strategy.Lines[lineIndexPhysical]; var visualInfo = this.TextView.GetVisualInformation(lineIndexPhysical); var lineCountVisual = visualInfo.GetLineCountVisual(textColumnIndex); var linesHeight = lineCountVisual * rs.LineHeight; if (rs.Y + linesHeight <= rs.ViewportY) { // This line is before the viewport. rs.Y += linesHeight; rs.LineIndexVirtual += lineCountVisual; continue; } if (rs.Line.Index >= firstCharIndex && rs.Line.Index <= (this.TextView.SelectionStart + this.TextView.SelectionLength)) { rs.LineIndexVirtualFocused = rs.LineIndexVirtual; if (this.TextView.SelectionLength == 0) { this.RenderSelectedLineBackground(hdc, rs); } } var textPoints = new Dictionary <int, List <ITextSegmentStyled> >(); if (firstVisibleLine == null) { firstVisibleLine = rs.Line; #region Special handling for selection if (this.TextView.SelectionLength > 0) { if (this.TextView.SelectionStart < rs.Line.Index && this.TextView.SelectionStart + this.TextView.SelectionLength >= rs.Line.Index) { // The selection begins on the line before this. selectionSegment = new TextAnchor(styleSelection); selectionSegment.Index = firstVisibleLine.Index; var textPointIndex = rs.Line.Index; if (textPoints.ContainsKey(textPointIndex) == false) { textPoints.Add(textPointIndex, new List <ITextSegmentStyled>()); } textPoints[textPointIndex].Add(selectionSegment); } } #endregion } var lineLength = rs.Line.GetLength(textColumnIndex); if (this.TextView.SelectionLength > 0) { #region Special handling for selection if (this.TextView.SelectionStart >= rs.Line.Index && this.TextView.SelectionStart <= rs.Line.Index + lineLength) { // The selection begins on this line. selectionSegment = new TextAnchor(styleSelection); selectionSegment.Index = rs.Line.Index; selectionSegment.SetLength(textColumnIndex, this.TextView.SelectionLength); var textPointIndex = this.TextView.SelectionStart; if (textPoints.ContainsKey(textPointIndex) == false) { textPoints.Add(textPointIndex, new List <ITextSegmentStyled>()); } textPoints[textPointIndex].Add(selectionSegment); } if (this.TextView.SelectionStart + this.TextView.SelectionLength >= rs.Line.Index && this.TextView.SelectionStart + this.TextView.SelectionLength <= rs.Line.Index + lineLength) { // The selection ends on this line. var textPointIndex = -(this.TextView.SelectionStart + this.TextView.SelectionLength); if (textPoints.ContainsKey(textPointIndex) == false) { textPoints.Add(textPointIndex, new List <ITextSegmentStyled>()); } textPoints[textPointIndex].Add(selectionSegment); } #endregion } var textLine = (TextLine)rs.Line; if (textLine.StyledTextSegments != null && textLine.StyledTextSegments.Count > 0) { foreach (var textSegment in textLine.StyledTextSegments) { var textPointStartIndex = textLine.Index + textSegment.Index; if (textPoints.ContainsKey(textPointStartIndex) == false) { textPoints.Add(textPointStartIndex, new List <ITextSegmentStyled>()); } textPoints[textPointStartIndex].Add(textSegment); var textPointEndIndex = -(textLine.Index + textSegment.Index + textSegment.GetLength(textColumnIndex)); if (textPoints.ContainsKey(textPointEndIndex) == false) { textPoints.Add(textPointEndIndex, new List <ITextSegmentStyled>()); } textPoints[textPointEndIndex].Add(textSegment); } } var wordWrapIndex = 0; var tabIndex = 0; rs.X = 0; var previousTextIndex = 0; //var textLength = rs.Line.GetLength(textColumnIndex); var lineSplitIndexes = visualInfo.GetLineSplitIndexes(textColumnIndex); for (var textIndex = 0; textIndex <= lineLength; textIndex++) { var isLastIndex = textIndex == lineLength; var isNewline = lineSplitIndexes != null; if (isNewline) { isNewline = wordWrapIndex < lineSplitIndexes.Length && lineSplitIndexes[wordWrapIndex] == textIndex; if (isNewline) { wordWrapIndex++; } } var isTab = visualInfo.GetTabSplitIndexes(textColumnIndex) != null; if (isTab) { isTab = tabIndex < visualInfo.GetTabSplitIndexes(textColumnIndex).Length&& visualInfo.GetTabSplitIndexes(textColumnIndex)[tabIndex] == textIndex; if (isTab) { tabIndex++; } } var globalIndex = rs.Line.Index + textIndex; var styleStart = textPoints.ContainsKey(globalIndex) ? textPoints[globalIndex] : null; var styleEnd = globalIndex != 0 && textPoints.ContainsKey(-globalIndex) ? textPoints[-globalIndex] : null; if ((isLastIndex || isNewline || isTab || styleStart != null || styleEnd != null) == false) { // This is a regular character, and no change is done for it. continue; } var start = previousTextIndex; var length = textIndex - start; var outputText = rs.Line.GetText(textColumnIndex); #region Add empty space at end of text if selection goes beyond current line if (start + length == lineLength) { foreach (var rsi in rs.RenderState.GetRenderStateItems()) { if (rsi.Segment.Style.NameKey != styleSelection.NameKey) { continue; } if (styleEnd != null) { var isStyleSelection = false; foreach (var se in styleEnd) { if (se.Style.NameKey == styleSelection.NameKey) { isStyleSelection = true; break; } } if (isStyleSelection) { break; } } outputText += " "; length++; break; } } #endregion fixed(char *c = outputText) { SafeNativeMethods.TextOut(hdc, rs.TextRectangle.Left + (rs.X - rs.ViewportX), rs.TextRectangle.Top + rs.Y - rs.ViewportY, c + start, length); if ((isNewline == false && isLastIndex == false) || styleEnd != null) { rs.X += rs.Line.GetSize(hdc, rs.X, start, length, visualInfo.GetVisualInfo(textColumnIndex)).Width; } if (styleEnd != null) { foreach (var t in styleEnd) { switch (t.Style.PaintMode) { case TextStylePaintMode.Custom: { t.Style.Paint(hdc, t, this.TextView, visualInfo.GetVisualInfo(textColumnIndex), rs.TextRectangle.Left + (rs.X - rs.ViewportX), rs.TextRectangle.Top + rs.Y - rs.ViewportY, rs.LineHeight, sri); } break; } } } } if (isNewline) { this.RenderLineColumns(hdc, clientSize, rs); rs.X = 0; rs.LineIndexVirtual++; rs.Y += rs.LineHeight; } if (styleStart != null) { foreach (var t in styleStart) { rs.RenderState.Add(this.TextView, t); } rs.RenderState.Apply(hdc); } if (styleEnd != null) { foreach (var t in styleEnd) { rs.RenderState.Remove(t); } rs.RenderState.Apply(hdc); } previousTextIndex = textIndex; } if (this.TextView.WordWrapGlyphs && lineCountVisual > 1) { RenderWordWrapGlyph(hdc, rs.ViewportY, rs.Y, rs.TextRectangle, rs.LineHeight); } this.RenderLineColumns(hdc, clientSize, rs); rs.X = 0; rs.LineIndexVirtual++; rs.Y += rs.LineHeight; } this.PaintTooltipOverlay(hdc); }
private bool ReadHash(ITextSegment textSegment) { int count = Math.Min(textSegment.Length, 40 - _bufferOffset); if(count != 0) { textSegment.MoveTo(_buffer, _bufferOffset, count); _bufferOffset += count; } if(_bufferOffset == 40) { if(textSegment.Length > 0) { textSegment.Skip(1); return true; } } return false; }
public bool Parse(ITextSegment textSegment) { while (textSegment.Length > 0) { switch (_state) { case State.ReadingHeader: { int terminator = textSegment.IndexOf(' '); if (terminator == -1) { int count = textSegment.Length; if (_bufferOffset + count > _buffer.Length) { throw new Exception("header is too large"); } textSegment.MoveTo(_buffer, _bufferOffset, count); _bufferOffset += count; } else { if (terminator != 0) { if (_bufferOffset + terminator > _buffer.Length) { throw new Exception("header is too large"); } textSegment.MoveTo(_buffer, _bufferOffset, terminator); _bufferOffset += terminator; } textSegment.Skip(1); switch (_part) { case Part.None: if (CurrentHeaderIs(@"commit")) { _part = Part.Commit; } else { throw new Exception("Expected header: commit"); } break; case Part.Commit: if (CurrentHeaderIs(@"tree")) { _part = Part.Tree; } else { throw new Exception("Expected header: tree"); } break; case Part.Tree: case Part.Parent: if (CurrentHeaderIs(@"parent")) { _part = Part.Parent; } else if (CurrentHeaderIs(@"author")) { _part = Part.Author; } else { throw new Exception("Expected header: parent or author"); } break; case Part.Author: if (CurrentHeaderIs("committer")) { _part = Part.Committer; } else { throw new Exception("Expected header: committer"); } break; default: throw new Exception("Invalid parser state."); } _bufferOffset = 0; _state = State.ReadingContent; } } break; case State.ReadingContent: switch (_part) { case Part.Commit: if (ReadHash(textSegment)) { _commit = new Hash(_buffer); _state = State.ReadingHeader; } break; case Part.Tree: if (ReadHash(textSegment)) { _tree = new Hash(_buffer); _state = State.ReadingHeader; } break; case Part.Parent: if (ReadHash(textSegment)) { _parents.Add(new Hash(_buffer)); _state = State.ReadingHeader; } break; } break; } } return(false); }
public bool Parse(ITextSegment textSegment) { Verify.Argument.IsNotNull(textSegment, nameof(textSegment)); Verify.State.IsFalse(_isCompleted, "Field is already completed."); while (textSegment.Length > 0) { int separatorIndex = _isSubjectCompleted ? textSegment.IndexOf('\0') : textSegment.IndexOfAny(Separators); if (separatorIndex == -1) { if (_isSubjectCompleted) { textSegment.MoveTo(_body, textSegment.Length); } else { if (_separator.Length != 0) { _separator.Dump(_subject); } textSegment.MoveTo(_subject, textSegment.Length); } return(false); } else { if (_isSubjectCompleted) { textSegment.MoveTo(_body, separatorIndex); } else { if (separatorIndex != 0) { if (_separator.Length != 0) { _separator.Dump(_subject); } textSegment.MoveTo(_subject, separatorIndex); } } var separatorChar = textSegment.ReadChar(); switch (separatorChar) { case '\0': RemoveTrailingWhitespace(_subject); if (_isSubjectCompleted) { RemoveTrailingWhitespace(_body); } _isCompleted = true; return(true); case '\r': case '\n': if (_isSubjectCompleted) { _body.Append(separatorChar); } else { if (_separator.Append(separatorChar)) { _isSubjectCompleted = true; _separator.Reset(); } } break; } } } return(false); }
public bool Parse(ITextSegment textSegment) { while(textSegment.Length > 0) { switch(_state) { case State.ReadingHeader: { int terminator = textSegment.IndexOf(' '); if(terminator == -1) { int count = textSegment.Length; if(_bufferOffset + count > _buffer.Length) { throw new Exception("header is too large"); } textSegment.MoveTo(_buffer, _bufferOffset, count); _bufferOffset += count; } else { if(terminator != 0) { if(_bufferOffset + terminator > _buffer.Length) { throw new Exception("header is too large"); } textSegment.MoveTo(_buffer, _bufferOffset, terminator); _bufferOffset += terminator; } textSegment.Skip(1); switch(_part) { case Part.None: if(CurrentHeaderIs(@"commit")) { _part = Part.Commit; } else { throw new Exception("Expected header: commit"); } break; case Part.Commit: if(CurrentHeaderIs(@"tree")) { _part = Part.Tree; } else { throw new Exception("Expected header: tree"); } break; case Part.Tree: case Part.Parent: if(CurrentHeaderIs(@"parent")) { _part = Part.Parent; } else if(CurrentHeaderIs(@"author")) { _part = Part.Author; } else { throw new Exception("Expected header: parent or author"); } break; case Part.Author: if(CurrentHeaderIs("committer")) { _part = Part.Committer; } else { throw new Exception("Expected header: committer"); } break; default: throw new Exception("Invalid parser state."); } _bufferOffset = 0; _state = State.ReadingContent; } } break; case State.ReadingContent: switch(_part) { case Part.Commit: if(ReadHash(textSegment)) { _commit = new Hash(_buffer); _state = State.ReadingHeader; } break; case Part.Tree: if(ReadHash(textSegment)) { _tree = new Hash(_buffer); _state = State.ReadingHeader; } break; case Part.Parent: if(ReadHash(textSegment)) { _parents.Add(new Hash(_buffer)); _state = State.ReadingHeader; } break; } break; } } return false; }
public WordSegment GetWord(int globalIndex, ITextSegment insideSegment, bool strict) { return(this.TextDocument.GetWord(globalIndex, insideSegment, strict, this.CurrentTextColumnIndex)); }
public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int index, int length, int textColumnIndex) { var lineIndex = document.GetLineFromCharIndex(textSegment.Index + index, textColumnIndex); var firstCharIndex = document.GetFirstCharIndexFromLine(lineIndex); var styleCount = document.TextSegmentStyledManager.Get(firstCharIndex, NameKey, textColumnIndex).Count(); if (styleCount > 0) { return(null); } var content = document.GetLineText(lineIndex, textColumnIndex); var isManual = _regexManual.IsMatch(content); // Regex.IsMatch(content, "^\\d:"); var isSwitch = _regexSwitch.IsMatch(content); // Regex.IsMatch(content, "^-[^\\-]"); if (isManual || isSwitch) { var segment = document.CreateStyledTextSegment(this); segment.Index = 0; segment.SetLength(textColumnIndex, 1); segment.Object = isManual ? int.Parse("" + document.GetCharFromIndex(firstCharIndex, textColumnIndex)) : -1; return(segment); } if (content.StartsWith("[")) { var match = _regexTimestamp.Match(content); if (match.Success) { if (string.IsNullOrEmpty(match.Groups[3].Value) == false) { var segment = document.CreateStyledTextSegment(this); segment.Index = 0; segment.SetLength(textColumnIndex, content.Length); segment.Object = -2; return(segment); } } } return(null); }
public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int startIndex, int length, int textColumnIndex) { var text = textSegment.GetText(textColumnIndex); if (startIndex >= text.Length) { return(null); } foreach (var word in this.WordList) { for (var i = 0; i < word.Length; i++) { if (word[i] != text[startIndex]) { continue; } var found = true; var left = i - 1; for (; left >= 0; left--) { var relativeIndex = startIndex - (i - left); if (relativeIndex < 0) { found = false; break; } var c = text[relativeIndex]; if (word[left] != c) { found = false; break; } } if (found == false) { break; } left = Math.Max(0, left); var right = i + 1; for (; right < word.Length; right++) { var relativeIndex = startIndex + (right - i); if (relativeIndex >= text.Length) { found = false; break; } var c = text[relativeIndex]; if (word[right] != c) { found = false; break; } } if (found) { var newTextSegment = document.CreateStyledTextSegment(this); var relativeIndex = startIndex - (i - left); newTextSegment.Index = relativeIndex; newTextSegment.SetLength(textColumnIndex, right - left); newTextSegment.Object = word; return(newTextSegment); } } } return(null); }
public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int index, int length, int textColumnIndex) { // TODO: This is way too slow. Should be able to speed up significantly. foreach (var textView in document.GetTextViews()) { this._cultureInfo = textView.Language; if (this._cultureInfo != null) { break; } } if (textEditor.Settings.SpellcheckEnabled(this._cultureInfo) == false || textEditor.Settings.InlineEnabled == false) { return(null); } var searchStartIndex = textSegment.Index + index; var selectedWord = document.GetWord(searchStartIndex, textSegment, true, textColumnIndex); if (selectedWord == null) { // If the current index has no word, then we exit. return(null); } if (selectedWord.End - selectedWord.Start < 3) { // If the word is shorter than 3 characters, then we exit. return(null); } if (textEditor.Settings.CheckIfWordIsValid(selectedWord.Word, textSegment.GetText(textColumnIndex)) == false) { // If the word is not a valid word according to out filter settings, then we exit. return(null); } try { //var spellcheckValid = ; //foreach (var check in LanguageFeature.FeatureFetchMultiple<bool>(this._cultureInfo, "Spellcheck.Check", new LFSString(selectedWord.Word))) //{ // spellcheckValid = check; // if (spellcheckValid) // { // break; // } //} if (textEditor.Settings.IsSpelledCorrectly(selectedWord.Word)) { // If the word is a correctly spelled word, then we exit. return(null); } } catch (Exception) { } // The word is not spelled correctly, so we create a style and return it. var incorrectlySpelledTextSegment = document.CreateStyledTextSegment(this); incorrectlySpelledTextSegment.Index = selectedWord.Start - textSegment.Index; incorrectlySpelledTextSegment.SetLength(textColumnIndex, selectedWord.End - selectedWord.Start); incorrectlySpelledTextSegment.Object = selectedWord.Word; return(incorrectlySpelledTextSegment); }
public override WordSegment GetWord(int globalIndex, ITextSegment insideSegment, bool strict, int textColumnIndex) { return(insideSegment.GetText(textColumnIndex).GetWord(globalIndex, insideSegment.Index, strict)); }