界面库

语法高亮支持忽略大小写
This commit is contained in:
JianjunLiu 2022-10-24 13:41:46 +08:00
parent 8dc7a0c6d8
commit b78f2d8bfd
3 changed files with 87 additions and 7 deletions

View File

@ -1838,7 +1838,7 @@ type thighlighter= class(tcustomsynhighlighter)
end end
function publishs();override; function publishs();override;
begin begin
return array("name","keywordcolor","symcolor","stringcolor","annotationcolor"); return array("name","keywordcolor","symcolor","stringcolor","annotationcolor","ignorecase");
end end
end end

View File

@ -3217,19 +3217,51 @@ type tcustomsynhighlighter = class(TSynHighLighter)
property stringcolor:color read fstringcolor write fstringcolor; property stringcolor:color read fstringcolor write fstringcolor;
property annotationcolor:color read fannotationcolor write fannotationcolor; property annotationcolor:color read fannotationcolor write fannotationcolor;
property symcolor:color read fsymcolor write fsymcolor; property symcolor:color read fsymcolor write fsymcolor;
property ignorecase:bool read fignorecase write setignorecase;
private private
function setignorecase(i);
begin
ni := i?true:false;
if ni<>FIgnoreCase then
begin
FIgnoreCase := ni;
for i,v in array(fstrstires ,
fkeystires,
fblockstiresa,
fblockstiresb,
frowstires,
fsymstires) do
begin
for j,vj in v do
begin
vj.ignorecase := ni;
end
end
if fswordpairshashdata then
begin
td := fswordpairshashdata;
setpairs(td);
end
end
end
function dopair(d,bttk); //´¦ÀíÅä¶ÔÐÅÏ¢ function dopair(d,bttk); //´¦ÀíÅä¶ÔÐÅÏ¢
begin begin
n := fswordpairshash[bttk]; if FIgnoreCase then
begin
lttk := lowercase(bttk);
end else
begin
lttk := bttk;
end
n := fswordpairshash[lttk];
if n then if n then
begin begin
st := fcbgestate[n]; st := fcbgestate[n];
if fswordpairs[n][1]=bttk then if fswordpairs[n][1]=lttk then
begin begin
st.GetRight(); st.GetRight();
end else end else
begin begin
st.GetLeft(); st.GetLeft();
end end
d.FMATe := st.GetSate(); d.FMATe := st.GetSate();
@ -3399,17 +3431,24 @@ type tcustomsynhighlighter = class(TSynHighLighter)
begin begin
fswordpairs := array(); fswordpairs := array();
fswordpairshash := array(); fswordpairshash := array();
fswordpairshashdata := array();
for i,v in d do for i,v in d do
begin begin
if not ifarray(v) then continue; if not ifarray(v) then continue;
v0 := v[0]; v0 := v[0];
v1 := v[1]; v1 := v[1];
if FIgnoreCase then
begin
v0 := lowercase(v0);
v1 := lowercase(v1);
end
if ifstring(v0) and ifstring(v1) and v0 and v1 then if ifstring(v0) and ifstring(v1) and v0 and v1 then
begin begin
fswordpairs[v1,0]:= v0; fswordpairs[v1,0]:= v0;
fswordpairs[v1,1]:= v1; fswordpairs[v1,1]:= v1;
fswordpairshash[v0]:=v1; fswordpairshash[v0]:=v1;
fswordpairshash[v1]:=v1; fswordpairshash[v1]:=v1;
fswordpairshashdata[i] := v;
end end
end end
@ -3505,6 +3544,7 @@ type tcustomsynhighlighter = class(TSynHighLighter)
// //
fswordpairs; fswordpairs;
fswordpairshash; fswordpairshash;
fswordpairshashdata;
end end
type TSynCustomMemo = class(TCustomMemo) type TSynCustomMemo = class(TCustomMemo)

View File

@ -1637,19 +1637,23 @@ type TTire = class
FChar; FChar;
FSub; FSub;
FEnd; FEnd;
Ficase;
function Create(v); function Create(v);
begin begin
FChar := v; FChar := v;
FSub := array(); FSub := array();
FEnd := false; FEnd := false;
Ficase := false;
end end
function Add(s); function Add(s);
begin begin
v0 := s[1]; v0 := s[1];
if Ficase then v0 := lowercase(v0);
vsub := FSub[v0]; vsub := FSub[v0];
if not vsub then if not vsub then
begin begin
vsub := new TTireNode(v0); vsub := new TTireNode(v0);
vsub.Ficase := Ficase;
FSub[v0] := vsub; FSub[v0] := vsub;
end end
ls := length(s); ls := length(s);
@ -1664,6 +1668,7 @@ type TTire = class
begin begin
if idx>slen then return FEnd; if idx>slen then return FEnd;
v0 := s[idx]; v0 := s[idx];
if Ficase then v0 := lowercase(v0);
vsub := FSub[v0]; vsub := FSub[v0];
if vsub then if vsub then
begin begin
@ -1672,6 +1677,28 @@ type TTire = class
end end
return FEnd ; return FEnd ;
end end
function seticase(i);
begin
ni := i?true:false;
if ni<>Ficase then
begin
Ficase := ni;
for i,v in mrows(FSub,1) do
begin
vi := FSub[v];
if ni then //ºöÂÔ´óСд
begin
reindex(FSub,array(v:nil));
FSub[lowercase(vi.FChar)] := vi;
end else //Çø·Ö´óСд
begin
reindex(FSub,array(v:nil));
FSub[vi.FChar] := vi;
end
vi.seticase(i);
end
end
end
end end
function Add(s); function Add(s);
begin begin
@ -1679,7 +1706,9 @@ type TTire = class
end end
function Create(); function Create();
begin begin
fignorecase := false;
FRoot := new TTireNode(); FRoot := new TTireNode();
FRoot.Ficase := false;
end end
function Find(s,slen,idx,outidx,ostr); function Find(s,slen,idx,outidx,ostr);
begin begin
@ -1694,6 +1723,17 @@ type TTire = class
return r; return r;
end end
FRoot; FRoot;
property ignorecase read fignorecase write setignorecase;
private
function setignorecase(i);
begin
ni := i?true :false;
if ni<>fignorecase then
begin
FRoot.seticase(ni);
end
end
fignorecase;
end end
type tpairstate =class //À¨ºÅ״̬ type tpairstate =class //À¨ºÅ״̬
function Create(t); function Create(t);