Skip to content

Commit

Permalink
fix(tabsWithNumbers): correctly update closed tab (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitaly Turovsky <[email protected]>
  • Loading branch information
Ilanaya and zardoy authored Nov 27, 2022
1 parent 9cc8929 commit b12b1d3
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/features/tabsWithNumbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default () => {
}

const index = number - 1
console.log('focus', number)
if (mode === 'fromLeft') await focusTabFromLeft(index)
// eslint-disable-next-line sonarjs/no-duplicate-string
const tabUriToFocus = (getExtensionSetting('showTabNumbers.reversedMode') ? [...recentFileStack].reverse() : recentFileStack)[index]
Expand All @@ -49,22 +48,15 @@ export default () => {
const humanReadableMode = noCase(mode)

class FileDecorationProvider implements vscode.FileDecorationProvider {
listeners: Array<(e: vscode.Uri | vscode.Uri[] | undefined) => any> = []
eventEmitter = new vscode.EventEmitter<vscode.Uri | vscode.Uri[] | undefined>()
onDidChangeFileDecorations = this.eventEmitter.event

constructor() {
subscribe(recentFileStack, ops => {
const deletedUris = compact(ops.map(([operation, _affectedIndexes, uri]) => (operation === 'delete' ? (uri as vscode.Uri) : undefined)))
for (const listener of this.listeners) listener([...recentFileStack, ...deletedUris])
this.eventEmitter.fire(recentFileStack)
})
updateDecorations = uris => {
for (const listener of this.listeners) listener(uris ?? recentFileStack)
}
}

onDidChangeFileDecorations: vscode.Event<vscode.Uri | vscode.Uri[] | undefined> | undefined = listener => {
this.listeners.push(listener)
return {
dispose() {},
this.eventEmitter.fire(uris ?? recentFileStack)
}
}

Expand Down Expand Up @@ -143,6 +135,7 @@ export default () => {
const elemIndex = recentFileStack.findIndex(tabUri => tabUri.toString() === document.uri.toString())
if (elemIndex === -1) return
recentFileStack.splice(elemIndex, 1)
updateDecorations([document.uri])
}),
)
}
Expand Down

0 comments on commit b12b1d3

Please sign in to comment.