Used Tab completion optimizing code structure: arrow functions or early return when object isEmpty

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Regarding Tab auto-suggestion:

Case 1: Return null values ​​early to reduce if nesting

When I want to change

if(isNotEmpty) {
...
}

to

if(isEmpty) return;
...

Tab auto-suggestion sometimes doesn’t understand my intention well.

Sometimes, it only adds if(object.isEmpty) return; but accidentally deletes the {} part, resulting in a syntax error.

The next time Tab auto-suggestion appears, it deletes the rest of my code.

if(object.isEmpty) return;

{
...
} 

The old code is not marked as removed. And when I press Tab next time, it cannot be deleted together. I have to delete them manually.


There are more cases

if(object.isNotEmpty) {
...
}
else {
...
}

expected to

if(object.isEmpty) return; 
...

but

if(object.isEmpty) return;
if(object.isNotEmpty) {
...
else {
...
}

or

if(object.isEmpty) return;
...


else {
...
}

if (obj != null) {   
  ...
else {   
  ... 
}

expected to

if (obj == null) return;
...

Case 2: Arrow function

When I want to change

onTap: (xxx) {
  onFunction(...);
}

to

onTap: onFunction,
onTap: () => onFunction(),

or

onTap: (xxx) {
   if (...) {
     ...
    } else {
     ...
    }
}

to

onTap: xxx ? onFunction1 : onFunction2,

Steps to Reproduce

I’m using Flutter and Dart.

Expected Behavior

When I add a new line above if(object.isNotEmpty) and enter if, Tab completion can predict that I want to optimize this code structure.

Tab completion must be in the first result to help me clear the code and spaces that should be deleted.

Operating System

MacOS

Current Cursor Version (Menu → About Cursor → Copy)

Version: 1.7.28
VSCode Version: 1.99.3
Commit: adb0f9e3e4f184bba7f3fa6dbfd72ad0ebb8cfd0
Date: 2025-10-01T02:45:21.769Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 25.0.0

Does this stop you from using Cursor

No - Cursor works, but with this issue

return isNotEmpty 
    ? Container(
      ...);
    : Container();

it added the code, but did not remove necessary structure


The prediction results are always random, but the results are not always the expected results.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.