can move right by word
This commit is contained in:
parent
4da9094dd6
commit
14cbd1335b
|
@ -737,72 +737,11 @@ COORD CommandLine::_moveCursorLeft(CookedRead& cookedReadData)
|
|||
// - The new cursor position
|
||||
COORD CommandLine::_moveCursorRightByWord(CookedRead& cookedReadData) noexcept
|
||||
{
|
||||
return cookedReadData.PromptStartLocation();
|
||||
/*
|
||||
COORD cursorPosition = cookedReadData.ScreenInfo().GetTextBuffer().GetCursor().GetPosition();
|
||||
if (cookedReadData.InsertionPoint() < (cookedReadData.BytesRead() / sizeof(WCHAR)))
|
||||
{
|
||||
PWCHAR NextWord = cookedReadData.BufferCurrentPtr();
|
||||
|
||||
// A bit better word skipping.
|
||||
PWCHAR BufLast = cookedReadData.BufferStartPtr() + cookedReadData.BytesRead() / sizeof(WCHAR);
|
||||
|
||||
FAIL_FAST_IF(!(NextWord < BufLast));
|
||||
if (*NextWord == L' ')
|
||||
{
|
||||
// If the current character is space, skip to the next non-space character.
|
||||
while (NextWord < BufLast)
|
||||
{
|
||||
if (*NextWord != L' ')
|
||||
{
|
||||
break;
|
||||
}
|
||||
++NextWord;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip the body part.
|
||||
bool fStartFromDelim = IsWordDelim(*NextWord);
|
||||
|
||||
while (++NextWord < BufLast)
|
||||
{
|
||||
if (fStartFromDelim != IsWordDelim(*NextWord))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip the space block.
|
||||
if (NextWord < BufLast && *NextWord == L' ')
|
||||
{
|
||||
while (++NextWord < BufLast)
|
||||
{
|
||||
if (*NextWord != L' ')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cookedReadData.SetBufferCurrentPtr(NextWord);
|
||||
cookedReadData.InsertionPoint() = (ULONG)(cookedReadData.BufferCurrentPtr() - cookedReadData.BufferStartPtr());
|
||||
cursorPosition = cookedReadData.OriginalCursorPosition();
|
||||
cursorPosition.X = (SHORT)(cursorPosition.X +
|
||||
RetrieveTotalNumberOfSpaces(cookedReadData.OriginalCursorPosition().X,
|
||||
cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.InsertionPoint()));
|
||||
const SHORT sScreenBufferSizeX = cookedReadData.ScreenInfo().GetBufferSize().Width();
|
||||
if (CheckBisectStringW(cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.InsertionPoint() + 1,
|
||||
sScreenBufferSizeX - cookedReadData.OriginalCursorPosition().X))
|
||||
{
|
||||
cursorPosition.X++;
|
||||
}
|
||||
}
|
||||
const size_t cellsMoved = cookedReadData.MoveInsertionIndexRightByWord();
|
||||
// the cursor is adjusted to be within the bounds of the screen later, don't need to worry about it here
|
||||
cursorPosition.X += gsl::narrow<short>(cellsMoved);
|
||||
return cursorPosition;
|
||||
*/
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
|
|
@ -118,7 +118,7 @@ size_t CookedRead::_visibleCharCountOf(const std::wstring_view wstrView)
|
|||
size_t CookedRead::MoveInsertionIndexLeft()
|
||||
{
|
||||
// check if there's anything to the left to
|
||||
if (_insertionIndex == 0)
|
||||
if (_isInsertionIndexAtPromptBegin())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -152,13 +152,14 @@ size_t CookedRead::MoveInsertionIndexLeft()
|
|||
|
||||
// Routine Description:
|
||||
// - moves the insertion index one codepoint to the right if possible
|
||||
// right beyond the end of the current prompt text
|
||||
// Return Value:
|
||||
// - returns the number of cells that the move operation passed over
|
||||
size_t CookedRead::MoveInsertionIndexRight()
|
||||
{
|
||||
// check if we're at the far right side of the prompt text for character insertion from last command in
|
||||
// the history
|
||||
if (_insertionIndex >= _prompt.size())
|
||||
if (_isInsertionIndexAtPromptEnd())
|
||||
{
|
||||
// if we have any command history, grab the nth next character from the previous command and write it
|
||||
// to the buffer, then move over it
|
||||
|
@ -243,19 +244,19 @@ size_t CookedRead::MoveInsertionIndexToEnd()
|
|||
// - the number of cells that the insertion point has moved by
|
||||
size_t CookedRead::MoveInsertionIndexLeftByWord()
|
||||
{
|
||||
if (_insertionIndex == 0)
|
||||
if (_isInsertionIndexAtPromptBegin())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t cellsMoved = 0;
|
||||
// move through any word delimiters to the left
|
||||
while (_insertionIndex > 0 && IsWordDelim(_prompt.at(_insertionIndex - 1)))
|
||||
while (!_isInsertionIndexAtPromptBegin() && IsWordDelim(_prompt.at(_insertionIndex - 1)))
|
||||
{
|
||||
cellsMoved += MoveInsertionIndexLeft();
|
||||
}
|
||||
// move through word to next word delimiter
|
||||
while (_insertionIndex > 0 && !IsWordDelim(_prompt.at(_insertionIndex - 1)))
|
||||
while (!_isInsertionIndexAtPromptBegin() && !IsWordDelim(_prompt.at(_insertionIndex - 1)))
|
||||
{
|
||||
cellsMoved += MoveInsertionIndexLeft();
|
||||
}
|
||||
|
@ -263,6 +264,35 @@ size_t CookedRead::MoveInsertionIndexLeftByWord()
|
|||
return cellsMoved;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - moves insertion index to the right by a word
|
||||
// Return Value:
|
||||
// - the number of cells that the insertion point has moved by
|
||||
size_t CookedRead::MoveInsertionIndexRightByWord()
|
||||
{
|
||||
if (_isInsertionIndexAtPromptEnd())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t cellsMoved = 0;
|
||||
if (!IsWordDelim(_prompt.at(_insertionIndex)))
|
||||
{
|
||||
// move through a word until we come to the first word delimiter
|
||||
while (!_isInsertionIndexAtPromptEnd() && !IsWordDelim(_prompt.at(_insertionIndex)))
|
||||
{
|
||||
cellsMoved += MoveInsertionIndexRight();
|
||||
}
|
||||
}
|
||||
// move through word delimiters until we encounter a char that isn't one
|
||||
while (!_isInsertionIndexAtPromptEnd() && IsWordDelim(_prompt.at(_insertionIndex)))
|
||||
{
|
||||
cellsMoved += MoveInsertionIndexRight();
|
||||
}
|
||||
|
||||
return cellsMoved;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - checks if wch matches up with the control character masking for early data return
|
||||
// Arguments:
|
||||
|
@ -693,3 +723,22 @@ bool CookedRead::_isSurrogatePairAt(const std::wstring_view wstrView, const size
|
|||
return (Utf16Parser::IsLeadingSurrogate(wstrView.at(index)) &&
|
||||
Utf16Parser::IsTrailingSurrogate(wstrView.at(index + 1)));
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - checks if insertion index is at the far left end of the prompt
|
||||
// Return Value:
|
||||
// - true if insertion index is at the beginning of the prompt, false otherwise
|
||||
bool CookedRead::_isInsertionIndexAtPromptBegin()
|
||||
{
|
||||
return _insertionIndex == 0;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - checks if insertion index is at the far right end of the prompt
|
||||
// Return Value:
|
||||
// - true if insertion index is at the end of the prompt, false otherwise
|
||||
bool CookedRead::_isInsertionIndexAtPromptEnd()
|
||||
{
|
||||
FAIL_FAST_IF(_insertionIndex > _prompt.size());
|
||||
return _insertionIndex == _prompt.size();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void MoveInsertionIndexToStart() noexcept;
|
||||
size_t MoveInsertionIndexToEnd();
|
||||
size_t MoveInsertionIndexLeftByWord();
|
||||
size_t MoveInsertionIndexRightByWord();
|
||||
|
||||
SCREEN_INFORMATION& ScreenInfo();
|
||||
|
||||
|
@ -110,4 +111,7 @@ private:
|
|||
void _writeToScreen(const bool resetCursor);
|
||||
|
||||
size_t _calculatePromptCellLength(const bool wholePrompt) const;
|
||||
|
||||
bool _isInsertionIndexAtPromptBegin();
|
||||
bool _isInsertionIndexAtPromptEnd();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue