void SetSelection(CursorPosition begin, CursorPosition?end) { selection.first = begin; if (end.HasValue) { selection.last = end.Value; } selection.normalized = CursorPosition.Compare(selection.first, selection.last) <= 0; }
public bool IsInsideSelection(CursorPosition pos) { var normalized = this.Normalize(); if (normalized.IsEmpty) { return(false); } return(CursorPosition.Compare(normalized.First, pos) <= 0 && CursorPosition.Compare(normalized.Last, pos) >= 0); }
public SelectionInfo Normalize() { if (last == null || CursorPosition.Compare(first, last) <= 0) { return(this); } else { return(new SelectionInfo(last, first, messageTextGetter)); } }
public bool Contains(CursorPosition pos) { if (pos == null) { throw new ArgumentNullException(); } if (IsEmpty) { return(false); } var normalized = this.Normalize(); return(CursorPosition.Compare(normalized.First, pos) <= 0 && CursorPosition.Compare(normalized.Last, pos) >= 0); }
async Task <List <ScreenBufferEntry> > GetSelectedDisplayMessagesEntries() { var viewLines = screenBuffer.Messages; Func <CursorPosition, bool> isGoodDisplayPosition = p => { if (p.Message == null) { return(true); } return(p.DisplayIndex >= 0 && p.DisplayIndex < viewLines.Count); }; var normSelection = selection.Normalize(); if (normSelection.IsEmpty) { return(new List <ScreenBufferEntry>()); } Func <List <ScreenBufferEntry> > defaultGet = () => { int selectedLinesCount = normSelection.Last.DisplayIndex - normSelection.First.DisplayIndex + 1; return(viewLines.Skip(normSelection.First.DisplayIndex).Take(selectedLinesCount).ToList()); }; if (isGoodDisplayPosition(normSelection.First) && isGoodDisplayPosition(normSelection.Last)) { // most common case: both positions are in the screen buffer at the moment return(defaultGet()); } CancellationToken cancellation = CancellationToken.None; IScreenBuffer tmpBuf = screenBufferFactory.CreateScreenBuffer(initialBufferPosition: InitialBufferPosition.Nowhere); await tmpBuf.SetSources(screenBuffer.Sources.Select(s => s.Source), cancellation); if (!await tmpBuf.MoveToBookmark(bookmarksFactory.CreateBookmark(normSelection.First.Message, 0), BookmarkLookupMode.ExactMatch, cancellation)) { // Impossible to load selected message into screen buffer. Rather impossible. return(defaultGet()); } var tasks = screenBuffer.Sources.Select(async sourceBuf => { var sourceMessages = new List <IMessage>(); await sourceBuf.Source.EnumMessages( tmpBuf.Sources.First(sb => sb.Source == sourceBuf.Source).Begin, m => { if (MessagesComparer.Compare(m, normSelection.Last.Message) > 0) { return(false); } sourceMessages.Add(m); return(true); }, EnumMessagesFlag.Forward, LogProviderCommandPriority.AsyncUserAction, cancellation ); return(new { Source = sourceBuf.Source, Messages = sourceMessages }); }).ToList(); await Task.WhenAll(tasks); cancellation.ThrowIfCancellationRequested(); var messagesToSource = tasks.ToDictionary( t => (IMessagesCollection) new MessagesContainers.SimpleCollection(t.Result.Messages), t => t.Result.Source); return (new MessagesContainers.SimpleMergingCollection(messagesToSource.Keys) .Forward(0, int.MaxValue) .SelectMany(m => Enumerable.Range(0, GetTextToDisplay(m.Message.Message).GetLinesCount()).Select( lineIdx => new ScreenBufferEntry() { TextLineIndex = lineIdx, Message = m.Message.Message, Source = messagesToSource[m.SourceCollection], } ) ) .TakeWhile(m => CursorPosition.Compare(CursorPosition.FromViewLine(m.ToViewLine(), 0), normSelection.Last) <= 0) .ToList()); }