📄 jvunicodehleditor.pas
字号:
I := P - F + 1;
end
else
I := L1 + 1;
end;
end;
hlCocoR:
case FLong of
lgNone: // not in comment
case S[I] of
'(':
if {S[I + 1]} F[I] = '*' then
begin
FLong := lgComment2;
P := StrScanW(F + I + 2, WideChar(')'));
if P = nil then
Break
else
begin
if P[-1] = '*' then
FLong := lgNone;
I := P - F + 1;
end;
end;
'"':
begin
P := StrScanW(F + I + 1, WideChar('"'));
if P <> nil then
begin
i1 := P - F;
if P[1] <> '"' then
I := i1
else
{ ?? }
end
else
I := L1 + 1;
end;
'''':
begin
P := StrScanW(F + I + 1, WideChar(''''));
if P <> nil then
begin
i1 := P - F;
if P[1] <> '''' then
I := i1
else
{ ?? }
end
else
I := L1 + 1;
end;
'/':
if {S[I + 1]} F[I] = '*' then
begin
FLong := lgComment2;
P := StrScanW(F + I + 2, WideChar('/'));
if P = nil then
Break
else
begin
if P[-1] = '*' then
FLong := lgNone;
I := P - F + 1;
end;
end;
end;
lgComment2:
begin // (*
P := StrScanW(F + I, WideChar(')'));
if P = nil then
Break
else
begin
if P[-1] = '*' then
FLong := lgNone;
I := P - F + 1;
end;
end;
end;
end;
Inc(I);
end;
if (FHighlighter = hlCocoR) and
(StrLICompW2(PWideChar(S), 'productions', Length('productions')) = 0) then
begin
ProductionsLine := iLine;
end;
end;
Inc(iLine);
if FLongDesc[iLine] <> FLong then
begin
FLongDesc[iLine] := FLong;
Result := True; // Invalidate
end;
end;
// undefine following lines
if MaxScanLine < MaxLine then
FillChar(FLongDesc[MaxScanLine + 1], SizeOf(FLongDesc[0]) * (MaxLine - MaxScanLine), lgUndefined);
end;
function TJvWideHLEditor.FindLongEnd: Integer;
var
P, F: PWideChar;
I: Integer;
begin
P := PWideChar(FLine);
Result := Length(FLine);
case FHighlighter of
hlPascal:
case FLong of
lgPreproc1, lgComment1:
begin
P := StrScanW(P, WideChar('}'));
if P <> nil then
Result := P - PWideChar(FLine);
end;
lgPreproc2, lgComment2:
begin
F := P;
while True do
begin
F := StrScanW(F, WideChar('*'));
if F = nil then
Exit;
if F[1] = ')' then
Break;
Inc(F);
end;
P := F + 1;
Result := P - PWideChar(FLine);
end;
end;
hlCBuilder, hlSql, hlJava, hlPhp, hlNQC:
begin
case FLong of
lgComment2:
begin
F := P;
while True do
begin
F := StrScanW(F, WideChar('*'));
if F = nil then
Exit;
if F[1] = '/' then
Break;
Inc(F);
end;
P := F + 1;
Result := P - PWideChar(FLine);
end;
lgString:
begin
F := P;
repeat
P := StrScanW(P, WideChar('"'));
if P <> nil then
begin
if (P = F) or (P[-1] <> '\') then
begin
Result := P - F;
Break;
end
else
begin
// count the backslashes
I := 1;
while (P - 1 - I > F) and (P[-1 - I] = '\') do
Inc(I);
if I and $01 = 0 then {faster than: if I mod 2 = 0 then}
begin
Result := P - F;
Break;
end;
end;
Inc(P);
end;
until P = nil;
end;
end; // case
end;
hlPython, hlPerl:
case FLong of
lgString:
begin
P := StrScanW(P, WideChar('"'));
if P <> nil then
Result := P - PWideChar(FLine);
end;
end;
hlHtml:
case FLong of
lgTag:
begin
P := StrScanW(P, WideChar('>'));
if P <> nil then
Result := P - PWideChar(FLine);
end;
end;
end;
end;
procedure TJvWideHLEditor.TextModified(ACaretX, ACaretY: Integer; Action: TModifiedAction;
const Text: WideString);
var
S: WideString;
L: Integer;
{ LP, I: Integer;
P: PChar;
OldProductionsLine: Integer; }
begin
if not FLongTokens then
Exit;
case FHighlighter of
hlPascal:
S := #13'{}*()/ ';
hlCBuilder, hlJava, hlSql, hlPhp, hlNQC:
S := #13'*/\ ';
hlVB:
S := #13'''';
hlPython, hlPerl:
S := #13'#"';
hlHtml:
S := #13'<>';
hlCocoR:
S := #13'*()/ ';
hlSyntaxHighlighter:
if FSyntaxHighlighter <> nil then
begin
if FSyntaxHighlighter.GetRescanLongKeys(Self, Action, ACaretX, ACaretY, Text) then
begin
if RescanLong(ACaretY) then
Invalidate;
end;
Exit;
end
else
S := #13;
else
S := #13; { unknown Highlighter ? }
end;
if Action = maAll then
ACaretY := -1; // rescan all lines
if (Action in [maAll, maReplace]) or HasAnyChar(S, Text) then
begin
if RescanLong(ACaretY) then
Invalidate;
end
else
begin
if (Highlighter = hlPascal) and (Cardinal(ACaretY) < Cardinal(Length(FLongDesc))) then
begin
// comment <-> preproc
S := Lines[ACaretY];
L := Length(S);
// [Backspace, "insert"]
if ((ACaretX > 1) and (ACaretX <= L + 1) and (S[ACaretX - 1] = '{')) or
((ACaretX > 2) and (ACaretX <= L + 2) and (S[ACaretX - 2] = '(') and (S[ACaretX - 1] = '*')) or
// [Delete]
((ACaretX > 0) and (ACaretX <= L) and (S[ACaretX] = '{')) or
((ACaretX > 1) and (ACaretX <= L + 1) and (S[ACaretX - 1] = '(') and (S[ACaretX] = '*')) then
begin
if RescanLong(ACaretY) then
Invalidate;
end;
end;
end;
{
if (FHighlighter = hlCocoR) and (HasAnyChar('productions'#13, Text)) then
begin
LP := Length('productions');
OldProductionsLine := ProductionsLine;
ProductionsLine := High(Integer);
for I := 0 to Lines.Count - 1 do
begin
P := PWideChar(Lines[I]);
if (StrLICompW2(P, 'productions', LP) = 0) and
((Length(P) = LP) or (P[LP] = ' ')) then
begin
ProductionsLine := I;
Break;
end;
end;
if ProductionsLine <> OldProductionsLine then
Invalidate;
end; }
end;
function TJvWideHLEditor.GetReservedWord(const Token: WideString;
var Reserved: Boolean): Boolean;
begin
Result := Assigned(FOnReservedWord);
if Result then
begin
Reserved := False;
FOnReservedWord(Self, Token, Reserved);
end
end;
function TJvWideHLEditor.UserReservedWords: Boolean;
begin
Result := Assigned(FOnReservedWord);
end;
procedure TJvWideHLEditor.Assign(Source: TPersistent);
begin
inherited Assign(Source);
if Source is TJvWideHLEditor then
begin
FHighlighter := TJvWideHLEditor(Source).Highlighter;
Colors.Assign(TJvWideHLEditor(Source).Colors);
//FSyntaxHighlighting := TJvWideHLEditor(Source).SyntaxHighlighting;
Invalidate;
end
else
if Source is TJvHLEditor then
begin
FHighlighter := TJvHLEditor(Source).Highlighter;
Colors.Assign(TJvHLEditor(Source).Colors);
//FSyntaxHighlighting := TJvHLEditor(Source).SyntaxHighlighting;
Invalidate;
end;
end;
procedure TJvWideHLEditor.AssignTo(Source: TPersistent);
begin
if Source is TJvHLEditor then
begin
TJvHLEditor(Source).BeginUpdate;
try
TJvHLEditor(Source).Assign(TJvCustomEditorBase(Self));
TJvHLEditor(Source).Highlighter := Highlighter;
TJvHLEditor(Source).Colors.Assign(Colors);
TJvHLEditor(Source).SyntaxHighlighting := SyntaxHighlighting;
finally
TJvHLEditor(Source).EndUpdate;
end;
end;
end;
function TJvWideHLEditor.GetDelphiColors: Boolean;
function CompareColor(Symbol: TJvSymbolColor; const DelphiColor: TDelphiColor): Boolean;
begin
Result :=
(Symbol.ForeColor = DelphiColor.ForeColor) and
(Symbol.BackColor = DelphiColor.BackColor) and
(Symbol.Style = DelphiColor.Style);
end;
begin
Result := False;
if not CompareColor(Colors.Comment, DelphiColor_Comment) then
Exit;
if not CompareColor(Colors.Preproc, DelphiColor_Preproc) then
Exit;
if not CompareColor(Colors.Number, DelphiColor_Number) then
Exit;
if not CompareColor(Colors.Strings, DelphiColor_Strings) then
Exit;
if not CompareColor(Colors.Symbol, DelphiColor_Symbol) then
Exit;
if not CompareColor(Colors.Reserved, DelphiColor_Reserved) then
Exit;
if not CompareColor(Colors.Identifier, DelphiColor_Identifier) then
Exit;
if not CompareColor(Colors.PlainText, DelphiColor_PlainText) then
Exit;
Result := True;
end;
procedure TJvWideHLEditor.SetDelphiColors(Value: Boolean);
procedure SetColor(Symbol: TJvSymbolColor; const DelphiColor: TDelphiColor);
begin
with DelphiColor do
Symbol.SetColor(ForeColor, BackColor, Style);
end;
begin
if Value then
begin
SetColor(Colors.Comment, DelphiColor_Comment);
SetColor(Colors.Preproc, DelphiColor_Preproc);
SetColor(Colors.Number, DelphiColor_Number);
SetColor(Colors.Strings, DelphiColor_Strings);
SetColor(Colors.Symbol, DelphiColor_Symbol);
SetColor(Colors.Reserved, DelphiColor_Reserved);
SetColor(Colors.Identifier, DelphiColor_Identifier);
SetColor(Colors.PlainText, DelphiColor_PlainText);
end;
end;
procedure TJvWideHLEditor.SetSyntaxHighlighter(const Value: TJvWideEditorHighlighter);
begin
if Value <> FSyntaxHighlighter then
begin
if Value <> nil then
FHighlighter := hlSyntaxHighlighter
else
if FHighlighter = hlSyntaxHighlighter then
FHighlighter := hlNone;
FSyntaxHighlighter := Value;
RescanLong(0);
Invalidate;
end;
end;
function TJvWideHLEditor.GetColors: TJvColors;
begin
Result := FColors;
end;
procedure TJvWideHLEditor.SetColors(const Value: TJvColors);
begin
FColors.Assign(Value);
end;
function TJvWideHLEditor.GetSyntaxHighlighting: Boolean;
begin
Result := FSyntaxHighlighting;
end;
procedure TJvWideHLEditor.SetSyntaxHighlighting(Value: Boolean);
begin
FSyntaxHighlighting := Value;
Invalidate;
end;
function TJvWideHLEditor.GetHighlighter: TJvHighlighter;
begin
Result := FHighlighter;
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -