Mercurial > projects > dwt2
comparison org.eclipse.text/src/org/eclipse/jface/text/link/InclusivePositionUpdater.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | 5feec68b4556 |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.jface.text.link.InclusivePositionUpdater; | |
14 | |
15 import org.eclipse.jface.text.link.LinkedModeModel; // packageimport | |
16 import org.eclipse.jface.text.link.LinkedPosition; // packageimport | |
17 import org.eclipse.jface.text.link.ILinkedModeListener; // packageimport | |
18 import org.eclipse.jface.text.link.TabStopIterator; // packageimport | |
19 import org.eclipse.jface.text.link.LinkedModeUI; // packageimport | |
20 import org.eclipse.jface.text.link.LinkedPositionGroup; // packageimport | |
21 import org.eclipse.jface.text.link.LinkedModeManager; // packageimport | |
22 import org.eclipse.jface.text.link.LinkedPositionAnnotations; // packageimport | |
23 import org.eclipse.jface.text.link.ProposalPosition; // packageimport | |
24 | |
25 | |
26 import java.lang.all; | |
27 import java.util.Set; | |
28 | |
29 import org.eclipse.jface.text.BadPositionCategoryException; | |
30 import org.eclipse.jface.text.DocumentEvent; | |
31 import org.eclipse.jface.text.IPositionUpdater; | |
32 import org.eclipse.jface.text.Position; | |
33 | |
34 | |
35 /** | |
36 * Position updater that considers any change in | |
37 * <code>[p.offset, p.offset + p.length]</code> of a {@link Position} | |
38 * <code>p</code> as belonging to the position. | |
39 * <p> | |
40 * Internal class. Do not use. Public for testing purposes only. | |
41 * </p> | |
42 * | |
43 * @since 3.0 | |
44 * @noinstantiate This class is not intended to be instantiated by clients. | |
45 * @noextend This class is not intended to be subclassed by clients. | |
46 */ | |
47 public class InclusivePositionUpdater : IPositionUpdater { | |
48 | |
49 /** The position category. */ | |
50 private const String fCategory; | |
51 | |
52 /** | |
53 * Creates a new updater for the given <code>category</code>. | |
54 * | |
55 * @param category the new category. | |
56 */ | |
57 public this(String category) { | |
58 fCategory= category; | |
59 } | |
60 | |
61 /* | |
62 * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent) | |
63 */ | |
64 public void update(DocumentEvent event) { | |
65 | |
66 int eventOffset= event.getOffset(); | |
67 int eventOldLength= event.getLength(); | |
68 int eventNewLength= event.getText() is null ? 0 : event.getText().length(); | |
69 int deltaLength= eventNewLength - eventOldLength; | |
70 | |
71 try { | |
72 Position[] positions= event.getDocument().getPositions(fCategory); | |
73 | |
74 for (int i= 0; i !is positions.length; i++) { | |
75 | |
76 Position position= positions[i]; | |
77 | |
78 if (position.isDeleted()) | |
79 continue; | |
80 | |
81 int offset= position.getOffset(); | |
82 int length= position.getLength(); | |
83 int end= offset + length; | |
84 | |
85 if (offset > eventOffset + eventOldLength) | |
86 // position comes way | |
87 // after change - shift | |
88 position.setOffset(offset + deltaLength); | |
89 else if (end < eventOffset) { | |
90 // position comes way before change - | |
91 // leave alone | |
92 } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { | |
93 // event completely internal to the position - adjust length | |
94 position.setLength(length + deltaLength); | |
95 } else if (offset < eventOffset) { | |
96 // event extends over end of position - adjust length | |
97 int newEnd= eventOffset + eventNewLength; | |
98 position.setLength(newEnd - offset); | |
99 } else if (end > eventOffset + eventOldLength) { | |
100 // event extends from before position into it - adjust offset | |
101 // and length | |
102 // offset becomes end of event, length adjusted accordingly | |
103 // we want to recycle the overlapping part | |
104 position.setOffset(eventOffset); | |
105 int deleted= eventOffset + eventOldLength - offset; | |
106 position.setLength(length - deleted + eventNewLength); | |
107 } else { | |
108 // event consumes the position - delete it | |
109 position.delete_(); | |
110 } | |
111 } | |
112 } catch (BadPositionCategoryException e) { | |
113 // ignore and return | |
114 } | |
115 } | |
116 | |
117 /** | |
118 * Returns the position category. | |
119 * | |
120 * @return the position category | |
121 */ | |
122 public String getCategory() { | |
123 return fCategory; | |
124 } | |
125 | |
126 } |