Skip to content

Commit f710f90

Browse files
committed
performance improvements for result animations
and breakpoint gutter insertion
1 parent 41909a8 commit f710f90

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

lib/debugger/breakpoints.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ export default class BreakpointManager {
7171
this.onUncaught = false
7272
this.compiledMode = false
7373

74-
this.subs.add(atom.workspace.observeTextEditors(ed => {
75-
this.subs.add(ed.observeGrammar(() => {
76-
if (this.appliesToEditor(ed)) {
77-
this.init(ed)
78-
} else {
79-
this.deinit(ed)
80-
}
81-
}))
74+
this.subs.add(atom.workspace.observeActiveTextEditor(ed => {
75+
if (ed && ed.observeGrammar) {
76+
this.subs.add(ed.observeGrammar(() => {
77+
if (this.appliesToEditor(ed)) {
78+
this.init(ed)
79+
} else {
80+
this.deinit(ed)
81+
}
82+
}))
83+
}
8284
}))
8385
}
8486

@@ -100,22 +102,30 @@ export default class BreakpointManager {
100102
}
101103

102104
init(ed) {
105+
if (ed.gutterWithName(this.name) !== null) return
103106
ed.addGutter({
104107
name: this.name,
105108
priority: 0
106109
})
107110

108-
// click on gutter creates new bp
109111
const editorElement = atom.views.getView(ed)
112+
let hasListener = false
110113

114+
// click on gutter creates new bp
111115
const addClickListener = () => {
116+
if (hasListener) return
117+
112118
const gutterElement = editorElement.querySelector(`.gutter[gutter-name="${this.name}"]`)
113119

114120
if (gutterElement == null) {
115-
window.requestAnimationFrame(addClickListener)
121+
setTimeout(() => {
122+
process.nextTick(() => window.requestAnimationFrame(addClickListener))
123+
}, 1000)
124+
116125
return
117126
}
118127

128+
hasListener = true
119129
gutterElement.addEventListener('click', event => {
120130
if (!ed || !ed.getPath()) {
121131
atom.notifications.addError('Need a saved file to add a breakpoint')

lib/editor/result.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,14 @@ export default class Result {
268268
let winWidth = window.innerWidth;
269269

270270
res.forEach((r) => r.view.decideUpdateWidth(rect))
271+
271272
// DOM writes
272273
res.forEach((r) => r.view.updateWidth(rect, winWidth))
273274
}
274-
window.requestAnimationFrame(listener)
275-
// setTimeout(() => {
276-
// process.nextTick(() => window.requestAnimationFrame(listener))
277-
// }, 10*1000/60)
275+
276+
setTimeout(() => {
277+
process.nextTick(() => window.requestAnimationFrame(listener))
278+
}, 750)
278279
}
279280
window.requestAnimationFrame(listener)
280281
return

0 commit comments

Comments
 (0)