Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Introduce Move Lines Feature, Fix Selection Bug on macOS, and Update JavaDoc #964

Merged
merged 8 commits into from
Mar 21, 2025

Conversation

yehiarasheed
Copy link
Contributor

@yehiarasheed yehiarasheed commented Mar 7, 2025

Feature Overview

This PR closes issue #953 and introduces the Move Lines feature, allowing users to move selected lines up or down in the editor. The feature ensures:

  • Proper selection behavior after moving lines.
  • Undo (Ctrl + Z) and redo (Ctrl + Y on Windows/Linux and Shift + Cmd + Z on macOS) functionality.
  • Clear documentation for expected behavior.

Fixes & Improvements

Fixed Selection Bug on macOS

  • Previously, moving lines down on macOS caused the cursor to jump to the end of enclosing braces instead of maintaining selection.
  • The fix ensures selection updates correctly by wrapping them in SwingUtilities.invokeLater(), ensuring execution on the Swing event dispatch thread.
  • The issue did not occur on Windows, but testing confirmed consistent behavior across both platforms.

Updated JavaDoc for Users

  • Clarified that redo on macOS is Shift + Cmd + Z, not Cmd + Y.
  • Improved documentation to provide clear guidance on the move lines feature.

Testing

  • Linux: Tested on a Manjaro System and confirmed working. A video demonstration is included.
  • macOS: Tested on a macOS Catalina System and confirmed working. A video demonstration and Screenshots are included.
  • Windows: Tested on a Windows 11 System and confirmed working. A video demonstration is included.

Media

Linux Video Demonstration:

Linux-MoveLines-Demo.mp4

macOS Video Demonstration and Screenshots:

Video Demonstration

macOS-moveLines-Demo.mp4

Screenshots

Before macOS
After macOS

Windows Video Demonstration:

Windows.Move.Lines.Feature.mp4

JavaDoc for the handleMoveLines(boolean moveUp) method

image

Next Steps

This PR introduces a new feature while ensuring cross-platform reliability. Further review and feedback are welcome.


yehiarasheed and others added 3 commits March 7, 2025 15:09
…teners

- Implement handleMoveLines to manage line movement functionality
- Add keystroke bindings for triggering line movements
- Integrate ActionListeners for responsive UI interactions
- Ensure cross-platform compatibility for macOS and Linux
Previously, moving lines down on macOS caused incorrect selection, moving
the cursor to the end of the enclosing braces instead of properly selecting the moved line. This issue did not occur on Windows.

The fix ensures that selection updates happen inside Swing's event
dispatch thread by wrapping the selection logic in SwingUtilities.invokeLater().
This guarantees proper selection behavior across all platforms.

Additionally, updated the JavaDoc for the method to reflect the fix and clarify
the behavior of the selection update.

Tested on Windows and macOS.
Updated the JavaDoc to reflect that the redo command on macOS is {@code Shift + Cmd + Z},
not {@code Cmd + Y}, and may vary on other platforms. This ensures the documentation is
accurate and aligns with the actual keybindings.

No functional code changes were made.
@yehiarasheed
Copy link
Contributor Author

yehiarasheed commented Mar 7, 2025

Hi @Stefterv @SableRaf ,

I've been exploring the project and noticed a few areas where we might enhance user experience and functionality. I’d appreciate your thoughts on the following ideas:

  1. Keyboard Shortcuts Page:
    While exploring the repository and documentation, I couldn’t locate a dedicated page (in the docs, README, or on the official website) that lists all available keyboard shortcuts for the editor. Would it be useful to create such a page for users? Perhaps under the Documentation Section found in the Processing.org website. I believe having a centralized, easy-to-access reference for shortcuts could enhance user experience.

  2. macOS Dock/Menu Naming:
    While testing on macOS, I observed that the app appears in the dock as “java” and the menu item is labeled “Start.” Is this behavior expected, or would you prefer these be adjusted? I’m happy to investigate and resolve this if it’s not intentional.

Screenshots

macOS Menu Bar Processing
image


macOS Dock Processing

