Skip to content

Commit 17b8fc8

Browse files
author
Joachim Meyer
committed
Home and End button don't scroll the Texteditor up and down, but let the cursor jump to the front / end of the line. (works with selection too)
1 parent 7317c1f commit 17b8fc8

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

Core/Contents/Include/PolyInputKeys.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ namespace Polycode {
232232
KEY_LEFT = 276,
233233
KEY_INSERT = 277,
234234
KEY_HOME = 278,
235-
KEY_END = 279,
235+
KEY_END = 279,
236236
KEY_PAGEUP = 280,
237-
KEY_PAGEDOWN = 281,
237+
KEY_PAGEDOWN = 281,
238238

239239
/* Function keys */
240240
KEY_F1 = 282,

Modules/Contents/UI/Source/PolyUITextInput.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,17 +1850,43 @@ void UITextInput::onKeyDown(PolyKEY key, wchar_t charCode) {
18501850
}
18511851

18521852
if(key == KEY_HOME) {
1853-
if(multiLine) {
1854-
scrollContainer->setScrollValue(0, 0);
1855-
1853+
if (actualCaretPosition < lines[actualLineOffset].text.length() || lineOffset + 1 < lines.size()) {
1854+
if (input->getKeyState(KEY_LSHIFT) || input->getKeyState(KEY_RSHIFT)) {
1855+
// Holding down shift allows you to select with the arrow keys.
1856+
if (hasSelection) {
1857+
setSelection(actualLineOffset, selectionLine, actualCaretPosition, 0);
1858+
} else {
1859+
setSelection(actualLineOffset, actualLineOffset, actualCaretPosition, 0);
1860+
}
1861+
} else {
1862+
clearSelection();
1863+
1864+
int newLineEnd = actualLineOffset;
1865+
actualCaretPosition = 0;
1866+
actualLineOffset = newLineEnd;
1867+
}
1868+
updateCaretPosition();
18561869
}
18571870
return;
18581871
}
18591872

18601873
if(key == KEY_END) {
1861-
if(multiLine) {
1862-
scrollContainer->setScrollValue(0, 1);
1863-
1874+
if (actualCaretPosition < lines[actualLineOffset].text.length() || lineOffset + 1 < lines.size()) {
1875+
if (input->getKeyState(KEY_LSHIFT) || input->getKeyState(KEY_RSHIFT)) {
1876+
// Holding down shift allows you to select with the arrow keys.
1877+
if (hasSelection) {
1878+
setSelection(actualLineOffset, selectionLine, actualCaretPosition, lines[selectionLine].text.length());
1879+
} else {
1880+
setSelection(actualLineOffset, actualLineOffset, actualCaretPosition, lines[actualLineOffset].text.length());
1881+
}
1882+
} else {
1883+
clearSelection();
1884+
1885+
int newLineEnd = actualLineOffset;
1886+
actualCaretPosition = lines[actualLineOffset].text.length();
1887+
actualLineOffset = newLineEnd;
1888+
}
1889+
updateCaretPosition();
18641890
}
18651891
return;
18661892
}

0 commit comments

Comments
 (0)