1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add text selection and copying to console

This commit is contained in:
ShadowNinja 2016-02-27 16:04:44 -05:00
parent 3edb7575a1
commit 430929e75a
3 changed files with 103 additions and 59 deletions

View file

@ -390,6 +390,7 @@ ChatPrompt::ChatPrompt(std::wstring prompt, u32 history_limit):
m_cols(0),
m_view(0),
m_cursor(0),
m_cursor_len(0),
m_nick_completion_start(0),
m_nick_completion_end(0)
{
@ -426,11 +427,6 @@ void ChatPrompt::addToHistory(std::wstring line)
m_history_index = m_history.size();
}
std::wstring ChatPrompt::getLine()
{
return m_line;
}
void ChatPrompt::clear()
{
m_line.clear();
@ -590,14 +586,12 @@ void ChatPrompt::cursorOperation(CursorOp op, CursorOpDir dir, CursorOpScope sco
s32 length = m_line.size();
s32 increment = (dir == CURSOROP_DIR_RIGHT) ? 1 : -1;
if (scope == CURSOROP_SCOPE_CHARACTER)
{
switch (scope) {
case CURSOROP_SCOPE_CHARACTER:
new_cursor += increment;
}
else if (scope == CURSOROP_SCOPE_WORD)
{
if (increment > 0)
{
break;
case CURSOROP_SCOPE_WORD:
if (dir == CURSOROP_DIR_RIGHT) {
// skip one word to the right
while (new_cursor < length && isspace(m_line[new_cursor]))
new_cursor++;
@ -605,39 +599,47 @@ void ChatPrompt::cursorOperation(CursorOp op, CursorOpDir dir, CursorOpScope sco
new_cursor++;
while (new_cursor < length && isspace(m_line[new_cursor]))
new_cursor++;
}
else
{
} else {
// skip one word to the left
while (new_cursor >= 1 && isspace(m_line[new_cursor - 1]))
new_cursor--;
while (new_cursor >= 1 && !isspace(m_line[new_cursor - 1]))
new_cursor--;
}
}
else if (scope == CURSOROP_SCOPE_LINE)
{
break;
case CURSOROP_SCOPE_LINE:
new_cursor += increment * length;
break;
case CURSOROP_SCOPE_SELECTION:
break;
}
new_cursor = MYMAX(MYMIN(new_cursor, length), 0);
if (op == CURSOROP_MOVE)
{
switch (op) {
case CURSOROP_MOVE:
m_cursor = new_cursor;
}
else if (op == CURSOROP_DELETE)
{
if (new_cursor < old_cursor)
{
m_line.erase(new_cursor, old_cursor - new_cursor);
m_cursor = new_cursor;
m_cursor_len = 0;
break;
case CURSOROP_DELETE:
if (m_cursor_len > 0) { // Delete selected text first
m_line.erase(m_cursor, m_cursor_len);
} else {
m_cursor = MYMIN(new_cursor, old_cursor);
m_line.erase(m_cursor, abs(new_cursor - old_cursor));
}
else if (new_cursor > old_cursor)
{
m_line.erase(old_cursor, new_cursor - old_cursor);
m_cursor = old_cursor;
m_cursor_len = 0;
break;
case CURSOROP_SELECT:
if (scope == CURSOROP_SCOPE_LINE) {
m_cursor = 0;
m_cursor_len = length;
} else {
m_cursor = MYMIN(new_cursor, old_cursor);
m_cursor_len += abs(new_cursor - old_cursor);
m_cursor_len = MYMIN(m_cursor_len, length - m_cursor);
}
break;
}
clampView();