Skip to content

Commit

Permalink
fix: ignore history navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Feb 8, 2023
1 parent 01a7cba commit 5b45464
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
56 changes: 32 additions & 24 deletions src/renderer/compositions/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,38 @@ export async function createTerminalTab({
if (event.key === 'c' && xterm.hasSelection()) return false
if (event.key === 'f') return false
}
if (tab.addons.shellIntegration?.completion) {
switch (event.key) {
case 'Enter':
case 'Tab':
event.preventDefault()
if (event.type === 'keydown') {
return !tab.addons.shellIntegration.applySelectedCompletionElement(event.key === 'Enter')
}
return false
case 'Escape':
if (event.type === 'keydown') {
tab.addons.shellIntegration.clearCompletion()
}
return false
case 'ArrowUp':
if (event.type === 'keydown') {
tab.addons.shellIntegration.selectPreviousCompletionElement()
}
return false
case 'ArrowDown':
if (event.type === 'keydown') {
tab.addons.shellIntegration.selectNextCompletionElement()
}
return false
const shellIntegration = tab.addons.shellIntegration
if (shellIntegration) {
if (shellIntegration.completion) {
switch (event.key) {
case 'Enter':
case 'Tab':
event.preventDefault()
if (event.type === 'keydown') {
return !shellIntegration.applySelectedCompletionElement(event.key === 'Enter')
}
return false
case 'Escape':
if (event.type === 'keydown') {
shellIntegration.clearCompletion()
}
return false
case 'ArrowUp':
if (event.type === 'keydown') {
shellIntegration.selectPreviousCompletionElement()
}
return false
case 'ArrowDown':
if (event.type === 'keydown') {
shellIntegration.selectNextCompletionElement()
}
return false
}
} else {
if (['ArrowUp', 'ArrowDown'].includes(event.key) && event.type === 'keydown') {
shellIntegration.skipCompletion()
return true
}
}
}
const matchedItem = rendererKeybindings.find(item => isMatch(event, item.pattern))
Expand Down
14 changes: 10 additions & 4 deletions src/renderer/utils/shell-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ShellIntegrationAddon implements ITerminalAddon {
recentMarker?: WeakRef<IMarker>
completion?: IntegratedShellCompletion
completionKey?: symbol
recentCompletionAppliedPosition?: IntegratedShellCompletion['position']
recentCompletionAppliedPosition?: true | IntegratedShellCompletion['position']

constructor(tab: TerminalTab) {
this.tab = tab
Expand Down Expand Up @@ -496,8 +496,10 @@ export class ShellIntegrationAddon implements ITerminalAddon {
return
}
if (
isEqual(this.recentCompletionAppliedPosition, currentPosition)
&& completions.some(item => item.query && item.value === item.query)
this.recentCompletionAppliedPosition === true || (
isEqual(this.recentCompletionAppliedPosition, currentPosition)
&& completions.some(item => item.query && item.value === item.query)
)
) {
this.recentCompletionAppliedPosition = undefined
if (shouldReuseDecoration) {
Expand Down Expand Up @@ -534,6 +536,10 @@ export class ShellIntegrationAddon implements ITerminalAddon {
}
}

skipCompletion(position?: IntegratedShellCompletion['position']) {
this.recentCompletionAppliedPosition = position ?? true
}

applyCompletion(value: string, back = 0) {
const { xterm } = this.tab
const position = this._getCurrentPosition()
Expand All @@ -542,7 +548,7 @@ export class ShellIntegrationAddon implements ITerminalAddon {
while (position.x > xterm.cols) {
position.x -= xterm.cols
}
this.recentCompletionAppliedPosition = position
this.skipCompletion(position)
writeTerminalTab(this.tab, '\x7F'.repeat(back) + value)
// Preload completions
this._getRealtimeCompletions(input.slice(0, -back) + value + ' ')
Expand Down

0 comments on commit 5b45464

Please sign in to comment.