AndroidIDE icon indicating copy to clipboard operation
AndroidIDE copied to clipboard

Automatic Code Indentation

Open Abiddarris opened this issue 1 year ago • 1 comments

Issue Checklist

  • [X] I confirm that this feature request has not been previously suggested.
  • [X] I agree to follow the project's code of conduct.
  • [X] I have checked and verified that I am using the latest version of AndroidIDE from GitHub or F-Droid.

Additional terms

  • [X] I understand that feature requests are subject to evaluation and may not be implemented immediately.
  • [X] I agree to provide additional details if needed for a clearer understanding of the requested feature.

Feature description

Summary: There is an issue with the automatic indentation of code when moving blocks of code in the editor. The indentation is not preserved correctly, resulting in poorly formatted code.

Steps to Reproduce:

  1. Consider the following initial Java code:

    class MyClass {
    
        void myMethod() {
            int a = 10;
            int b = 5;
            if(a > b) {
                b *= a;
            } else {
                b = a--;
            }
    
            while(true) {
               int c = 100;
               if(--c < 0)
                   break;
            }
        }
    
    }
    
  2. Move the code block:

    int a = 10;
    int b = 5;
    if(a > b) {
        b *= a;
    } else {
        b = a--;
    }
    

    inside the while loop.

  3. Observe the result:

    class MyClass {
    
        void myMethod() {
    
            while(true) {
               int c = 100;
               if(--c < 0)
                    break;
    
                int a = 10;
            int b = 5;
            if(a > b) {
                b *= a;
            } else {
                b = a--;
            }
    
            }
        }
    
    }
    
  4. The expected correctly indented result should be:

    class MyClass {
    
        void myMethod() {
    
            while(true) {
               int c = 100;
               if(--c < 0)
                    break;
    
                int a = 10;
                int b = 5;
                if(a > b) {
                    b *= a;
                } else {
                    b = a--;
                }
    
            }
        }
    
    }
    
  5. Move the code inside the while loop back to outside of it.

  6. Observe the result:

    class MyClass {
        void myMethod() {
            int a = 10;
            int b = 5;
            if(a > b) {
                b *= a;
            } else {
                b = a--;
            }
    
            int c = 100;
               if(--c < 0)
                    break;
            while(true) {
    
            }
        }
    }    
    
  7. The expected correctly indented result should be:

    class MyClass {
        void myMethod() {
            int a = 10;
            int b = 5;
            if(a > b) {
                b *= a;
            } else {
                b = a--;
            }
    
            int c = 100;
            if(--c < 0)
                break;
            while(true) {
    
            }
        }
    }    
    

Actual Result: The code is not indented correctly when moved, leading to a messy and hard-to-read code structure.

Expected Result: The code should maintain proper indentation when moved, making it clean and readable.

Use Case

Enhanced Readability: The code remains clean and readable regardless of how blocks are moved around

Improved Maintainability: Well-indented code is easier to understand, modify, and debug.

Time-Saving: Jane saves time otherwise spent on manually fixing indentation errors, allowing her to focus more on the logic and functionality of the code.

Consistency: Ensures a consistent code style throughout the project, which is crucial for team-based development and code reviews.

Benefits

Enchanced user experience

Abiddarris avatar May 19 '24 10:05 Abiddarris

😂, for this to work maybe there should be a listener for the paste action that will automatically format the entire code when the paste action is performed in the editor, actually this is my suggestion - maybe there is a proper way for the implementation other than this

itSMcodez avatar May 19 '24 14:05 itSMcodez