Simple.Wpf.Terminal icon indicating copy to clipboard operation
Simple.Wpf.Terminal copied to clipboard

Command text removed

Open CarlPrentice opened this issue 8 years ago • 1 comments

If command text is present after the prompt when items are added to the ItemsSource, the text is removed from after the prompt and placed in front of the item added. This means if data is added at regular intervals from an asynchronous source, the command text can become corrupted whist typing, before the return key is hit.

CarlPrentice avatar Jul 04 '16 14:07 CarlPrentice

Hacking some code yields the desired effect for my issue (probably could be done better):

    private void AddItems(object[] items)
    {
        Contract.Requires(items != null);

        // added
        var command = AggregateAfterPrompt();
        ClearAfterPrompt();

        _paragraph.Inlines.Remove(_promptInline);

        var inlines = items.SelectMany(x =>
        {
            var value = ExtractValue(x);

            var newInlines = new List<Inline>();
            using (var reader = new StringReader(value))
            {
                var line = reader.ReadLine();

                newInlines.Add(new Run(line) { Foreground = GetForegroundColor(x) });
                newInlines.Add(new LineBreak());
            }

            return newInlines;

        }).ToArray();

        _paragraph.Inlines.AddRange(inlines);

        AddPrompt();

        // added
        _paragraph.Inlines.Add(new Run(command));

        CaretPosition = CaretPosition.DocumentEnd;
    }

CarlPrentice avatar Jul 04 '16 18:07 CarlPrentice