编辑器

优化代码
This commit is contained in:
JianjunLiu 2022-09-14 16:39:54 +08:00
parent 023c4eb967
commit a89d92ad42
4 changed files with 90 additions and 64 deletions

View File

@ -1,9 +1,11 @@
unit UTslCodeFormat;
interface
uses utslvclauxiliary;
//TSL代码格式化 code 为代码,tabwidth 为缩进空格数 LineWordCount 为单行最大的词数目 linelength 字符最多个数
//20210311 美化了函数定义换行的问题
//20210406 LineWordCount linelength 两个参数已经不起作用
//20210308 添加 ABComment 参数,控制块注释的行首缩进
//20220914 移动tire树到 utslvclauxiliary
function FormatTsl(Code,tabwidth,LineWordCount,linelength,arraytype,ABComment);
type TTslFParser = class(TFormatParser)
function Create();
@ -1460,69 +1462,7 @@ Type TTK = class
FTypeSub := st ;
end
end
type TTire = class
type TTireNode = class
FChar;
FSub;
FEnd;
function Create(v);
begin
FChar := v;
FSub := array();
FEnd := false;
end
function Add(s);
begin
v0 := s[1];
vsub := FSub[v0];
if not vsub then
begin
vsub := new TTireNode(v0);
FSub[v0] := vsub;
end
ls := length(s);
if ls>1 then
vsub.Add(s[2:]);
else
begin
vsub.FEnd := true;
end
end
function Find(s,slen,idx);
begin
if idx>slen then return FEnd;
v0 := s[idx];
vsub := FSub[v0];
if vsub then
begin
idx++;
return vsub.Find(s,slen,idx);
end
return FEnd ;
end
end
function Add(s);
begin
FRoot.Add(s);
end
function Create();
begin
FRoot := new TTireNode();
end
function Find(s,slen,idx,outidx,ostr);
begin
tid := idx;
r := FRoot.Find(s,slen,idx);
if r then
begin
ostr := s[tid:idx-1];
outidx := idx;
end
idx := tid;
return r;
end
FRoot;
end
Type TStateStack = class
function Create();
begin

View File

@ -310,6 +310,7 @@ type TTslSynHighLighter = class(TSynHighLighter)
begin
idx := max(1,idx);
if not(FChangeDeal) and idx>FSatesCount then return ;
fdolastline := idx-2;
if length(FSates)>=idx then
FSatesCount := idx;
else FSatesCount := length(FSates)-1;
@ -975,7 +976,8 @@ type TTslSynHighLighter = class(TSynHighLighter)
FChangeDeal := true;
{setprofiler(7);
t := now();}
mtic;
if fdolastline>=LastLine then return ;
fdolastline := LastLine;
for i:= FSatesCount-1 to LastLine do
begin
if i<0 then continue;
@ -1114,6 +1116,7 @@ type TTslSynHighLighter = class(TSynHighLighter)
static FJsHtmlEvent;
static FCssPropertys;
private
fdolastline;
FChangeDeal;
//ÓïÑÔ·ÖÖ§
FSynBranch;
@ -1256,6 +1259,7 @@ type TJsonSynHighLighter = class(TSynHighLighter)
begin
idx := max(1,idx);
if not(FChangeDeal) and idx>FSatesCount then return ;
fdolastline := idx-2;
if length(FSates)>=idx then
FSatesCount := idx;
else FSatesCount := length(FSates)-1;
@ -1342,6 +1346,8 @@ label L_XCDG;
begin
ls := Lines;
FChangeDeal := true;
if fdolastline>=LastLine then return ;
fdolastline := LastLine;
for i:= FSatesCount-1 to LastLine do
begin
if i<0 then continue;
@ -1456,6 +1462,7 @@ label L_XCDG;
end
private
fdolastline;
FTokens;
FSates;
FSatesCount;
@ -1496,6 +1503,7 @@ type ttfmhighlighter = class(TSynHighLighter)
begin
idx := max(1,idx);
if not(FChangeDeal) and idx>FSatesCount then return ;
fdolastline := idx-2;
if length(FSates)>=idx then
FSatesCount := idx;
else FSatesCount := length(FSates)-1;
@ -1587,6 +1595,8 @@ label L_XCDG;
begin
ls := Lines;
FChangeDeal := true;
if fdolastline>=LastLine then return ;
fdolastline := LastLine;
for i:= FSatesCount-1 to LastLine do
begin
if i<0 then continue;
@ -1727,6 +1737,7 @@ label L_XCDG;
end
private
fdolastline;
FTokens;
FSates;
FSatesCount;

View File

@ -31,6 +31,14 @@ type tsgtkapi = class(tgtkapis)
function shell32DllGetVersion();
begin
end
function GetSystemMetrics(idx);
begin
global g_w_c_width;
case idx of
0x4 : return g_w_c_width;
end ;
return 24;
end
function GetCursorInfo_();
begin
end

View File

@ -2,6 +2,7 @@ unit utslvclauxiliary;
{**
@explan(˵Ã÷) tslvcl ¸¨Öú¿â %%
**}
//20220914 ÒÆÈëtireÊ÷
interface
function includestate(u,s);
function excludestate(u,s);
@ -1628,6 +1629,72 @@ type TNode = class()
return FItems.Count;
end
end
type TTire = class
{**
@explan(˵Ã÷) tireÊ÷
**}
type TTireNode = class
FChar;
FSub;
FEnd;
function Create(v);
begin
FChar := v;
FSub := array();
FEnd := false;
end
function Add(s);
begin
v0 := s[1];
vsub := FSub[v0];
if not vsub then
begin
vsub := new TTireNode(v0);
FSub[v0] := vsub;
end
ls := length(s);
if ls>1 then
vsub.Add(s[2:]);
else
begin
vsub.FEnd := true;
end
end
function Find(s,slen,idx);
begin
if idx>slen then return FEnd;
v0 := s[idx];
vsub := FSub[v0];
if vsub then
begin
idx++;
return vsub.Find(s,slen,idx);
end
return FEnd ;
end
end
function Add(s);
begin
FRoot.Add(s);
end
function Create();
begin
FRoot := new TTireNode();
end
function Find(s,slen,idx,outidx,ostr);
begin
tid := idx;
r := FRoot.Find(s,slen,idx);
if r then
begin
ostr := s[tid:idx-1];
outidx := idx;
end
idx := tid;
return r;
end
FRoot;
end
implementation
function includestate(u,s);
begin