Skip to content

Commit

Permalink
perf(lazy): defer watching keymap files
Browse files Browse the repository at this point in the history
  • Loading branch information
craftzdog committed Jul 10, 2023
1 parent da169d0 commit 29325a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/keymap-manager-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ describe('KeymapManager', function () {
'ctrl-a': 'x'
`
)
keymapManager.loadKeymap(keymapFilePath, { watch: true })
keymapManager.loadKeymap(keymapFilePath, { watch: true, watchImmediately: true })
subscription = keymapManager.watchSubscriptions[keymapFilePath]
return assert.equal(
keymapManager.findKeyBindings({ command: 'x' }).length,
Expand Down Expand Up @@ -2325,7 +2325,7 @@ describe('KeymapManager', function () {
assert(!reloaded)

// Can start watching again after cancelling
keymapManager.loadKeymap(keymapFilePath, { watch: true })
keymapManager.loadKeymap(keymapFilePath, { watch: true, watchImmediately: true })
fs.writeFileSync(
keymapFilePath,
`\
Expand Down
3 changes: 2 additions & 1 deletion src/keymap-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ module.exports = KeymapManager = (function () {
options != null ? options.priority : undefined
)
if (options != null ? options.watch : undefined) {
this.watchKeymap(bindingsPath, options)
const watch = () => this.watchKeymap(bindingsPath, options)
options.watchImmediately ? watch() : setTimeout(watch, 300)
}
}

Expand Down

0 comments on commit 29325a4

Please sign in to comment.