1
1
class APLField extends Drawable implements TextReciever {
2
- float tsz;
2
+ float tsz, chw ;
3
3
SyntaxHighlight hl;
4
4
Theme th = new Theme ();
5
5
6
6
float extraH = 1.2 ;
7
+ float xoff = 0 ;
7
8
8
9
APLField (int x , int y , int w , int h ) {
9
10
this (x, y, w, h, " " );
@@ -18,6 +19,8 @@ class APLField extends Drawable implements TextReciever {
18
19
19
20
void redraw () {
20
21
tsz = h/ extraH;
22
+ textSize (tsz);
23
+ chw = textWidth (" H" );
21
24
}
22
25
boolean saveUndo = true ;
23
26
boolean modified = false ;
@@ -29,6 +32,13 @@ class APLField extends Drawable implements TextReciever {
29
32
if (mousePressed && ! pmousePressed && smouseIn()) {
30
33
textInput = this ;
31
34
}
35
+ if (mousePressed && smouseIn()) {
36
+ xoff+= mouseX - pmouseX ;
37
+ }
38
+ float maxx = w* . 8 / chw > line. length()? 0 : (line. length() - 2 )* chw;
39
+ if (xoff < - maxx) xoff = (int ) - maxx;
40
+ if (xoff > 0 ) xoff = 0 ;
41
+
32
42
if (modified || saveUndo) {
33
43
modified();
34
44
hl = new SyntaxHighlight (line, th, g);
@@ -43,7 +53,7 @@ class APLField extends Drawable implements TextReciever {
43
53
clip(x, y, w, h);
44
54
if (pmousePressed && ! mousePressed && smouseIn() && dist (mouseX , mouseY , smouseX, smouseY) < 10 ) {
45
55
textSize (tsz);
46
- sx = constrain (round ((mouseX - x)/ textWidth (" H" )), 0 , line. length());
56
+ sx = constrain (round ((mouseX - x- xoff )/ textWidth (" H" )), 0 , line. length());
47
57
ex = sx;
48
58
tt = 0 ;
49
59
}
@@ -52,18 +62,18 @@ class APLField extends Drawable implements TextReciever {
52
62
rectMode (CORNER );
53
63
rect (x, y, w, h);
54
64
// text(line, x, y + dy*tsz + h*.1);
55
- if (apl()) hl. draw(x, y , tsz, sx); // SyntaxHighlight.apltext(line, x, y + dy*tsz + h*.1, tsz, new Theme(), g);
65
+ if (apl()) hl. draw(x + xoff, textY(y, tsz) , tsz, sx); // SyntaxHighlight.apltext(line, x, y + dy*tsz + h*.1, tsz, new Theme(), g);
56
66
else {
57
67
fill (#D2D2D2 );
58
68
g. textAlign(LEFT , TOP );
59
69
textSize (tsz);
60
- text (line, x, y );
70
+ text (line, x + xoff, textY(y, tsz) );
61
71
}
62
72
tt-- ;
63
73
if (tt < 0 ) tt = 60 ;
64
74
65
- float spx = x + max (textWidth (line. substring(0 , sx)), 3 );
66
- float epx = x + max (textWidth (line. substring(0 , ex)), 3 );
75
+ float spx = x + max (textWidth (line. substring(0 , sx)), 3 ) + xoff ;
76
+ float epx = x + max (textWidth (line. substring(0 , ex)), 3 ) + xoff ;
67
77
float sy = y + h* . 1 ;
68
78
float ey = y + h* . 9 ;
69
79
if (tt > 30 || this != textInput) {
@@ -104,6 +114,8 @@ class APLField extends Drawable implements TextReciever {
104
114
if (! one()) line = line. substring(0 , min) + line. substring(max);
105
115
ex = min;
106
116
sx = min;
117
+ modified = true ;
118
+ saveUndo = true ;
107
119
}
108
120
void append (String str ) {
109
121
deleteSel();
@@ -195,6 +207,10 @@ class APLField extends Drawable implements TextReciever {
195
207
else if (s. equals(" paste" )) {
196
208
paste(this );
197
209
}
210
+ else if (s. equals(" match" )) {
211
+ int sel = hl. sel(sx);
212
+ if (sel != - 1 ) sx = ex = sel;
213
+ }
198
214
else extraSpecial(s);
199
215
}
200
216
void pasted (String s ) {
0 commit comments