Skip to content

Commit 18adf24

Browse files
authored
In text editor, fix behaviour of Home and End keys (#836)
## Usage and product changes The behaviour of Home and End keys are now in line with most other text editors, moving to the start/end of the line (rather than the file) unless Ctrl (Cmd on MacOS) is additionally pressed. ## Implementation We had some confusing terminology in the `Command` class - `MOVE_HOME` and `MOVE_END` intuitively sounded like they should correspond to a keyboard's Home and End keys, but this resulted in incorrect behaviour. We've renamed them to `MOVE_CONTENT_START` and `MOVE_CONTENT_END`, and these are now correctly only triggered by Ctrl+Home and Ctrl+End respectively. Home and End take you to the start/end of a line. If Shift is additionally pressed in any case, trigger selection.
1 parent 60aea7b commit 18adf24

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

framework/common/KeyMapper.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ interface KeyMapper {
4646
MOVE_LINE_DOWN,
4747
MOVE_PAGE_UP,
4848
MOVE_PAGE_DOWN,
49-
MOVE_HOME,
50-
MOVE_END,
49+
MOVE_CONTENT_START,
50+
MOVE_CONTENT_END,
5151

5252
SELECT_NONE,
5353
SELECT_ALL,
@@ -65,8 +65,8 @@ interface KeyMapper {
6565
SELECT_LINE_DOWN,
6666
SELECT_PAGE_UP,
6767
SELECT_PAGE_DOWN,
68-
SELECT_HOME,
69-
SELECT_END,
68+
SELECT_CONTENT_START,
69+
SELECT_CONTENT_END,
7070

7171
DELETE_CHAR_PREV,
7272
DELETE_CHAR_NEXT,
@@ -170,6 +170,8 @@ interface KeyMapper {
170170
Keys.DirectionRight -> Command.SELECT_LINE_RIGHT
171171
Keys.DirectionUp -> Command.REORDER_LINES_UP
172172
Keys.DirectionDown -> Command.REORDER_LINES_DOWN
173+
Keys.MoveHome -> Command.SELECT_CONTENT_START
174+
Keys.MoveEnd -> Command.SELECT_CONTENT_END
173175
else -> null
174176
}
175177
shortcutModifier(event) -> when (event.key) {
@@ -188,6 +190,8 @@ interface KeyMapper {
188190
Keys.Equals -> Command.TEXT_SIZE_INCREASE
189191
Keys.Minus -> Command.TEXT_SIZE_DECREASE
190192
Keys.Zero -> Command.TEXT_SIZE_RESET
193+
Keys.MoveHome -> Command.MOVE_CONTENT_START
194+
Keys.MoveEnd -> Command.MOVE_CONTENT_END
191195
else -> null
192196
}
193197
event.isCtrlPressed && event.isShiftPressed -> when (event.key) {
@@ -212,8 +216,8 @@ interface KeyMapper {
212216
Keys.DirectionDown -> Command.SELECT_LINE_DOWN
213217
Keys.PageUp -> Command.SELECT_PAGE_UP
214218
Keys.PageDown -> Command.SELECT_PAGE_DOWN
215-
Keys.MoveHome -> Command.SELECT_HOME
216-
Keys.MoveEnd -> Command.SELECT_END
219+
Keys.MoveHome -> Command.SELECT_LINE_START
220+
Keys.MoveEnd -> Command.SELECT_LINE_END
217221
Keys.Insert -> Command.PASTE
218222
Keys.Tab -> Command.TAB_SHIFT
219223
Keys.Enter, Keys.EnterNumPad -> Command.ENTER_SHIFT
@@ -226,8 +230,8 @@ interface KeyMapper {
226230
Keys.DirectionDown -> Command.MOVE_LINE_DOWN
227231
Keys.PageUp -> Command.MOVE_PAGE_UP
228232
Keys.PageDown -> Command.MOVE_PAGE_DOWN
229-
Keys.MoveHome -> Command.MOVE_HOME
230-
Keys.MoveEnd -> Command.MOVE_END
233+
Keys.MoveHome -> Command.MOVE_LINE_START
234+
Keys.MoveEnd -> Command.MOVE_LINE_END
231235
Keys.Enter, Keys.EnterNumPad -> Command.ENTER
232236
Keys.Backspace -> Command.DELETE_CHAR_PREV
233237
Keys.Delete -> Command.DELETE_CHAR_NEXT
@@ -288,8 +292,8 @@ interface KeyMapper {
288292
event.isMetaPressed -> when (event.key) {
289293
Keys.DirectionLeft -> Command.MOVE_LINE_LEFT
290294
Keys.DirectionRight -> Command.MOVE_LINE_RIGHT
291-
Keys.DirectionUp -> Command.MOVE_HOME
292-
Keys.DirectionDown -> Command.MOVE_END
295+
Keys.DirectionUp -> Command.MOVE_CONTENT_START
296+
Keys.DirectionDown -> Command.MOVE_CONTENT_END
293297
Keys.Backspace -> Command.DELETE_LINE_START
294298
Keys.Q -> Command.QUIT
295299
Keys.R -> Command.REPLACE

framework/editor/EventHandler.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.ENTER_SHIFT
3232
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOD_ENTER
3333
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_CHAR_LEFT
3434
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_CHAR_RIGHT
35-
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_END
36-
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_HOME
35+
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_CONTENT_END
36+
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_CONTENT_START
3737
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_LINE_DOWN
3838
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_LINE_END
3939
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.MOVE_LINE_LEFT
@@ -53,8 +53,8 @@ import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.REORDER_LINE
5353
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_ALL
5454
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_CHAR_LEFT
5555
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_CHAR_RIGHT
56-
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_END
57-
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_HOME
56+
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_CONTENT_END
57+
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_CONTENT_START
5858
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_LINE_DOWN
5959
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_LINE_END
6060
import com.vaticle.typedb.studio.framework.common.KeyMapper.Command.SELECT_LINE_LEFT
@@ -123,8 +123,8 @@ internal class EventHandler constructor(
123123
MOVE_LINE_DOWN -> target.moveCursorDownByLine()
124124
MOVE_PAGE_UP -> target.moveCursorUpByPage()
125125
MOVE_PAGE_DOWN -> target.moveCursorDownByPage()
126-
MOVE_HOME -> target.moveCursorToStartOfContent()
127-
MOVE_END -> target.moveCursorToEndOfContent()
126+
MOVE_CONTENT_START -> target.moveCursorToStartOfContent()
127+
MOVE_CONTENT_END -> target.moveCursorToEndOfContent()
128128
SELECT_CHAR_LEFT -> target.moveCursorPrevByChar(true) // because we only display left to right
129129
SELECT_CHAR_RIGHT -> target.moveCursorNextByChar(true) // because we only display left to right
130130
SELECT_WORD_LEFT -> target.moveCursorPrevByWord(true) // because we only display left to right
@@ -139,8 +139,8 @@ internal class EventHandler constructor(
139139
SELECT_LINE_DOWN -> target.moveCursorDownByLine(true)
140140
SELECT_PAGE_UP -> target.moveCursorUpByPage(true)
141141
SELECT_PAGE_DOWN -> target.moveCursorDownByPage(true)
142-
SELECT_HOME -> target.moveCursorToStartOfContent(true)
143-
SELECT_END -> target.moveCursorToEndOfContent(true)
142+
SELECT_CONTENT_START -> target.moveCursorToStartOfContent(true)
143+
SELECT_CONTENT_END -> target.moveCursorToEndOfContent(true)
144144
SELECT_ALL -> target.selectAll()
145145
SELECT_NONE -> target.selectNone()
146146
REORDER_LINES_UP -> processor.reorderLinesUp()

0 commit comments

Comments
 (0)