mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-08 19:28:08 +00:00
faster syntax highlighting
This commit is contained in:
@@ -41,6 +41,7 @@ public class SyntaxDocument extends PlainDocument {
|
||||
Lexer lexer;
|
||||
List<Token> tokens;
|
||||
CompoundUndoMan undo;
|
||||
boolean ignoreUpdate;
|
||||
|
||||
public SyntaxDocument(Lexer lexer) {
|
||||
super();
|
||||
@@ -62,12 +63,12 @@ public class SyntaxDocument extends PlainDocument {
|
||||
tokens = null;
|
||||
return;
|
||||
}
|
||||
List<Token> toks = new ArrayList<Token>(getLength() / 10);
|
||||
long ts = System.nanoTime();
|
||||
int len = getLength();
|
||||
List<Token> toks = new ArrayList<Token>(len / 10);
|
||||
long ts = System.nanoTime();
|
||||
try {
|
||||
Segment seg = new Segment();
|
||||
getText(0, getLength(), seg);
|
||||
getText(0, len, seg);
|
||||
lexer.parse(seg, 0, toks);
|
||||
} catch (BadLocationException ex) {
|
||||
log.log(Level.SEVERE, null, ex);
|
||||
@@ -88,6 +89,9 @@ public class SyntaxDocument extends PlainDocument {
|
||||
|
||||
@Override
|
||||
protected void fireInsertUpdate(DocumentEvent e) {
|
||||
if (ignoreUpdate) {
|
||||
return;
|
||||
}
|
||||
parse();
|
||||
super.fireInsertUpdate(e);
|
||||
}
|
||||
@@ -98,6 +102,13 @@ public class SyntaxDocument extends PlainDocument {
|
||||
super.fireRemoveUpdate(e);
|
||||
}
|
||||
|
||||
public void setIgnoreUpdate(boolean value) {
|
||||
ignoreUpdate = value;
|
||||
if (!ignoreUpdate) {
|
||||
parse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the token with the replacement string
|
||||
* @param token
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
@@ -221,9 +222,18 @@ public class LineNumbersRuler extends JPanel
|
||||
int maxLines = ActionUtils.getLineCount(editor);
|
||||
SyntaxView.setRenderingHits((Graphics2D) g);
|
||||
|
||||
Rectangle bounds = g.getClipBounds();
|
||||
int minY = bounds.y;
|
||||
int maxY = minY + bounds.height;
|
||||
for (int line = 1; line <= maxLines; line++) {
|
||||
String lineNumber = String.format(numbersFormat, line);
|
||||
int y = line * lh;
|
||||
if (y < minY) {
|
||||
continue;
|
||||
}
|
||||
if (y - lh > maxY) {
|
||||
break;
|
||||
}
|
||||
String lineNumber = String.format(numbersFormat, line);
|
||||
if (line == currentLine) {
|
||||
g.setColor(currentLineColor);
|
||||
g.fillRect(0, y - lh + fontMetrics.getDescent() - 1, getWidth(), lh);
|
||||
|
||||
@@ -355,6 +355,6 @@ Preprocessor = \u00A7\u00A7 {Identifier}
|
||||
}
|
||||
|
||||
/* error fallback */
|
||||
.|\n { }
|
||||
[^] { }
|
||||
<<EOF>> { return null; }
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import jsyntaxpane.TokenType;
|
||||
|
||||
%{
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
StringBuilder string = new StringBuilder();
|
||||
|
||||
|
||||
/**
|
||||
@@ -150,5 +150,5 @@ Constant= constant{NumberLiteral}
|
||||
}
|
||||
|
||||
/* error fallback */
|
||||
.|\n { }
|
||||
[^] { }
|
||||
<<EOF>> { return null; }
|
||||
|
||||
@@ -19,7 +19,7 @@ import jsyntaxpane.TokenType;
|
||||
|
||||
%{
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
StringBuilder string = new StringBuilder();
|
||||
boolean isMultiname=false;
|
||||
|
||||
|
||||
@@ -249,5 +249,5 @@ ExceptionTarget = "exceptiontarget "{PositiveNumberLiteral}":"
|
||||
}
|
||||
|
||||
/* error fallback */
|
||||
.|\n { }
|
||||
[^] { }
|
||||
<<EOF>> { return null; }
|
||||
|
||||
@@ -18,7 +18,7 @@ import jsyntaxpane.TokenType;
|
||||
|
||||
%{
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
StringBuilder string = new StringBuilder();
|
||||
boolean isMultiname=false;
|
||||
|
||||
|
||||
@@ -146,5 +146,5 @@ StringCharacter = [^\r\n\"\\]
|
||||
}
|
||||
|
||||
/* error fallback */
|
||||
.|\n { }
|
||||
[^] { }
|
||||
<<EOF>> { return null; }
|
||||
@@ -18,7 +18,7 @@ import jsyntaxpane.TokenType;
|
||||
|
||||
%{
|
||||
|
||||
StringBuffer string = new StringBuffer();
|
||||
StringBuilder string = new StringBuilder();
|
||||
private int tokenStart = -1;
|
||||
|
||||
private static final byte BRACKET = 1;
|
||||
@@ -89,5 +89,5 @@ Divider = [ \r\n]+
|
||||
}
|
||||
|
||||
/* error fallback */
|
||||
.|\n { }
|
||||
[^] { }
|
||||
<<EOF>> { return null; }
|
||||
|
||||
Reference in New Issue
Block a user