From 981b2ebef0d03460d5115e19e501920bf6c6491b Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 9 Feb 2017 10:51:32 +0100 Subject: [PATCH] add jumpPreviousBreakpoint --- src/code/breakpointManager.js | 51 ++++++++++++++++++++++++----------- src/ui/ButtonNavigator.js | 6 +++++ src/ui/StepManager.js | 3 +++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/code/breakpointManager.js b/src/code/breakpointManager.js index a06a0ed963..ddbae21ab7 100644 --- a/src/code/breakpointManager.js +++ b/src/code/breakpointManager.js @@ -17,37 +17,58 @@ class breakpointManager { this.event = new EventManager() this.debugger = _debugger this.breakpoints = {} - this.isPlaying = false this.locationToRowConverter = _locationToRowConverter - this.currentLine + this.previousLine } /** * start looking for the next breakpoint + * @param {Bool} defaultToLimit - if true jump to the enf of the trace if no more breakpoint found * */ - async jumpNextBreakpoint (defaultToEnd) { - this.isPlaying = true + async jumpNextBreakpoint (defaultToLimit) { + this.jump(1, defaultToLimit) + } + + /** + * start looking for the previous breakpoint + * @param {Bool} defaultToLimit - if true jump to the enf of the trace if no more breakpoint found + * + */ + async jumpPreviousBreakpoint (defaultToLimit) { + this.jump(-1, defaultToLimit) + } + + /** + * start looking for the previous or next breakpoint + * @param {Int} direction - 1 or -1 direction of the search + * @param {Bool} defaultToLimit - if true jump to the enf of the trace if no more breakpoint found + * + */ + async jump (direction, defaultToLimit) { + if (!this.locationToRowConverter) { + return + } var sourceLocation - for (var currentStep = this.debugger.currentStepIndex + 1; currentStep < this.debugger.traceManager.trace.length; currentStep++) { + var currentStep = this.debugger.currentStepIndex + direction + while (currentStep > 0 && currentStep < this.debugger.traceManager.trace.length) { try { sourceLocation = await this.debugger.callTree.extractSourceLocation(currentStep) } catch (e) { console.log('cannot jump to breakpoint ' + e) } - if (this.locationToRowConverter) { - var lineColumn = this.locationToRowConverter(sourceLocation) - if (this.currentLine === lineColumn.start.line) { - if (defaultToEnd && currentStep === this.debugger.traceManager.trace.length - 1) { - this.debugger.stepManager.jumpTo(currentStep) // jump to the end - } - continue + var lineColumn = this.locationToRowConverter(sourceLocation) + if (this.previousLine !== lineColumn.start.line) { + this.previousLine = lineColumn.start.line + if (this.checkSourceLocation(sourceLocation.file, lineColumn.start.line)) { + this.debugger.stepManager.jumpTo(currentStep) + this.event.trigger('breakpointHit', [sourceLocation]) + break } - this.currentLine = lineColumn.start.line } - if (this.checkSourceLocation(sourceLocation.file, this.currentLine)) { + currentStep += direction + if (defaultToLimit && (currentStep === this.debugger.traceManager.trace.length - 1 || currentStep === 0)) { this.debugger.stepManager.jumpTo(currentStep) - this.event.trigger('breakpointHit', [sourceLocation]) break } } diff --git a/src/ui/ButtonNavigator.js b/src/ui/ButtonNavigator.js index b91c0f84ae..b63c427aa5 100644 --- a/src/ui/ButtonNavigator.js +++ b/src/ui/ButtonNavigator.js @@ -12,6 +12,7 @@ function ButtonNavigator (_parent, _traceManager) { this.overForwardDisabled = true this.jumpOutDisabled = true this.jumpNextBreakpointDisabled = true + this.jumpPreviousBreakpointDisabled = true this.traceManager = _traceManager this.currentCall = null @@ -69,6 +70,8 @@ ButtonNavigator.prototype.render = function () { +