public bool IsInOriginal (ISegment segment) { if (segment == null) throw new ArgumentNullException ("segment"); return segment.Contains(Offset) && segment.Contains (Offset + Length); }
public bool IsInOriginal(ISegment segment) { if (segment == null) { throw new ArgumentNullException("segment"); } return(segment.Contains(Offset) && segment.Contains(Offset + Length)); }
void Caret_PositionChanged(object sender, EventArgs e) { ISegment s = this.Segment; if (s != null) { bool newIsCaretInside = s.Contains(context.TextArea.Caret.Offset, 0); if (newIsCaretInside != isCaretInside) { isCaretInside = newIsCaretInside; context.TextArea.TextView.InvalidateLayer(foreground.Layer); } } }
//check if "theAncestor" is an ancestor of "theMarkupData" private bool IsAncestorOfMarkup(IAbstractMarkupData theMarkupData, ISegment theAncestor) { var ret = false; if (theMarkupData == null || theAncestor == null) { return(ret); } var parent = theMarkupData.Parent; if (parent == null) { return(ret); } ret = parent.Equals(theAncestor) || theAncestor.Contains(theMarkupData); return(ret); }
public async void Complete(TextArea textArea, ISegment completionSegment, EventArgs e) { if (_glyph == Glyph.Snippet && CompleteSnippet(textArea, completionSegment, e)) { return; } var changes = await CompletionService.GetService(_document) .GetChangeAsync(_document, _item, _completionChar).ConfigureAwait(false); if (!changes.TextChanges.IsDefaultOrEmpty) { var document = textArea.Document; using (document.RunUpdate()) { // find the change that contains the completionSegment // we may need to remove a few typed chars since the Roslyn document isn't updated // while the completion window is open var firstSpan = changes.TextChanges.FirstOrDefault(x => completionSegment.Contains(x.Span.Start, x.Span.Length)); if (firstSpan != default(TextChange) && completionSegment.EndOffset > firstSpan.Span.End) { document.Replace(new TextSegment { StartOffset = firstSpan.Span.End, EndOffset = completionSegment.EndOffset }, string.Empty); } var offset = 0; foreach (var change in changes.TextChanges) { document.Replace(change.Span.Start + offset, change.Span.Length, new StringTextSource(change.NewText)); offset += change.NewText.Length - change.Span.Length; } } } if (changes.NewPosition != null) { textArea.Caret.Offset = changes.NewPosition.Value; } }
//check if "theAncestor" is an ancestor of "theMarkupData" private bool IsAncestorOfMarkup(IAbstractMarkupData theMarkupData, ISegment theAncestor) { bool ret = false; if (theMarkupData != null && theAncestor != null) { IAbstractMarkupDataContainer parent = theMarkupData.Parent; if (parent != null) { if (parent.Equals(theAncestor)) { ret = true; } else { ret = theAncestor.Contains(theMarkupData); } } } return(ret); }
private static List <IAbstractMarkupData> GetNonSegmentMarkupDataAfterSegment(IAbstractMarkupDataContainer segmentParent, ISegment segmentContainer) { var markupDataList = new List <IAbstractMarkupData>(); var foundContainer = false; foreach (var markupData in segmentParent.AllSubItems) { if (markupData is ISegment segment) { if (foundContainer) { break; } if (segmentContainer.Properties.Id.Id == segment.Properties.Id.Id) { foundContainer = true; } } else if (foundContainer) { if (segmentContainer.Contains(markupData)) { continue; } if (markupData is ITagPair) { break; } // Add to the list markupDataList.Add(markupData); } } return(markupDataList); }
/// <summary> /// If _from or _to is in the path, the returned path is this path cut such that it starts at _from and/or ends at _to /// if _cutRooms is true it removes the associated _from or _to room if _from/_to is not null /// </summary> /// <param name="_from"></param> /// <param name="_to"></param> /// <param name="_cutRooms"></param> /// <returns></returns> public IPath Cut(IVector2?_from, IVector2?_to, bool _cutRooms = true) { IVector2 from; Room fromRoom = null; IVector2 to; Room toRoom = null; if (_from == null) { from = Points[0]; fromRoom = m_FromRoom; } else { from = _from.Value; if (!_cutRooms) { fromRoom = m_FromRoom; } } if (_to == null) { to = Points.Last(); toRoom = m_ToRoom; } else { to = _to.Value; if (!_cutRooms) { toRoom = m_ToRoom; } } var newPath = new List <IVector2>(); bool copy = false; for (int i = 0; i < m_Path.Count - 1; ++i) { var seg = new ISegment(m_Path[i], m_Path[i + 1]); if (seg.Contains(from)) { copy = true; newPath.Add(from); i++; } if (copy) { newPath.Add(m_Path[i]); if (i >= m_Path.Count - 1) { break; } var lastSeg = new ISegment(newPath.Last(), m_Path[i + 1]); if (lastSeg.Contains(to)) { newPath.Add(to); break; } } } return(new IPath(newPath, fromRoom, toRoom)); }