Skip to content

Commit 938109d

Browse files
committed
Fix selection bug in handleMoveLines on macOS by using invokeLater()
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.
1 parent 34cc438 commit 938109d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/src/processing/app/ui/Editor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,8 @@ public void handleIndentOutdent(boolean indent) {
19361936
* <p>If {@code moveUp} is true, the selected lines are moved up. If false, they move down.</p>
19371937
* <p>This method ensures proper selection updates and handles edge cases like moving
19381938
* the first or last line.</p>
1939+
* <p>This operation is undo/redoable, allowing the user to revert the action using
1940+
* {@code Ctrl/Cmd + Z} (Undo) and redo with {@code Ctrl/Cmd + Y} (Redo).</p>
19391941
*
19401942
* @param moveUp {@code true} to move the selection up, {@code false} to move it down.
19411943
*/
@@ -2005,7 +2007,7 @@ public void handleMoveLines(boolean moveUp) {
20052007
: textarea.getLineStopOffset(stopLine); // Prevent out-of-bounds
20062008
}
20072009

2008-
textarea.select(newSelectionStart, newSelectionEnd);
2010+
SwingUtilities.invokeLater(() -> textarea.select(newSelectionStart, newSelectionEnd));
20092011
stopCompoundEdit();
20102012
}
20112013

0 commit comments

Comments
 (0)