编辑器

加速文件查找
This commit is contained in:
JianjunLiu
2023-04-11 10:31:54 +08:00
parent a7dea9b2cd
commit 0a4713c591
6 changed files with 589 additions and 5645 deletions
+117 -1
View File
@@ -3801,10 +3801,123 @@ type TEditer=class(TCustomcontrol) //
end
//fo.SetStatusText(format("共替换:%d 处",idx));
end
function matchword(f,d);
begin
wr := d["c_wrap"];
cw := d["c_case"];
tg := d["target"];
if not tg then return ;
ctl2 := "m";
if not d["c_reg"] then
begin
ntg := "";
ltg := length(tg);
for i := 1 to length(tg) do
begin
vi := tg[i];
cvi := ord(vi);
if cvi>=9 and cvi<=13 then
begin
ntg +="\\s";
if i=1 then wrp :=1;
if i=ltg then wrp .|= 2;
end else
if (cvi>=0x21 and cvi<=0x2f) or
(cvi>=0x3a and cvi<=0x40) or
(cvi>=0x5b and cvi<=0x60) or
(cvi>=0x7b and cvi<=0x7e) then
begin
ntg +="\\"+vi;
if i=1 then wrp :=1;
if i=ltg then wrp .|= 2;
end else
begin
ntg+=vi;
end
end
tg := ntg;
end
ctl := tg;
if wr then
begin
if not((wrp .& 1) >1) then ctl := "\\b"+ctl;
if not((wrp .& 2) >1) then ctl := ctl+"\\b";
end
if cw then ctl2 += "i";
linesi := array(1:1);
if (1 = readfile(rwraw(),"",f,0,filesize("",f),s)) and s then
begin
if 1= parseregexpr(ctl,s,ctl2,m,mp,mlen) then
begin
r := array();
idx := 1;
rid := 1;
jid := 1;
ip := 1;
if pos("\r\n",s) or pos("\n",s) then
begin
fgf := "\n";
end else
fgf := "\r";
for i,v in m do
begin
mi := mp[i,0];
while idx<mi do
begin
vi := s[idx];
idx++;
jid++;
if vi=fgf then
begin
linesi[rid]:=idx;
rid++;
jid := 1;
end
end
r[i][0] := rid; //行
r[i][1] := jid; //列
p1 := linesi[rid-1];
p2 := idx+mlen[i,0]-1;
if (p2>p1) and (rid<>orid) then
begin
r[i][2] := trim(s[p1:p2]);
end
else r[i,2] := "";
orid := rid;
end
return r;
end
end
end
function FindInFiles(d,o,rep,ct);
begin
fs := GetFilesFormSearchInfo(d);
ct := 0;
if not rep then
begin
for i,v in fs do
begin
ri := matchword(i,d);
if ri then
begin
ril := length(ri);
FFindListWnd.AppendItem(array("caption":format("find:%s in file:%s has:%d",d["target"],i,ril)));
orii := -1;
for ii,vi in ri do
begin
rii := vi[0];
ct++;
if orii=rii then continue;
orii := rii;
scap := format(" %d:(第%d行) ",ct,rii)+limitstringlength(vi[2]);
FFindListWnd.AppendItem(array("caption":scap,"file":i,"line":rii));
end
end
end
return ;
end
for i,v in fs do
begin
if not FIsFinding then break;
@@ -3967,7 +4080,10 @@ type TEditer=class(TCustomcontrol) //
end
function FindAllInCurrent(data,fo,it,rt);
begin
if rt = "noshow" then fnoshow := true;
if rt = "noshow" then
begin
fnoshow := true;
end
rt := 0;
if not it then it := GetCurrentItem();
if not it then return;