コード例 #1
0
ファイル: ReflowWider.cs プロジェクト: sgmunn/xts-test
        void ApplyNewLayout(CircularList <BufferLine> lines, int [] newLayout)
        {
            var newLayoutLines = new CircularList <BufferLine> (lines.Length);

            for (int i = 0; i < newLayout.Length; i++)
            {
                newLayoutLines.Push(lines [newLayout [i]]);
            }

            // Rearrange the list
            for (int i = 0; i < newLayoutLines.Length; i++)
            {
                lines [i] = newLayoutLines [i];
            }

            lines.Length = newLayout.Length;
        }
コード例 #2
0
ファイル: ReflowWider.cs プロジェクト: sgmunn/xts-test
        LayoutResult CreateNewLayout(CircularList <BufferLine> lines, int [] toRemove)
        {
            var layout = new CircularList <int> (lines.Length);

            // First iterate through the list and get the actual indexes to use for rows
            int nextToRemoveIndex = 0;
            int nextToRemoveStart = toRemove [nextToRemoveIndex];
            int countRemovedSoFar = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                if (nextToRemoveStart == i)
                {
                    int countToRemove = toRemove [++nextToRemoveIndex];

                    // Tell markers that there was a deletion
                    //lines.onDeleteEmitter.fire ({
                    //	index: i - countRemovedSoFar,
                    //	amount: countToRemove
                    //});

                    i += countToRemove - 1;
                    countRemovedSoFar += countToRemove;

                    nextToRemoveStart = int.MaxValue;
                    if (nextToRemoveIndex < toRemove.Length - 1)
                    {
                        nextToRemoveStart = toRemove [++nextToRemoveIndex];
                    }
                }
                else
                {
                    layout.Push(i);
                }
            }

            return(new LayoutResult()
            {
                Layout = layout.ToArray(),
                RemovedCount = countRemovedSoFar,
            });
        }
コード例 #3
0
ファイル: ReflowNarrower.cs プロジェクト: mrward/XtermSharp
        void Rearrange(List <InsertionSet> toInsert, int countToInsert)
        {
            // Rearrange lines in the buffer if there are any insertions, this is done at the end rather
            // than earlier so that it's a single O(n) pass through the buffer, instead of O(n^2) from many
            // costly calls to CircularList.splice.
            if (toInsert.Count > 0)
            {
                // Record buffer insert events and then play them back backwards so that the indexes are
                // correct
                List <int> insertEvents = new List <int> ();

                // Record original lines so they don't get overridden when we rearrange the list
                CircularList <BufferLine> originalLines = new CircularList <BufferLine> (Buffer.Lines.MaxLength);
                for (int i = 0; i < Buffer.Lines.Length; i++)
                {
                    originalLines.Push(Buffer.Lines [i]);
                }

                int originalLinesLength = Buffer.Lines.Length;

                int          originalLineIndex = originalLinesLength - 1;
                int          nextToInsertIndex = 0;
                InsertionSet nextToInsert      = toInsert [nextToInsertIndex];
                Buffer.Lines.Length = Math.Min(Buffer.Lines.MaxLength, Buffer.Lines.Length + countToInsert);

                int countInsertedSoFar = 0;
                for (int i = Math.Min(Buffer.Lines.MaxLength - 1, originalLinesLength + countToInsert - 1); i >= 0; i--)
                {
                    if (!nextToInsert.IsNull && nextToInsert.Start > originalLineIndex + countInsertedSoFar)
                    {
                        // Insert extra lines here, adjusting i as needed
                        for (int nextI = nextToInsert.Lines.Length - 1; nextI >= 0; nextI--)
                        {
                            Buffer.Lines [i--] = nextToInsert.Lines [nextI];
                        }

                        i++;

                        // Create insert events for later
                        //insertEvents.Add ({
                        //	index: originalLineIndex + 1,
                        //	amount: nextToInsert.newLines.length
                        //});

                        countInsertedSoFar += nextToInsert.Lines.Length;
                        if (nextToInsertIndex < toInsert.Count - 1)
                        {
                            nextToInsert = toInsert [++nextToInsertIndex];
                        }
                        else
                        {
                            nextToInsert = InsertionSet.Null;
                        }
                    }
                    else
                    {
                        Buffer.Lines [i] = originalLines [originalLineIndex--];
                    }
                }

                /*
                 * // Update markers
                 * let insertCountEmitted = 0;
                 * for (let i = insertEvents.length - 1; i >= 0; i--) {
                 *      insertEvents [i].index += insertCountEmitted;
                 *      this.lines.onInsertEmitter.fire (insertEvents [i]);
                 *      insertCountEmitted += insertEvents [i].amount;
                 * }
                 *
                 * const amountToTrim = Math.max (0, originalLinesLength + countToInsert - this.lines.maxLength);
                 * if (amountToTrim > 0) {
                 *      this.lines.onTrimEmitter.fire (amountToTrim);
                 * }
                 */
            }
        }