diff --git a/src/ui/textedit.cpp b/src/ui/textedit.cpp index a300b6ee2..c6482ec7d 100644 --- a/src/ui/textedit.cpp +++ b/src/ui/textedit.cpp @@ -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 @@ -228,10 +228,28 @@ bool TextEdit::onKeyDown(const KeyMessage* keyMessage) const Caret prevCaret(m_caret); 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 kKeyLeft: m_caret.left(byWord); break; + case kKeyRight: m_caret.right(byWord); 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) diff --git a/src/ui/textedit.h b/src/ui/textedit.h index 5f936649d..d3696bec0 100644 --- a/src/ui/textedit.h +++ b/src/ui/textedit.h @@ -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;