Selaa lähdekoodia

Fixed some source editor bugs

Stan Hebben 6 vuotta sitten
vanhempi
commit
c3ee072c2d

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java Näytä tiedosto

@@ -83,7 +83,7 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
83 83
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
84 84
 		}
85 85
 		
86
-		long start = System.currentTimeMillis();
86
+		//long start = System.currentTimeMillis();
87 87
 		Rectangle clipBounds = g.getClipBounds();
88 88
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
89 89
 		Graphics2D g2d = (Graphics2D) g;
@@ -91,7 +91,7 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
91 91
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
92 92
 		surface.paint(g2d, clipBounds2);
93 93
 		
94
-		System.out.println("Paint in " + (System.currentTimeMillis() - start) + " ms, bounds: " + clipBounds.toString());
94
+		//System.out.println("Paint in " + (System.currentTimeMillis() - start) + " ms, bounds: " + clipBounds.toString());
95 95
 	}
96 96
 
97 97
 	@Override

+ 3
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java Näytä tiedosto

@@ -745,6 +745,9 @@ public class SourceEditor implements DComponent {
745 745
 		public void onLineDeleted(int index) {
746 746
 			onLinesUpdated();
747 747
 			
748
+			if (index >= lineNumbers.size())
749
+				return;
750
+			
748 751
 			if (bounds != null) {
749 752
 				lineNumbers.remove(lineNumbers.size() - 1).close();
750 753
 				removeLineTokens(drawnTokens.remove(index));

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourcePosition.java Näytä tiedosto

@@ -18,6 +18,11 @@ public class SourcePosition {
18 18
 	private TokenModel.Position position;
19 19
 
20 20
 	public SourcePosition(TokenModel tokens, int line, int offset) {
21
+		if (line < 0)
22
+			throw new IllegalArgumentException("line cannot be negative");
23
+		if (offset < 0)
24
+			throw new IllegalArgumentException("offset cannot be negative");
25
+		
21 26
 		this.tokens = tokens;
22 27
 		this.line = line;
23 28
 		this.offset = offset;

+ 10
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenLine.java Näytä tiedosto

@@ -54,6 +54,16 @@ public final class TokenLine {
54 54
 		}
55 55
 		return indent.toString();
56 56
 	}
57
+	
58
+	/**
59
+	 * Adds a temporary token. This token must be relexed later using the relexer.
60
+	 * 
61
+	 * @param token 
62
+	 */
63
+	public void addTemporary(ZSToken token) {
64
+		tokens.add(token);
65
+		length += token.content.length();
66
+	}
57 67
 
58 68
 	public void add(ZSToken token) {
59 69
 		insert(tokens.size(), token);

+ 9
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java Näytä tiedosto

@@ -193,7 +193,7 @@ public class TokenModel {
193 193
 		if (!remainder.isEmpty())
194 194
 			getLine(fromT.line).insert(fromT.token, new ZSToken(ZSTokenType.INVALID, remainder));
195 195
 		
196
-		relex(fromT.line, Math.max(0, fromT.token - 1), fromT.line, fromT.token + 1);
196
+		relex(fromT.line, Math.max(0, fromT.token - 1), fromT.line, Math.min(lines.get(fromT.line).getTokenCount(), fromT.token + 1));
197 197
 	}
198 198
 	
199 199
 	public void insert(SourcePosition position, String value) {
@@ -201,7 +201,7 @@ public class TokenModel {
201 201
 		Position tokenPosition = position.asTokenPosition();
202 202
 		ZSToken token = getTokenAt(tokenPosition);
203 203
 		if (token == null) {
204
-			line.add(new ZSToken(ZSTokenType.INVALID, value));
204
+			line.addTemporary(new ZSToken(ZSTokenType.INVALID, value));
205 205
 		} else {
206 206
 			token = token.insert(tokenPosition.offset, value);
207 207
 			line.replace(tokenPosition.token, token);
@@ -336,6 +336,13 @@ public class TokenModel {
336 336
 		public final int offset;
337 337
 		
338 338
 		public Position(int line, int token, int offset) {
339
+			if (line < 0)
340
+				throw new IllegalArgumentException("line cannot be negative");
341
+			if (token < 0)
342
+				throw new IllegalArgumentException("token cannot be negative");
343
+			if (offset < 0)
344
+				throw new IllegalArgumentException("offset cannot be negative");
345
+			
339 346
 			this.line = line;
340 347
 			this.token = token;
341 348
 			this.offset = offset;

Loading…
Peruuta
Tallenna