@@ -171,6 +171,17 @@ class PropertyEditorController extends DisposableController
171171 );
172172 }
173173
174+ Future <GenericApiResponse ?> executeCommand ({
175+ required String commandName,
176+ required List <Object ?> commandArgs,
177+ }) {
178+ return editorClient.executeCommand (
179+ commandName: commandName,
180+ commandArgs: commandArgs,
181+ screenId: gac.PropertyEditorSidebar .id,
182+ );
183+ }
184+
174185 int hashProperty (EditableProperty property) {
175186 final widgetData = editableWidgetData.value;
176187 if (widgetData == null ) {
@@ -212,14 +223,18 @@ class PropertyEditorController extends DisposableController
212223 CodeActionResult ? refactorsResult;
213224 // TODO(https://github.com/flutter/devtools/issues/8652): Enable refactors
214225 // in the Property Editor by default.
215- if (FeatureFlags .propertyEditorRefactors) {
216- // Get any supported refactors for the current position.
226+ if (editableArgsResult != null && FeatureFlags .propertyEditorRefactors) {
227+ // Fetch the refactors using the start of the editable arguments' range,
228+ // which corresponds to the widget constructor name. This ensures that the
229+ // refactors are always available, even when the cursor is within the
230+ // parameter list. See https://github.com/flutter/devtools/issues/9221.
231+ final position = editableArgsResult.range? .start ?? cursorPosition;
217232 // TODO(elliette): Consider updating the widget data immediately without
218233 // waiting for the refactors result, then updating the refactor buttons
219234 // once the refactors result is available.
220235 refactorsResult = await editorClient.getRefactors (
221236 textDocument: textDocument,
222- range: EditorRange (start: cursorPosition , end: cursorPosition ),
237+ range: EditorRange (start: position , end: position ),
223238 screenId: gac.PropertyEditorSidebar .id,
224239 );
225240 }
@@ -275,6 +290,7 @@ class PropertyEditorController extends DisposableController
275290 TextDocument ? document,
276291 CursorPosition ? cursorPosition,
277292 EditorRange ? range,
293+ List <CodeActionCommand >? refactors,
278294 }) {
279295 setActiveFilter ();
280296 if (editableArgsResult != null ) {
@@ -283,9 +299,7 @@ class PropertyEditorController extends DisposableController
283299 .map (argToProperty)
284300 .nonNulls
285301 .toList (),
286- // TODO(https://github.com/flutter/devtools/issues/8652): Add tests for
287- // refactors.
288- refactors: [],
302+ refactors: refactors ?? [],
289303 name: editableArgsResult.name,
290304 documentation: editableArgsResult.documentation,
291305 fileUri: document? .uriAsString,
0 commit comments