Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit da7393f

Browse files
committed
fix(plugins/plugin-client-common): improve platform compatibility of Home and End keys
This PR addresses both shift+Home/End behavior on macOS, and Home/End behavior on Linux/Windows. In both cases, Kui's behavior should now match that of the platform terminal. Note: browsers on macOS seem to interpret shift+Home as meaning "select all to beginning of line", whereas macOS Terminal interprets shift+Home to mean "move caret to beginning of line". Thus, Kui still (for darwin only) needs to override the default behavior, though just for this one case. Fixes #3267
1 parent 4e026b5 commit da7393f

File tree

1 file changed

+7
-16
lines changed
  • plugins/plugin-client-common/src/components/Views/Terminal/Block

1 file changed

+7
-16
lines changed

plugins/plugin-client-common/src/components/Views/Terminal/Block/OnKeyDown.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const setCaretPosition = (ctrl: HTMLInputElement, pos: number) => {
5353
}
5454
}
5555

56+
const setCaretPositionToStart = (input: HTMLInputElement) => setCaretPosition(input, 0)
5657
const setCaretPositionToEnd = (input: HTMLInputElement) => setCaretPosition(input, input.value.length)
5758

5859
/** Update the given input to reflect the given HistoryLine */
@@ -161,22 +162,12 @@ export default function onKeyDown(this: Input, event: KeyboardEvent) {
161162
// restore the prompt cursor position
162163
// debug('restoring cursor position', currentCursorPosition)
163164
// getCurrentPrompt().setSelectionRange(currentCursorPosition, currentCursorPosition)
164-
} else if (char === KeyCodes.HOME) {
165-
// go to first command in history
166-
setTimeout(async () => {
167-
const historyModel = await (await import('@kui-shell/core')).History(tab)
168-
const entry = historyModel.first()
169-
if (entry) {
170-
updateInputAndMoveCaretToEOL(this, entry)
171-
}
172-
})
173-
} else if (char === KeyCodes.END) {
174-
// go to last command in history
175-
setTimeout(async () => {
176-
const historyModel = await (await import('@kui-shell/core')).History(tab)
177-
const entry = historyModel.last()
178-
updateInputAndMoveCaretToEOL(this, entry)
179-
})
165+
} else if (event.key === 'Home' && event.shiftKey && process.platform === 'darwin') {
166+
// go to beginning of line
167+
setCaretPositionToStart(prompt)
168+
} else if (event.key === 'End' && event.shiftKey && process.platform === 'darwin') {
169+
// go to end of line
170+
setCaretPositionToEnd(prompt)
180171
} else if (char === KeyCodes.DOWN || (char === KeyCodes.N && event.ctrlKey)) {
181172
// going DOWN past the last history item will result in '', i.e. a blank line
182173
setTimeout(async () => {

0 commit comments

Comments
 (0)