Browse Source

Fixed some source editor bugs

Stan Hebben 6 years ago
parent
commit
c3ee072c2d

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java View File

83
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
83
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
84
 		}
84
 		}
85
 		
85
 		
86
-		long start = System.currentTimeMillis();
86
+		//long start = System.currentTimeMillis();
87
 		Rectangle clipBounds = g.getClipBounds();
87
 		Rectangle clipBounds = g.getClipBounds();
88
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
88
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
89
 		Graphics2D g2d = (Graphics2D) g;
89
 		Graphics2D g2d = (Graphics2D) g;
91
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
91
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
92
 		surface.paint(g2d, clipBounds2);
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
 	@Override
97
 	@Override

+ 3
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java View File

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

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourcePosition.java View File

18
 	private TokenModel.Position position;
18
 	private TokenModel.Position position;
19
 
19
 
20
 	public SourcePosition(TokenModel tokens, int line, int offset) {
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
 		this.tokens = tokens;
26
 		this.tokens = tokens;
22
 		this.line = line;
27
 		this.line = line;
23
 		this.offset = offset;
28
 		this.offset = offset;

+ 10
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenLine.java View File

54
 		}
54
 		}
55
 		return indent.toString();
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
 	public void add(ZSToken token) {
68
 	public void add(ZSToken token) {
59
 		insert(tokens.size(), token);
69
 		insert(tokens.size(), token);

+ 9
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java View File

193
 		if (!remainder.isEmpty())
193
 		if (!remainder.isEmpty())
194
 			getLine(fromT.line).insert(fromT.token, new ZSToken(ZSTokenType.INVALID, remainder));
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
 	public void insert(SourcePosition position, String value) {
199
 	public void insert(SourcePosition position, String value) {
201
 		Position tokenPosition = position.asTokenPosition();
201
 		Position tokenPosition = position.asTokenPosition();
202
 		ZSToken token = getTokenAt(tokenPosition);
202
 		ZSToken token = getTokenAt(tokenPosition);
203
 		if (token == null) {
203
 		if (token == null) {
204
-			line.add(new ZSToken(ZSTokenType.INVALID, value));
204
+			line.addTemporary(new ZSToken(ZSTokenType.INVALID, value));
205
 		} else {
205
 		} else {
206
 			token = token.insert(tokenPosition.offset, value);
206
 			token = token.insert(tokenPosition.offset, value);
207
 			line.replace(tokenPosition.token, token);
207
 			line.replace(tokenPosition.token, token);
336
 		public final int offset;
336
 		public final int offset;
337
 		
337
 		
338
 		public Position(int line, int token, int offset) {
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
 			this.line = line;
346
 			this.line = line;
340
 			this.token = token;
347
 			this.token = token;
341
 			this.offset = offset;
348
 			this.offset = offset;

Loading…
Cancel
Save