Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 11 package org.eclipse.jface.internal.text; 12 13 import org.eclipse.jface.text.BadPositionCategoryException; 14 import org.eclipse.jface.text.DocumentEvent; 15 import org.eclipse.jface.text.IPositionUpdater; 16 import org.eclipse.jface.text.Position; 17 18 19 28 public final class NonDeletingPositionUpdater implements IPositionUpdater { 29 30 private final String fCategory; 31 32 37 public NonDeletingPositionUpdater(String category) { 38 fCategory= category; 39 } 40 41 44 public void update(DocumentEvent event) { 45 46 int eventOffset= event.getOffset(); 47 int eventOldEndOffset= eventOffset + event.getLength(); 48 int eventNewLength= event.getText() == null ? 0 : event.getText().length(); 49 int eventNewEndOffset= eventOffset + eventNewLength; 50 int deltaLength= eventNewLength - event.getLength(); 51 52 try { 53 Position[] positions= event.getDocument().getPositions(fCategory); 54 55 for (int i= 0; i != positions.length; i++) { 56 57 Position position= positions[i]; 58 59 if (position.isDeleted()) 60 continue; 61 62 int offset= position.getOffset(); 63 int length= position.getLength(); 64 int end= offset + length; 65 66 if (offset > eventOldEndOffset) { 67 position.setOffset(offset + deltaLength); 69 } else if (end < eventOffset) { 70 } else if (offset <= eventOffset && end >= eventOldEndOffset) { 72 position.setLength(length + deltaLength); 74 } else if (offset < eventOffset) { 75 position.setLength(eventNewEndOffset - offset); 78 } else if (end > eventOldEndOffset) { 79 position.setOffset(eventOffset); 83 int deleted= eventOldEndOffset - offset; 84 position.setLength(length - deleted + eventNewLength); 85 } else { 86 int newOffset= Math.min(offset, eventNewEndOffset); 89 int newEndOffset= Math.min(end, eventNewEndOffset); 90 position.setOffset(newOffset); 91 position.setLength(newEndOffset - newOffset); 92 } 93 } 94 } catch (BadPositionCategoryException e) { 95 } 97 } 98 99 104 public String getCategory() { 105 return fCategory; 106 } 107 } 108
| Popular Tags
|