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

Commit 26f49e8

Browse files
committed
fix(plugins/plugin-client-common): restore history navigation behavior in minisplits
and instead use PageUp/PageDown to navigate blocks Fixes #5375
1 parent b623e4e commit 26f49e8

File tree

1 file changed

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

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ const setCaretPosition = (ctrl: HTMLInputElement, pos: number) => {
5656
const setCaretPositionToEnd = (input: HTMLInputElement) => setCaretPosition(input, input.value.length)
5757

5858
/** Update the given input to reflect the given HistoryLine */
59-
const updateInputAndMoveCaretToEOL = (
60-
input: Input,
61-
entry: HistoryLine,
62-
dir: 'first' | 'last' | 'previous' | 'next'
63-
) => {
64-
if (input.props.isPartOfMiniSplit && input.props.navigateTo && input.props.idx > 0) {
65-
input.props.navigateTo(dir)
66-
} else if (entry) {
59+
const updateInputAndMoveCaretToEOL = (input: Input, entry: HistoryLine) => {
60+
if (entry) {
6761
input.state.prompt.value = entry.raw
6862
setTimeout(() => setCaretPositionToEnd(input.state.prompt), 0)
6963
} else {
@@ -90,7 +84,7 @@ export default async function onKeyDown(this: Input, event: KeyboardEvent) {
9084
const historyModel = await (await import('@kui-shell/core')).History(tab)
9185
const entry = historyModel.previous()
9286
if (entry) {
93-
updateInputAndMoveCaretToEOL(this, entry, 'previous')
87+
updateInputAndMoveCaretToEOL(this, entry)
9488
}
9589
} else if (char === KeyCodes.D && event.ctrlKey) {
9690
if (prompt.value === '') {
@@ -103,12 +97,18 @@ export default async function onKeyDown(this: Input, event: KeyboardEvent) {
10397
debug('pageup')
10498
const { height } = document.body.getBoundingClientRect()
10599
document.querySelector('.kui--tab-content.visible .repl-inner').scrollBy(0, -height)
100+
} else if (this.props.isPartOfMiniSplit) {
101+
// in minisplits, pageup means navigate to previous Block
102+
this.props.navigateTo('previous')
106103
}
107104
} else if (char === KeyCodes.PAGEDOWN) {
108105
if (inBrowser()) {
109106
debug('pagedown')
110107
const { height } = document.body.getBoundingClientRect()
111108
document.querySelector('.kui--tab-content.visible .repl-inner').scrollBy(0, +height)
109+
} else if (this.props.isPartOfMiniSplit) {
110+
// in minisplits, pageup means navigate to next Block
111+
this.props.navigateTo('next')
112112
}
113113
} else if (char === KeyCodes.C && event.ctrlKey) {
114114
// Ctrl+C, cancel
@@ -133,18 +133,18 @@ export default async function onKeyDown(this: Input, event: KeyboardEvent) {
133133
const historyModel = await (await import('@kui-shell/core')).History(tab)
134134
const entry = historyModel.first()
135135
if (entry) {
136-
updateInputAndMoveCaretToEOL(this, entry, 'first')
136+
updateInputAndMoveCaretToEOL(this, entry)
137137
}
138138
} else if (char === KeyCodes.END) {
139139
// go to last command in history
140140
const historyModel = await (await import('@kui-shell/core')).History(tab)
141141
const entry = historyModel.last()
142-
updateInputAndMoveCaretToEOL(this, entry, 'last')
142+
updateInputAndMoveCaretToEOL(this, entry)
143143
} else if (char === KeyCodes.DOWN || (char === KeyCodes.N && event.ctrlKey)) {
144144
// going DOWN past the last history item will result in '', i.e. a blank line
145145
const historyModel = await (await import('@kui-shell/core')).History(tab)
146146
const entry = historyModel.next()
147-
updateInputAndMoveCaretToEOL(this, entry, 'next')
147+
updateInputAndMoveCaretToEOL(this, entry)
148148
} else if (event.key === 'w' && event.ctrlKey) {
149149
const { prompt } = this.state
150150
const idx = prompt.value.lastIndexOf(

0 commit comments

Comments
 (0)