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

Remove some unused TextBuffer methods #17443

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 0 additions & 202 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,38 +373,6 @@ TextBufferCellIterator TextBuffer::GetCellDataAt(const til::point at, const View
return TextBufferCellIterator(*this, at, limit);
}

//Routine Description:
// - Call before inserting a character into the buffer.
// - This will ensure a consistent double byte state (KAttrs line) within the text buffer
// - It will attempt to correct the buffer if we're inserting an unexpected double byte character type
// and it will pad out the buffer if we're going to split a double byte sequence across two rows.
//Arguments:
// - dbcsAttribute - Double byte information associated with the character about to be inserted into the buffer
//Return Value:
// - true if we successfully prepared the buffer and moved the cursor
// - false otherwise (out of memory)
void TextBuffer::_PrepareForDoubleByteSequence(const DbcsAttribute dbcsAttribute)
{
// Now compensate if we don't have enough space for the upcoming double byte sequence
// We only need to compensate for leading bytes
if (dbcsAttribute == DbcsAttribute::Leading)
{
const auto cursorPosition = GetCursor().GetPosition();
const auto lineWidth = GetLineWidth(cursorPosition.y);

// If we're about to lead on the last column in the row, we need to add a padding space
if (cursorPosition.x == lineWidth - 1)
{
// set that we're wrapping for double byte reasons
auto& row = GetMutableRowByOffset(cursorPosition.y);
row.SetDoubleBytePadded(true);

// then move the cursor forward and onto the next row
IncrementCursor();
}
}
}

// Given the character offset `position` in the `chars` string, this function returns the starting position of the next grapheme.
// For instance, given a `chars` of L"x\uD83D\uDE42y" and a `position` of 1 it'll return 3.
// GraphemePrev would do the exact inverse of this operation.
Expand Down Expand Up @@ -740,144 +708,6 @@ OutputCellIterator TextBuffer::WriteLine(const OutputCellIterator givenIt,
return newIt;
}

//Routine Description:
// - Inserts one codepoint into the buffer at the current cursor position and advances the cursor as appropriate.
//Arguments:
// - chars - The codepoint to insert
// - dbcsAttribute - Double byte information associated with the codepoint
// - bAttr - Color data associated with the character
//Return Value:
// - true if we successfully inserted the character
// - false otherwise (out of memory)
void TextBuffer::InsertCharacter(const std::wstring_view chars,
const DbcsAttribute dbcsAttribute,
const TextAttribute attr)
{
// Ensure consistent buffer state for double byte characters based on the character type we're about to insert
_PrepareForDoubleByteSequence(dbcsAttribute);

// Get the current cursor position
const auto iRow = GetCursor().GetPosition().y; // row stored as logical position, not array position
const auto iCol = GetCursor().GetPosition().x; // column logical and array positions are equal.

// Get the row associated with the given logical position
auto& Row = GetMutableRowByOffset(iRow);

// Store character and double byte data
switch (dbcsAttribute)
{
case DbcsAttribute::Leading:
Row.ReplaceCharacters(iCol, 2, chars);
break;
case DbcsAttribute::Trailing:
Row.ReplaceCharacters(iCol - 1, 2, chars);
break;
default:
Row.ReplaceCharacters(iCol, 1, chars);
break;
}

// Store color data
Row.SetAttrToEnd(iCol, attr);
IncrementCursor();
}

//Routine Description:
// - Inserts one ucs2 codepoint into the buffer at the current cursor position and advances the cursor as appropriate.
//Arguments:
// - wch - The codepoint to insert
// - dbcsAttribute - Double byte information associated with the codepoint
// - bAttr - Color data associated with the character
//Return Value:
// - true if we successfully inserted the character
// - false otherwise (out of memory)
void TextBuffer::InsertCharacter(const wchar_t wch, const DbcsAttribute dbcsAttribute, const TextAttribute attr)
{
InsertCharacter({ &wch, 1 }, dbcsAttribute, attr);
}

//Routine Description:
// - Finds the current row in the buffer (as indicated by the cursor position)
// and specifies that we have forced a line wrap on that row
//Arguments:
// - <none> - Always sets to wrap
//Return Value:
// - <none>
void TextBuffer::_SetWrapOnCurrentRow()
{
_AdjustWrapOnCurrentRow(true);
}

//Routine Description:
// - Finds the current row in the buffer (as indicated by the cursor position)
// and specifies whether or not it should have a line wrap flag.
//Arguments:
// - fSet - True if this row has a wrap. False otherwise.
//Return Value:
// - <none>
void TextBuffer::_AdjustWrapOnCurrentRow(const bool fSet)
{
// The vertical position of the cursor represents the current row we're manipulating.
const auto uiCurrentRowOffset = GetCursor().GetPosition().y;

// Set the wrap status as appropriate
GetMutableRowByOffset(uiCurrentRowOffset).SetWrapForced(fSet);
}

