/// <summary> /// Returns true if this CharData matches the given Rune, irrespective of character attributes /// </summary> public bool MatchesRune(CharData chr) { return(Rune == chr.Rune); }
/// <summary> /// Evaluates and returns indexes to be removed after a reflow larger occurs. Lines will be removed /// when a wrapped line unwraps. /// </summary> /// <param name="lines">The buffer lines</param> /// <param name="oldCols">The columns before resize</param> /// <param name="newCols">The columns after resize</param> /// <param name="bufferAbsoluteY"></param> /// <param name="nullCharacter"></param> int [] GetLinesToRemove(CircularList <BufferLine> lines, int oldCols, int newCols, int bufferAbsoluteY, CharData nullCharacter) { // Gather all BufferLines that need to be removed from the Buffer here so that they can be // batched up and only committed once List <int> toRemove = new List <int> (); for (int y = 0; y < lines.Length - 1; y++) { // Check if this row is wrapped int i = y; BufferLine nextLine = lines [++i]; if (!nextLine.IsWrapped) { continue; } // Check how many lines it's wrapped for List <BufferLine> wrappedLines = new List <BufferLine> (lines.Length - y); wrappedLines.Add(lines [y]); while (i < lines.Length && nextLine.IsWrapped) { wrappedLines.Add(nextLine); nextLine = lines [++i]; } // If these lines contain the cursor don't touch them, the program will handle fixing up wrapped // lines with the cursor if (bufferAbsoluteY >= y && bufferAbsoluteY < i) { y += wrappedLines.Count - 1; continue; } // Copy buffer data to new locations int destLineIndex = 0; int destCol = GetWrappedLineTrimmedLength(Buffer.Lines, destLineIndex, oldCols); int srcLineIndex = 1; int srcCol = 0; while (srcLineIndex < wrappedLines.Count) { int srcTrimmedTineLength = GetWrappedLineTrimmedLength(wrappedLines, srcLineIndex, oldCols); int srcRemainingCells = srcTrimmedTineLength - srcCol; int destRemainingCells = newCols - destCol; int cellsToCopy = Math.Min(srcRemainingCells, destRemainingCells); wrappedLines [destLineIndex].CopyCellsFrom(wrappedLines [srcLineIndex], srcCol, destCol, cellsToCopy); destCol += cellsToCopy; if (destCol == newCols) { destLineIndex++; destCol = 0; } srcCol += cellsToCopy; if (srcCol == srcTrimmedTineLength) { srcLineIndex++; srcCol = 0; } // Make sure the last cell isn't wide, if it is copy it to the current dest if (destCol == 0 && destLineIndex != 0) { if (wrappedLines [destLineIndex - 1].GetWidth(newCols - 1) == 2) { wrappedLines [destLineIndex].CopyCellsFrom(wrappedLines [destLineIndex - 1], newCols - 1, destCol++, 1); // Null out the end of the last row wrappedLines [destLineIndex - 1].ReplaceCells(newCols - 1, 1, nullCharacter); } } } // Clear out remaining cells or fragments could remain; wrappedLines [destLineIndex].ReplaceCells(destCol, newCols, nullCharacter); // Work backwards and remove any rows at the end that only contain null cells int countToRemove = 0; for (int ix = wrappedLines.Count - 1; ix > 0; ix--) { if (ix > destLineIndex || wrappedLines [ix].GetTrimmedLength() == 0) { countToRemove++; } else { break; } } if (countToRemove > 0) { toRemove.Add(y + wrappedLines.Count - countToRemove); // index toRemove.Add(countToRemove); } y += wrappedLines.Count - 1; } return(toRemove.ToArray()); }