Esempio n. 1
0
        private CommitPosition TryGetSelectedCommitPosition()
        {
            Commit selected = (SelectedItem as CommitViewModel)?.Commit;
            int    index    = -1;

            if (selected != null)
            {
                index = Commits.FindIndex(c => c.Commit.Id == selected.Id);
            }

            if (selected != null && index != -1)
            {
                return(new CommitPosition(selected, index));
            }

            return(null);
        }
Esempio n. 2
0
        private void TrySetSelectedCommitPosition(
            CommitPosition commitPosition, bool ignoreTopIndex = false)
        {
            if (commitPosition != null)
            {
                if (!ignoreTopIndex && commitPosition.Index == 0)
                {
                    // The index was 0 (top) lest ensure the index remains 0 again
                    Log.Debug("Scroll to 0 since first position was 0");
                    ScrollTo(0);
                    if (Commits.Any())
                    {
                        SelectedIndex = 0;
                        SelectedItem  = Commits.First();
                    }

                    return;
                }

                Commit selected = commitPosition.Commit;

                int indexAfter = Commits.FindIndex(c => c.Commit.Id == selected.Id);

                if (selected != null && indexAfter != -1)
                {
                    int indexBefore = commitPosition.Index;
                    ScrollRows(indexBefore - indexAfter);
                    SelectedIndex = indexAfter;
                    SelectedItem  = Commits[indexAfter];
                    return;
                }
            }

            ScrollTo(0);
            if (Commits.Any())
            {
                SelectedIndex = 0;
                SelectedItem  = Commits.First();
            }
        }