I’d appreciate your feedback on these points or any additional guidance regarding the project’s roadmap.


@yehiarasheed yehiarasheed deleted the yehiarasheed-add-movelines branch March 8, 2025 09:30
@yehiarasheed yehiarasheed restored the yehiarasheed-add-movelines branch March 8, 2025 11:29
@yehiarasheed yehiarasheed reopened this Mar 8, 2025
- Updated line moving logic to select until the end of the line only, avoiding selection of the new line character.
- Added functionality to move lines without selecting anything if no text is selected.
@yehiarasheed
Copy link
Contributor Author

Hey @Stefterv @SableRaf ,

I've implemented two enhancements inspired by IntelliJ IDEA for this feature:

  1. Line Movement Without Full Selection: When the cursor is on a specific line and we attempt to move that line, it now moves without selecting the entire line. Previously, the entire line would be selected even if only some text was selected.

  2. Cursor Position Maintenance: Previously, moving a line would select the entire line and place the cursor at the start of the next line due to the '\n' newline character. I've fixed this by allowing selection up to the last character of the line being moved, ensuring the cursor remains on the same line, thus solving the issue where the cursor would move to the next line.

Video Demonstration

Windows-moveLines-enhancedSelect.mp4

I've tested this on Windows, macOS and Linux to ensure consistency and to avoid wrinkles.

Also, just a quick heads-up: I accidentally closed this PR by mistake. Hope it didn't cause too much confusion. This feature is now finalized and ready for review.

@SableRaf SableRaf requested a review from Stefterv March 11, 2025 10:11
@SableRaf
Copy link
Collaborator

Hi @yehiarasheed, thanks for your work on this!

Just a quick note: As Stef mentioned here, the option shouldn’t be visible in the Edit menu. Right now, "Move Selected Lines Up" and "Move Selected Lines Down" appear there (screenshot below).

I’ll let @Stefterv review the code itself.

image

@yehiarasheed
Copy link
Contributor Author

yehiarasheed commented Mar 11, 2025

Hi @SableRaf,

Thanks for pointing that out. I’ve done the necessary adjustments.

Also, I previously mentioned a couple of potential improvements here and would love to hear your thoughts on them!

@SableRaf
Copy link
Collaborator

Thanks for pointing that out. I’ve done the necessary adjustments.

Hi @yehiarasheed, it looks like the changes in bb80a78 broke the shortcut, at least on macOS. Could you double check on other platforms and investigate the cause? Thanks!

Also, I previously mentioned a couple of potential improvements #964 (comment) and would love to hear your thoughts on them!

I think the changes are good in terms of user experience.

Note: We're busy right now preparing the release of Processing 4.4 but we'll review your PR as soon as we can.

@processing processing deleted a comment from Stefterv Mar 11, 2025
@yehiarasheed
Copy link
Contributor Author

yehiarasheed commented Mar 11, 2025

Hi @SableRaf, The shortcut broke for me too, but I’ve investigated the issue, and it seems to be related to how the shortcut was registered. It turns out that the menu.add(item) line was automatically handling the shortcut registration as well. I’ll manually add the registration to fix the issue as soon as possible.

Important

I've re-implemented the shortcut registration and it's working now across all platforms.

… shortcut registration. Added alternative shortcut handling for Move Lines functionality.
@yehiarasheed
Copy link
Contributor Author

I think the changes are good in terms of user experience.

Hey @SableRaf, I can create an issue for the Keyboard Shortcuts section in the processing-website repo if we agree it enhances the user experience. Keeping the documentation updated alongside development ensures it’s comprehensive and ready for the Processing 4.4 release.

…ary whitespace and added two blank lines between function blocks for improved readability.
@SableRaf
Copy link
Collaborator

@all-contributors please add @yehiarasheed for code

Copy link
Contributor

@SableRaf

I've put up a pull request to add @yehiarasheed! 🎉

@yehiarasheed yehiarasheed deleted the yehiarasheed-add-movelines branch March 21, 2025 11:42
@processing processing deleted a comment from allcontributors bot Mar 21, 2025
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.

3 participants