mirror of https://github.com/aseprite/aseprite.git
Fix End key to go to EOL and added Ctrl+Home/End to go to BOF/EOF
This commit is contained in:
parent
7e4b310a42
commit
d1f010cc47
|
@ -1,5 +1,5 @@
|
|||
// Aseprite
|
||||
// Copyright (C) 2024 Igara Studio S.A.
|
||||
// Copyright (C) 2024-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
|
@ -230,8 +230,26 @@ bool TextEdit::onKeyDown(const KeyMessage* keyMessage)
|
|||
switch (scancode) {
|
||||
case kKeyLeft: m_caret.left(byWord); break;
|
||||
case kKeyRight: m_caret.right(byWord); break;
|
||||
case kKeyHome: m_caret.setPos(0); break;
|
||||
case kKeyEnd: m_caret.set(m_lines.back().i, m_lines.back().glyphCount); break;
|
||||
case kKeyHome:
|
||||
// Beginning of text
|
||||
if (keyMessage->ctrlPressed()) {
|
||||
m_caret.set(0, 0);
|
||||
}
|
||||
// Beginning of line
|
||||
else {
|
||||
m_caret.setPos(0);
|
||||
}
|
||||
break;
|
||||
case kKeyEnd:
|
||||
// End of text
|
||||
if (keyMessage->ctrlPressed()) {
|
||||
m_caret.set(m_lines.back().i, m_lines.back().glyphCount);
|
||||
}
|
||||
// End of line
|
||||
else {
|
||||
m_caret.eol();
|
||||
}
|
||||
break;
|
||||
case kKeyUp: m_caret.up(); break;
|
||||
case kKeyDown: m_caret.down(); break;
|
||||
case kKeyEnter:
|
||||
|
@ -956,6 +974,11 @@ void TextEdit::Caret::down()
|
|||
m_pos = std::clamp(m_pos, size_t(0), lineObj().glyphCount);
|
||||
}
|
||||
|
||||
void TextEdit::Caret::eol()
|
||||
{
|
||||
m_pos = lineObj().glyphCount;
|
||||
}
|
||||
|
||||
size_t TextEdit::Caret::absolutePos() const
|
||||
{
|
||||
if (m_pos == 0 && m_line == 0)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Aseprite
|
||||
// Copyright (C) 2024 Igara Studio S.A.
|
||||
// Copyright (C) 2024-2025 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
|
@ -93,6 +93,9 @@ private:
|
|||
bool isLastInLine() const { return m_pos == lineObj().glyphCount; }
|
||||
bool isLastLine() const { return m_line == m_lines->size() - 1; }
|
||||
|
||||
// Go to the end of line.
|
||||
void eol();
|
||||
|
||||
// Returns the absolute position of the caret, aka the position in the main string that has all
|
||||
// the newlines.
|
||||
size_t absolutePos() const;
|
||||
|
|
Loading…
Reference in New Issue