Skip to content

Conversation

@ottijp
Copy link
Contributor

@ottijp ottijp commented Feb 8, 2025

I found the issue that the line, which is placed after the ViewModifier (the line starting with .), won't be unshifted.
This is caused by less consideration in PR #154 (sorry).

The indentation rule of Xcode is pretty complex.
If the line should be unshifted or not is depending on not only just previous line.
We also have to analyze if the previous lines are "dot block" (the previous line is included in the block staring with dot line (e.g. ViewModifier)).
So I created some helper functions.

  • s:CursorToBlockStart
    • to move the cursor to the line of staring block
  • s:SearchBackwardLineOrBlock
    • to search line by assuming a lines or a block as a unit
  • s:IsMatchingLineOrBlock
    • to judge the line is part of a block which starts with the pattern

If you know more smart implementation, please tell me.

I also added some line to example/SwiftUIView.swift to test this change.
I also refactored the cursor restoration method of function added in previous PR to align it with new functions.

Was:

Text("foo")
    .font(
        .caption
    )
    Text("bar")

Now:

Text("foo")
    .font(
        .caption
    )
Text("bar")

Diff:

$ diff -u --color=auto was.txt now.txt
--- was.txt     2025-02-08 22:11:19
+++ now.txt     2025-02-08 22:11:24
@@ -2,4 +2,4 @@
     .font(
         .caption
     )
-    Text("bar")
+Text("bar")

@ottijp ottijp marked this pull request as ready for review February 8, 2025 14:20
@ottijp
Copy link
Contributor Author

ottijp commented Feb 8, 2025

I also added some line to example/SwiftUIView.swift to test this change.

Of course I verified there are exactly same as Xcode's indentation.

@ottijp ottijp marked this pull request as draft February 8, 2025 15:00
@ottijp ottijp marked this pull request as ready for review February 8, 2025 15:10
@keith keith merged commit 511c37e into keith:master Feb 8, 2025
1 check passed
@ottijp ottijp deleted the fix-dot-line-not-unshifted branch February 9, 2025 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants