Addition of previous bugfix. Adjusting cursor positioning.
authortoshihiro <toshihiro>
Mon, 18 Jun 2007 13:12:24 +0000 (13:12 +0000)
committertoshihiro <toshihiro>
Mon, 18 Jun 2007 13:12:24 +0000 (13:12 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/actions/RTrimAction.java

index d0da3ca..a014e9e 100644 (file)
@@ -96,16 +96,45 @@ public class RTrimAction implements IEditorActionDelegate {
                                        String newText = oldText.substring(0, lineEnd) + lineDelimiter;
                                        doc.replace(offset, length, newText);
 
-                                       if (offset + length <= cursorOffset) {
-                                               if (oldText.length() != newText.length()) {
-                                                       cursorOffset -= oldText.length() - newText.length();
+//                                     if (offset + length <= cursorOffset) {
+//                                             if (oldText.length() != newText.length()) {
+//                                                     cursorOffset -= oldText.length() - newText.length();
+//                                             }
+//                                     } else if (offset <= cursorOffset + selectionLength
+//                                                     && selectionLength > 0) {
+//                                             selectionLength -= oldText.length() - newText.length();
+//                                     } else if (offset + length == cursorOffset + 2) {
+//                                             // Check if the cursor is at the end of the line.
+//                                             cursorOffset -= 2;
+//                                     }
+
+                                       int oldEndOffset = offset + length - lineDelimiter.length();
+                                       int newEndOffset = offset + lineEnd;
+
+                                       if (cursorOffset >= oldEndOffset) {
+                                               cursorOffset -= oldText.length() - newText.length();
+                                       } else if (cursorOffset >= newEndOffset) {
+                                               cursorOffset = newEndOffset;
+                                       }
+                                       if (selectionLength > 0) {
+                                               int selectionEndOffset = cursorOffset + selectionLength;
+                                               if (selectionEndOffset >= oldEndOffset) {
+                                                       if (cursorOffset <= newEndOffset) {
+                                                               // full overlap
+                                                               selectionLength -= oldText.length() - newText.length();
+                                                       } else {
+                                                               // starts inside
+                                                               selectionLength -= oldEndOffset - cursorOffset;
+                                                       }
+                                               } else if (selectionEndOffset >= newEndOffset) {
+                                                       if (cursorOffset <= newEndOffset) {
+                                                               // ends inside
+                                                               selectionLength -= selectionEndOffset - newEndOffset;
+                                                       } else {
+                                                               // full inside
+                                                               selectionLength = 0;
+                                                       }
                                                }
-                                       } else if (offset <= cursorOffset + selectionLength
-                                                       && selectionLength > 0) {
-                                               selectionLength -= oldText.length() - newText.length();
-                                       } else if (offset + length == cursorOffset + 2) {
-                                               // Check if the cursor is at the end of the line.
-                                               cursorOffset -= 2;
                                        }
                                }
                                currentLine++;