fix #761 also see #762.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / text / rules / OuterDocumentView.java
index 74abf96..efb1284 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors:
  *     Igor Malinin - initial contribution
  * 
- * $Id: OuterDocumentView.java,v 1.3 2004-09-25 22:42:52 jsurfer Exp $
+ * $Id: OuterDocumentView.java,v 1.5 2006-10-21 23:13:53 pombredanne Exp $
  */
 
 package net.sourceforge.phpeclipse.ui.text.rules;
@@ -149,52 +149,52 @@ public class OuterDocumentView extends AbstractDocument implements
                setTextStore(new TextStore());
                setLineTracker(new DefaultLineTracker());
                int length = getLength();
-               if (length<0) {
-                 length = 0;
+               if (length < 0) {
+                       length = 0;
                }
                getTracker().set(getStore().get(0, length));
+
                completeInitialization();
        }
 
-//     public void addRange(Position range) {
-//             DocumentEvent event = new DocumentEvent(this,
-//                     getLocalOffset(range.offset), range.length, "");
-//             fireDocumentAboutToBeChanged(event);
-//             ranges.add(-getIndex(range) - 1, range);
-//             fireDocumentChanged(event);
-//     }
-//
-//     public void removeRange(Position range) {
-//             String text;
-//             try {
-//                     text = parent.get(range.offset, range.length);
-//             } catch (BadLocationException e) {
-//                     return;
-//             }
-//             DocumentEvent event = new DocumentEvent(this,
-//                     getLocalOffset(range.offset), 0, text);
-//             fireDocumentAboutToBeChanged(event);
-//             deleteRange(range);
-//             fireDocumentChanged(event);
-//     }
-//
-//     public void deleteRange(Position range) {
-//             ranges.remove(getIndex(range));
-//     }
-//
-//     private int getIndex(Position range) {
-//             return Collections.binarySearch(ranges, range, new Comparator() {
-//                     public int compare(Object o1, Object o2) {
-//                             int offset1 = ((Position) o1).offset;
-//                             int offset2 = ((Position) o2).offset;
-//
-//                             if (offset1 < offset2) return -1;
-//                             if (offset1 > offset2) return 1;
-//                             return 0;
-//                     }
-//             });
-//     }
+       // public void addRange(Position range) {
+       // DocumentEvent event = new DocumentEvent(this,
+       // getLocalOffset(range.offset), range.length, "");
+       // fireDocumentAboutToBeChanged(event);
+       // ranges.add(-getIndex(range) - 1, range);
+       // fireDocumentChanged(event);
+       // }
+       //
+       // public void removeRange(Position range) {
+       // String text;
+       // try {
+       // text = parent.get(range.offset, range.length);
+       // } catch (BadLocationException e) {
+       // return;
+       // }
+       // DocumentEvent event = new DocumentEvent(this,
+       // getLocalOffset(range.offset), 0, text);
+       // fireDocumentAboutToBeChanged(event);
+       // deleteRange(range);
+       // fireDocumentChanged(event);
+       // }
+       //
+       // public void deleteRange(Position range) {
+       // ranges.remove(getIndex(range));
+       // }
+       //
+       // private int getIndex(Position range) {
+       // return Collections.binarySearch(ranges, range, new Comparator() {
+       // public int compare(Object o1, Object o2) {
+       // int offset1 = ((Position) o1).offset;
+       // int offset2 = ((Position) o2).offset;
+       //
+       // if (offset1 < offset2) return -1;
+       // if (offset1 > offset2) return 1;
+       // return 0;
+       // }
+       // });
+       // }
 
        /*
         * @see org.eclipse.jface.text.AbstractDocument#fireDocumentAboutToBeChanged(DocumentEvent)
@@ -212,7 +212,7 @@ public class OuterDocumentView extends AbstractDocument implements
                        getTracker().replace(event.getOffset(), event.getLength(),
                                        event.getText());
                } catch (IndexOutOfBoundsException x) {
-                 
+
                } catch (BadLocationException x) {
                }
 
@@ -250,7 +250,7 @@ public class OuterDocumentView extends AbstractDocument implements
         * @see net.sf.wdte.text.rules.IDocumentView#getLocalOffset(int)
         */
        public int getLocalOffset(int parentOffset) {
-//         Assert.isTrue(parentOffset>=0);
+               // Assert.isTrue(parentOffset>=0);
                int localOffset = parentOffset;
 
                Iterator i = ranges.iterator();
@@ -269,10 +269,12 @@ public class OuterDocumentView extends AbstractDocument implements
                        localOffset -= range.length;
                }
                // TODO jsurfer change start - check this
-//        if (localOffset<0) {
-//          return 0;
-//        }
-        // jsurfer change end
+               if (localOffset < 0) {
+                       return 0;
+               } else if (localOffset > getLength()) {
+                       return getLength();
+               }
+               // jsurfer change end
                return localOffset;
        }
 }