Skip to content

Commit

Permalink
Add: Quick clear input-line functionality (Mudlet#7450)
Browse files Browse the repository at this point in the history
#### Brief overview of PR changes/additions

This adds functionality to handle input line clearing as described in
Issue Mudlet#7177

A user may press DOWN (with no modifiers) to quickly clear what they
have typed in the command line.

The clearing functionality will only trigger if the user is in the
middle of typing a command (nothing *selected* on the command line), and
while not navigating through their command history. This allows history
navigation and autocompletion to function as normal while allowing an
additional feature of quickly clearing the command line.

#### Motivation for adding to Mudlet

Occasionally a player may find themself in the middle of typing a
command when they wish to quickly switch to another command. Previously
the options to clear the command line and start typing again involved
either sending the unwanted command which could cause unwanted game lag
set for the player (for example a backstab command on someone not there
may result in a combat round of lag on a *miss*), or using multiple
keystrokes to select all and clear with backspace.

#### Other info (issues closed, discussion etc)
  • Loading branch information
jmckisson authored Oct 2, 2024
1 parent 0dfcf77 commit a63c0d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions src/TCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ bool TCommandLine::event(QEvent* event)
#endif
// If EXACTLY Down is pressed without modifiers (special case
// for macOs - also sets KeyPad modifier)
historyMove(MOVE_DOWN);
bool shouldClearInput = historyMove(MOVE_DOWN);

// If the user has pressed DOWN while in the middle of typing a command
// the command line should be cleared
if (shouldClearInput) {
clear();
}
ke->accept();
return true;
}
Expand Down Expand Up @@ -1117,11 +1123,16 @@ void TCommandLine::handleAutoCompletion()
// cursor up/down: turns on autocompletion mode and cycles through all possible matches
// In case nothing has been typed it cycles through the command history in
// reverse order compared to cursor down.
// If the user is currently typing in the command line, a DOWN key will indicate
// that the input line should be cleared

void TCommandLine::historyMove(MoveDirection direction)
bool TCommandLine::historyMove(MoveDirection direction)
{
bool shouldClearInput = false;

if (mHistoryList.empty()) {
return;
// If the history is empty, we may still want to clear the input line...
return true;
}
const int shift = (direction == MOVE_UP ? 1 : -1);
if ((textCursor().selectedText().size() == toPlainText().size()) || (toPlainText().isEmpty()) || !mpHost->mHighlightHistory) {
Expand All @@ -1140,10 +1151,16 @@ void TCommandLine::historyMove(MoveDirection direction)
moveCursor(QTextCursor::End);
}
} else {
mAutoCompletionCount += shift;
handleAutoCompletion();
if (direction == MOVE_DOWN && !toPlainText().isEmpty()) {
shouldClearInput = true;
} else {
mAutoCompletionCount += shift;
handleAutoCompletion();
}
}
adjustHeight();

return shouldClearInput;
}

void TCommandLine::slot_clearSelection(bool yes)
Expand Down
2 changes: 1 addition & 1 deletion src/TCommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public slots:
void spellCheck();
void fillSpellCheckList(QMouseEvent*, QMenu*);
void handleTabCompletion(bool);
void historyMove(MoveDirection);
bool historyMove(MoveDirection);
void enterCommand(QKeyEvent*);
void processNormalKey(QEvent*);
bool keybindingMatched(QKeyEvent*);
Expand Down

0 comments on commit a63c0d7

Please sign in to comment.