-
Notifications
You must be signed in to change notification settings - Fork 399
debugger: Add keyboard shortcuts for pause/resume, stepping, and frame navigation (#3867) #9835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NadeemIqbal
wants to merge
2
commits into
flutter:master
Choose a base branch
from
NadeemIqbal:nadeem/3867-debugger-keyboard-shortcuts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,12 +54,22 @@ class DebuggerScreen extends Screen { | |
| searchInFileKeySet: SearchInFileIntent(controller), | ||
| escapeKeySet: EscapeIntent(controller), | ||
| openFileKeySet: OpenFileIntent(controller), | ||
| pauseResumeKeySet: PauseResumeIntent(controller), | ||
| nextStackFrameKeySet: NextStackFrameIntent(controller), | ||
| stepOverKeySet: StepOverIntent(controller), | ||
| stepInKeySet: StepInIntent(controller), | ||
| stepOutKeySet: StepOutIntent(controller), | ||
| }; | ||
| final actions = <Type, Action<Intent>>{ | ||
| GoToLineNumberIntent: GoToLineNumberAction(), | ||
| SearchInFileIntent: SearchInFileAction(), | ||
| EscapeIntent: EscapeAction(), | ||
| OpenFileIntent: OpenFileAction(), | ||
| PauseResumeIntent: PauseResumeAction(), | ||
| NextStackFrameIntent: NextStackFrameAction(), | ||
| StepOverIntent: StepOverAction(), | ||
| StepInIntent: StepInAction(), | ||
| StepOutIntent: StepOutAction(), | ||
| }; | ||
| return ShortcutsConfiguration(shortcuts: shortcuts, actions: actions); | ||
| } | ||
|
|
@@ -412,6 +422,134 @@ class OpenFileAction extends Action<OpenFileIntent> { | |
| } | ||
| } | ||
|
|
||
| // ----- Stepping / pause keyboard intents (issue #3867) ----------------------- | ||
| // | ||
| // These mirror the gating used by the debugger control buttons in | ||
| // `controls.dart`: stepping requires a paused, non-system isolate with at | ||
| // least one stack frame and no in-flight resume; pause/resume is gated by | ||
| // `isSystemIsolate` and the current paused state. | ||
|
|
||
| bool _isSystemIsolate(DebuggerController controller) => | ||
| controller.isSystemIsolate; | ||
|
|
||
| bool _canStep(DebuggerController controller) { | ||
| return serviceConnection.serviceManager.isMainIsolatePaused && | ||
| !controller.resuming.value && | ||
| controller.stackFramesWithLocation.value.isNotEmpty && | ||
| !controller.isSystemIsolate; | ||
| } | ||
|
|
||
| class PauseResumeIntent extends Intent { | ||
| const PauseResumeIntent(this._controller); | ||
|
|
||
| final DebuggerController _controller; | ||
| } | ||
|
|
||
| class PauseResumeAction extends Action<PauseResumeIntent> { | ||
| @override | ||
| bool isEnabled(PauseResumeIntent intent) { | ||
| if (_isSystemIsolate(intent._controller)) { | ||
| return false; | ||
| } | ||
| final isPaused = serviceConnection.serviceManager.isMainIsolatePaused; | ||
| if (isPaused) { | ||
| // When paused, the button becomes "Resume" and is disabled while a | ||
| // resume is already in flight. | ||
| return !intent._controller.resuming.value; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @override | ||
| void invoke(PauseResumeIntent intent) { | ||
| final controller = intent._controller; | ||
| if (serviceConnection.serviceManager.isMainIsolatePaused) { | ||
| unawaited(controller.resume()); | ||
| } else { | ||
| unawaited(controller.pause()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class NextStackFrameIntent extends Intent { | ||
| const NextStackFrameIntent(this._controller); | ||
|
|
||
| final DebuggerController _controller; | ||
| } | ||
|
|
||
| class NextStackFrameAction extends Action<NextStackFrameIntent> { | ||
| @override | ||
| bool isEnabled(NextStackFrameIntent intent) => | ||
| intent._controller.stackFramesWithLocation.value.length > 1; | ||
|
|
||
| @override | ||
| void invoke(NextStackFrameIntent intent) { | ||
| final controller = intent._controller; | ||
| final frames = controller.stackFramesWithLocation.value; | ||
| if (frames.length < 2) { | ||
| return; | ||
| } | ||
| final currentlySelected = controller.selectedStackFrame.value; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [NIT] This check is redundant as final currentlySelected = controller.selectedStackFrame.value;References
|
||
| final currentIndex = currentlySelected == null | ||
| ? -1 | ||
| : frames.indexWhere( | ||
| (frame) => frame.frame.index == currentlySelected.frame.index, | ||
| ); | ||
| // Cycle through frames so repeated presses walk the call stack and wrap | ||
| // back to the top. | ||
| final nextIndex = (currentIndex + 1) % frames.length; | ||
| unawaited(controller.selectStackFrame(frames[nextIndex])); | ||
| } | ||
| } | ||
|
|
||
| class StepOverIntent extends Intent { | ||
| const StepOverIntent(this._controller); | ||
|
|
||
| final DebuggerController _controller; | ||
| } | ||
|
|
||
| class StepOverAction extends Action<StepOverIntent> { | ||
| @override | ||
| bool isEnabled(StepOverIntent intent) => _canStep(intent._controller); | ||
|
|
||
| @override | ||
| void invoke(StepOverIntent intent) { | ||
| unawaited(intent._controller.stepOver()); | ||
| } | ||
| } | ||
|
|
||
| class StepInIntent extends Intent { | ||
| const StepInIntent(this._controller); | ||
|
|
||
| final DebuggerController _controller; | ||
| } | ||
|
|
||
| class StepInAction extends Action<StepInIntent> { | ||
| @override | ||
| bool isEnabled(StepInIntent intent) => _canStep(intent._controller); | ||
|
|
||
| @override | ||
| void invoke(StepInIntent intent) { | ||
| unawaited(intent._controller.stepIn()); | ||
| } | ||
| } | ||
|
|
||
| class StepOutIntent extends Intent { | ||
| const StepOutIntent(this._controller); | ||
|
|
||
| final DebuggerController _controller; | ||
| } | ||
|
|
||
| class StepOutAction extends Action<StepOutIntent> { | ||
| @override | ||
| bool isEnabled(StepOutIntent intent) => _canStep(intent._controller); | ||
|
|
||
| @override | ||
| void invoke(StepOutIntent intent) { | ||
| unawaited(intent._controller.stepOut()); | ||
| } | ||
| } | ||
|
|
||
| class DebuggerStatus extends StatefulWidget { | ||
| const DebuggerStatus({super.key, required this.controller}); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[CONCERN] The logic for determining if stepping is allowed is duplicated here and in
controls.dart. To improve maintainability and ensure consistent behavior between buttons and shortcuts, this logic should be moved to a shared property or method inDebuggerController.References