//Routine Description:
// - Increments the cursor one position in the buffer as if text is being typed into the buffer.
// - NOTE: Will introduce a wrap marker if we run off the end of the current row
//Arguments:
// - <none>
//Return Value:
// - true if we successfully moved the cursor.
// - false otherwise (out of memory)
void TextBuffer::IncrementCursor()
{
// Cursor position is stored as logical array indices (starts at 0) for the window
// Buffer Size is specified as the "length" of the array. It would say 80 for valid values of 0-79.
// So subtract 1 from buffer size in each direction to find the index of the final column in the buffer
const auto iFinalColumnIndex = GetLineWidth(GetCursor().GetPosition().y) - 1;

// Move the cursor one position to the right
GetCursor().IncrementXPosition(1);

// If we've passed the final valid column...
if (GetCursor().GetPosition().x > iFinalColumnIndex)
{
// Then mark that we've been forced to wrap
_SetWrapOnCurrentRow();

// Then move the cursor to a new line
NewlineCursor();
}
}

//Routine Description:
// - Increments the cursor one line down in the buffer and to the beginning of the line
//Arguments:
// - <none>
//Return Value:
// - true if we successfully moved the cursor.
void TextBuffer::NewlineCursor()
{
const auto iFinalRowIndex = GetSize().BottomInclusive();

// Reset the cursor position to 0 and move down one line
GetCursor().SetXPosition(0);
GetCursor().IncrementYPosition(1);

// If we've passed the final valid row...
if (GetCursor().GetPosition().y > iFinalRowIndex)
{
// Stay on the final logical/offset row of the buffer.
GetCursor().SetYPosition(iFinalRowIndex);

// Instead increment the circular buffer to move us into the "oldest" row of the backing buffer
IncrementCircularBuffer();
}
}

//Routine Description:
// - Increments the circular buffer by one. Circular buffer is represented by FirstRow variable.
//Arguments:
Expand Down Expand Up @@ -954,38 +784,6 @@ til::point TextBuffer::GetLastNonSpaceCharacter(const Viewport* viewOptional) co
return coordEndOfText;
}

// Routine Description:
// - Retrieves the position of the previous character relative to the current cursor position
// Arguments:
// - <none>
// Return Value:
// - Coordinate position in screen coordinates of the character just before the cursor.
// - NOTE: Will return 0,0 if already in the top left corner
til::point TextBuffer::_GetPreviousFromCursor() const
{
auto coordPosition = GetCursor().GetPosition();

// If we're not at the left edge, simply move the cursor to the left by one
if (coordPosition.x > 0)
{
coordPosition.x--;
}
else
{
// Otherwise, only if we're not on the top row (e.g. we don't move anywhere in the top left corner. there is no previous)
if (coordPosition.y > 0)
{
// move the cursor up one line
coordPosition.y--;

// and to the right edge
coordPosition.x = GetLineWidth(coordPosition.y) - 1;
}
}

return coordPosition;
}

const til::CoordType TextBuffer::GetFirstRowIndex() const noexcept
{
return _firstRow;
Expand Down
10 changes: 0 additions & 10 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ class TextBuffer final
const std::optional<bool> setWrap = std::nullopt,
const std::optional<til::CoordType> limitRight = std::nullopt);

void InsertCharacter(const wchar_t wch, const DbcsAttribute dbcsAttribute, const TextAttribute attr);
void InsertCharacter(const std::wstring_view chars, const DbcsAttribute dbcsAttribute, const TextAttribute attr);
void IncrementCursor();
void NewlineCursor();

// Scroll needs access to this to quickly rotate around the buffer.
void IncrementCircularBuffer(const TextAttribute& fillAttributes = {});

Expand Down Expand Up @@ -322,11 +317,6 @@ class TextBuffer final
til::CoordType _estimateOffsetOfLastCommittedRow() const noexcept;

void _SetFirstRowIndex(const til::CoordType FirstRowIndex) noexcept;
til::point _GetPreviousFromCursor() const;
void _SetWrapOnCurrentRow();
void _AdjustWrapOnCurrentRow(const bool fSet);
// Assist with maintaining proper buffer state for Double Byte character sequences
void _PrepareForDoubleByteSequence(const DbcsAttribute dbcsAttribute);
void _ExpandTextRow(til::inclusive_rect& selectionRow) const;
DelimiterClass _GetDelimiterClassAt(const til::point pos, const std::wstring_view wordDelimiters) const;
til::point _GetWordStartForAccessibility(const til::point target, const std::wstring_view wordDelimiters) const;
Expand Down
Loading
Loading