Skip to content

✨ Move selected lines up and down #259

Closed

Description

@austincondiff

Description

Users should be able to move lines up or down with ⇧ ⌘ [ and ] or by going to Editor > Move Line Up and Move Line Down.

Screenshots

image

Activity

  1. changed the title [-]✨ Move lines up and down[/-] [+]✨ Move selected lines up and down[/+] on Aug 23, 2024
  2. moved this from 🆕 New to 📋 Todo in CodeEdit Projecton Sep 3, 2024
  3. deleted a comment from on Dec 21, 2024
  4. Bogdan-Belogurov commented on May 22, 2025

    @Bogdan-Belogurov
    Contributor

    @austincondiff Hello! Do you mind if I take this?

  5. 0xWDG commented on May 22, 2025

    @0xWDG
    Collaborator

    @austincondiff Hello! Do you mind if I take this?

    I have assigned you :)

  6. Bogdan-Belogurov commented on May 24, 2025

    @Bogdan-Belogurov
    Contributor

    @0xWDG
    Hello!
    I've made the first prototype

    Details

    normal.mov

    And I noticed a few problems:

    1. If I select a line from the zero position, then in the editSelections method, the selection range includes that line, even if the selection is not actually visible in the UI. Is that the way it's meant to be?
    Details

    issue.mov

    1. As I see from Xcode, during line up/down actions, the selected lines understand their scope and automatically add/remove additional indents. Can you please show me where to look to implement similar logic? 🙏🏿
  7. austincondiff commented on May 24, 2025

    @austincondiff
    CollaboratorAuthor

    First of all, great work so far! Maybe if the selection ends with a newline character, we exclude it. Would that work?

  8. Bogdan-Belogurov commented on May 26, 2025

    @Bogdan-Belogurov
    Contributor

    @austincondiff
    Thanks! I'm not sure about the newline character because it allows you to draw the whole line in the UI, am I right?
    Image

    From my perspective, it would be better to handle this case in the getHighlightedLines-> textLineForOffset method. What do you think?

  9. thecoolwinter commented on May 27, 2025

    @thecoolwinter
    Collaborator

    I think you're right to keep the newline character, but it sounds like there might be something going funky with finding the lines being selected to move.

    And I noticed a few problems:

    1. If I select a line from the zero position, then in the editSelections method, the selection range includes that line, even if the selection is not actually visible in the UI. Is that the way it's meant to be?

    What are you using to determine what lines are selected? The editSelections method just passes along any text selections active in the TextView, so that makes me think there's maybe something going on with whatever method is being used to find lines in the selected range.

    1. As I see from Xcode, during line up/down actions, the selected lines understand their scope and automatically add/remove additional indents. Can you please show me where to look to implement similar logic? 🙏🏿

    Right now we don't have any architecture for determining 'correct' indent levels. I may be building that out right now while developing the line folding gutter and I know tree-sitter has that capability, but we haven't had a need for it just yet.

  10. Bogdan-Belogurov commented on May 28, 2025

    @Bogdan-Belogurov
    Contributor

    @thecoolwinter Hello!

    What are you using to determine what lines are selected?

    I use getHighlightedLines method to determine what lines are selected

    guard let lineIndexes = getHighlightedLines(for: selection.range) else { return }

    Here I've selected starting at line 27 of the zero position
    Image

    getHighlightedLines output:
    Image

  11. thecoolwinter commented on May 30, 2025

    @thecoolwinter
    Collaborator

    Okay looking into that method you're right it's not returning what you'd expect. Technically the selection contains the second line (line 27 in your screenshot), but that method shouldn't be returning both those lines. That's actually causing another bug with the indent lines functionality with the same issue you found. I'll have a patch ready in a moment for that method that should make it function as expected.

  12. 1 remaining item

  13. Bogdan-Belogurov commented on May 31, 2025

    @Bogdan-Belogurov
    Contributor

    @thecoolwinter Now it works perfectly. Thanks!

    Spoiler

    Screen.Recording.2025-05-31.at.12.25.01.mov

  14. austincondiff commented on May 31, 2025

    @austincondiff
    CollaboratorAuthor

    Looks fantastic!
    One detail. Should it modify your selection? Or should it move the lines, leaving your selection alone? We should follow Xcodes lead on this one. It looks like this works as expected.
    Submit a PR when ready!

  15. moved this from 📋 Todo to 🏃‍♂️ In Progress in CodeEdit Projecton May 31, 2025
  16. Bogdan-Belogurov commented on Jun 1, 2025

    @Bogdan-Belogurov
    Contributor

    @thecoolwinter Hi! I made a PR. Could you add reviewers, please 🙏🏿

  17. thecoolwinter commented on Jun 2, 2025

    @thecoolwinter
    Collaborator

    Closed with #327, thanks @Bogdan-Belogurov 🎉

  18. moved this from 🏃‍♂️ In Progress to 🏁 Complete in CodeEdit Projecton Jun 2, 2025
  19. Bogdan-Belogurov commented on Jun 3, 2025

    @Bogdan-Belogurov
    Contributor

    @thecoolwinter Hi! Do you need an Editor->Structure menu like in Xcode?

  20. austincondiff commented on Jun 3, 2025

    @austincondiff
    CollaboratorAuthor
  21. Bogdan-Belogurov commented on Jun 3, 2025

    @Bogdan-Belogurov
    Contributor

    @austincondiff I meant this editor menu

    Spoiler

    Image

  22. austincondiff commented on Jun 3, 2025

    @austincondiff
    CollaboratorAuthor

    Oh right, yes, that would be great!

  23. Bogdan-Belogurov commented on Jun 8, 2025

    @Bogdan-Belogurov
    Contributor

    @austincondiff Hi! I opened 2 PRs #333 and CodeEditApp/CodeEdit#2058 to migrate logic to the menu. But I notice an issue in the current solution. As you can see, I'm relying on EditorInstance.RangeTranslator to use the lines movement API. But if I switch tabs, the TextViewCoordinator.destroy method is called after TextViewCoordinator.prepareCoordinator, as a result, I can't reach the text view controller API (textViewController is nil). Is it expected behavior? Also, it breaks the linesInRange API

    Details

    Screen.Recording.2025-06-08.at.09.41.52.mov

  24. thecoolwinter commented on Jun 18, 2025

    @thecoolwinter
    Collaborator

    @Bogdan-Belogurov you're right, that's not expected behavior. The coordinator should be setup again after switching back to the old tab. I'll investigate today

  25. thecoolwinter commented on Jun 26, 2025

    @thecoolwinter
    Collaborator

    @Bogdan-Belogurov got a fix in for the coordinator lifecycle bug, I'll lyk when it's in a tagged release so we can update the related CodeEdit PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions