Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command text removed #11

Open
CarlPrentice opened this issue Jul 4, 2016 · 1 comment
Open

Command text removed #11

CarlPrentice opened this issue Jul 4, 2016 · 1 comment

Comments

@CarlPrentice
Copy link
Contributor

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
Copy link
Contributor Author

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant