📄 jveditor.pas
字号:
if (AMin >= 0) or (AMax >= 0) then
fMask := fMask or SIF_RANGE;
if APosition >= 0 then
fMask := fMask or SIF_POS;
if APage >= 0 then
fMask := fMask or SIF_PAGE;
nPos := APosition;
nMin := AMin;
nMax := AMax;
nPage := APage;
end;
SetScrollInfo(
Handle, // handle of window with scroll bar
SBKIND[Kind], // scroll bar flag
ScrollInfo, // pointer to structure with scroll parameters
True); // redraw flag
end;
end;
procedure TJvControlScrollBar95.SetParam(Index, Value: Integer);
begin
case Index of
0:
FMin := Value;
1:
FMax := Value;
2:
FPosition := Value;
3:
FPage := Value;
end;
if FMax < FMin then
raise EInvalidOperation.Create(SScrollBarRange);
if FPosition < FMin then
FPosition := FMin;
if FPosition > FMax then
FPosition := FMax;
SetParams(FMin, FMax, FPosition, FPage);
end;
{
procedure TJvControlScrollBar95.SetVisible(Value : Boolean);
begin
if FVisible <> Value then
begin
FVisible := Value;
if Handle <> 0 then
end;
end;
}
procedure TJvControlScrollBar95.DoScroll(var Msg: TWMScroll);
var
ScrollPos: Integer;
NewPos: Longint;
ScrollInfo: TScrollInfo;
begin
with Msg do
begin
NewPos := FPosition;
case TScrollCode(ScrollCode) of
scLineUp:
Dec(NewPos, FSmallChange);
scLineDown:
Inc(NewPos, FSmallChange);
scPageUp:
Dec(NewPos, FLargeChange);
scPageDown:
Inc(NewPos, FLargeChange);
scPosition, scTrack:
with ScrollInfo do
begin
cbSize := SizeOf(ScrollInfo);
fMask := SIF_ALL;
GetScrollInfo(Handle, SBKIND[Kind], ScrollInfo);
NewPos := nTrackPos;
end;
scTop:
NewPos := FMin;
scBottom:
NewPos := FMax;
end;
if NewPos < FMin then
NewPos := FMin;
if NewPos > FMax then
NewPos := FMax;
ScrollPos := NewPos;
Scroll(TScrollCode(ScrollCode), ScrollPos);
end;
Position := ScrollPos;
end;
procedure TJvControlScrollBar95.Scroll(ScrollCode: TScrollCode; var ScrollPos: Integer);
begin
if Assigned(FOnScroll) then
FOnScroll(Self, ScrollCode, ScrollPos);
end;
//=== TJvEditorStrings =======================================================
{ TJvEditorStrings }
constructor TJvEditorStrings.Create;
begin
inherited Create;
OnChange := StringsChanged;
end;
procedure TJvEditorStrings.SetTextStr(const Value: string);
begin
inherited SetTextStr(FJvEditor.ExpandTabs(Value));
if FJvEditor.FUpdateLock = 0 then
FJvEditor.NotUndoable;
FJvEditor.TextAllChanged;
end;
procedure TJvEditorStrings.StringsChanged(Sender: TObject);
begin
if FJvEditor.FUpdateLock = 0 then
FJvEditor.TextAllChanged;
end;
procedure TJvEditorStrings.SetLockText(const Text: string);
begin
Inc(FJvEditor.FUpdateLock);
try
inherited SetTextStr(Text)
finally
Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.SetInternal(Index: Integer; Value: string);
begin
Inc(FJvEditor.FUpdateLock);
try
InternalPut(Index, Value);
finally
Dec(FJvEditor.FUpdateLock);
end;
end;
function TJvEditorStrings.Add(const S: string): Integer;
begin
//Inc(FJvEditor.FUpdateLock);
try
Result := inherited Add(FJvEditor.ExpandTabs(S));
finally
//Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.Insert(Index: Integer; const S: string);
begin
//Inc(FJvEditor.FUpdateLock);
try
inherited Insert(Index, FJvEditor.ExpandTabs(S));
finally
//Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.Put(Index: Integer; const S: string);
var
L: Integer;
begin
if FJvEditor.FKeepTrailingBlanks then
inherited Put(Index, S)
else
begin
{--- UNDO ---}
L := Length(S) - Length(TrimRight(S));
if L > 0 then
TJvDeleteTrailUndo.Create(FJvEditor, Length(S), Index, Spaces(L));
{--- /UNDO ---}
inherited Put(Index, TrimRight(S));
end;
end;
procedure TJvEditorStrings.ReLine;
var
L: Integer;
begin
Inc(FJvEditor.FUpdateLock);
try
if Count = 0 then
L := FJvEditor.FCaretX
else
L := Length(Strings[Count - 1]);
while FJvEditor.FCaretY > Count - 1 do
begin
{--- UNDO ---}
TJvReLineUndo.Create(FJvEditor, L, FJvEditor.FCaretY, sLineBreak);
{--- /UNDO ---}
L := 0;
Add('');
end;
if FJvEditor.FCaretX > Length(Strings[FJvEditor.FCaretY]) then
begin
L := FJvEditor.FCaretX - Length(Strings[FJvEditor.FCaretY]);
{--- UNDO ---}
{ TJvReLineUndo.Create(FJvEditor, Length(Strings[FJvEditor.FCaretY]),
FJvEditor.FCaretY, Spaces(L)); }{disabled: will move the caret to wrong undo position }
{--- /UNDO ---}
inherited Put(FJvEditor.FCaretY, Strings[FJvEditor.FCaretY] + Spaces(L));
end;
finally
Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.InternalPut(Index: Integer; const Value: string);
begin
if FJvEditor.FKeepTrailingBlanks then
inherited Put(Index, FJvEditor.ExpandTabs(Value))
else
inherited Put(Index, TrimRight(FJvEditor.ExpandTabs(Value)));
end;
procedure TJvEditorStrings.DeleteText(BegX, BegY, EndX, EndY: Integer);
{ delete text from [BegX..EndY] [BegY..EndY] all inclusive.
BegX,EndX: [0..Max_X] }
var
BegLine, EndLine: string;
i, L: Integer;
begin
if BegY < 0 then
begin
BegY := 0;
BegX := 0;
end;
if BegY >= Count then Exit; // nothing to delete
if EndY >= Count then
begin
EndY := Count - 1;
EndX := MaxInt - 1;
end;
if BegX < 0 then BegX := 0;
Inc(FJvEditor.FUpdateLock);
BeginUpdate;
try
BegLine := Strings[BegY];
// expand BegLine if necessary
L := (BegX + 1) - Length(BegLine) - 1;
if L > 0 then BegLine := BegLine + Spaces(L);
EndLine := Strings[EndY];
// delete lines between and end line
for i := EndY downto BegY + 1 do
Delete(i);
System.Delete(BegLine, BegX + 1, MaxInt);
System.Delete(EndLine, 1, EndX + 1);
Internal[BegY] := BegLine + EndLine;
finally
EndUpdate;
Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.InsertText(X, Y: Integer; const Text: string);
{ insert text on X:[0..Max_X], Y }
var
BegLine, EndLine: string;
YStart: Integer;
F, P: PChar;
S, FirstLine: string;
Len: Integer;
begin
Inc(X); // increment for string functions
if Y < 0 then Y := 0;
while Y > Count do Add('');
BegLine := Strings[Y];
EndLine := System.Copy(BegLine, X, MaxInt);
System.Delete(BegLine, X, MaxInt);
// line is too small -> expand it with spaces
Len := Length(BegLine);
if (Len < X) then
begin
SetLength(BegLine, X - 1);
FillChar(BegLine[Len + 1], X - Len - 1, ' ');
end;
Inc(FJvEditor.FUpdateLock);
BeginUpdate;
try
P := PChar(Text);
F := P;
while not (P[0] in [#0, #10, #13]) do Inc(P);
SetString(s, F, P - F);
YStart := Y;
FirstLine := BegLine + s; // set Internal[YStart] later so we keep the trailing spaces for concat EndLine
while P[0] <> #0 do
begin
if P[0] = #13 then Inc(P);
if P[0] = #10 then Inc(P);
F := P;
while not (P[0] in [#0, #10, #13]) do Inc(P);
SetString(S, F, P - F);
Inc(Y);
Insert(Y, S);
end;
if Y = YStart then
Internal[YStart] := FirstLine + EndLine
else
begin
Internal[YStart] := FirstLine;
Internal[Y] := Strings[Y] + EndLine;
end;
finally
EndUpdate;
Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.DeleteColumnText(BegX, BegY, EndX, EndY: Integer);
{ delete column text from [BegX..EndY] [BegY..EndY] all inclusive.
BegX,EndX: [0..Max_X] }
var
S: string;
i: Integer;
begin
if BegY < 0 then
begin
BegY := 0;
BegX := 0;
end;
if BegY >= Count then Exit; // nothing to delete
if EndY >= Count then
begin
EndY := Count - 1;
EndX := MaxInt - 1;
end;
if BegX < 0 then BegX := 0;
Inc(FJvEditor.FUpdateLock);
BeginUpdate;
try
for i := BegY to EndY do
begin
S := FJvEditor.FLines[i];
System.Delete(S, BegX + 1, EndX - BegX + 1);
FJvEditor.FLines.Internal[i] := S;
end;
finally
EndUpdate;
Dec(FJvEditor.FUpdateLock);
end;
end;
procedure TJvEditorStrings.InsertColumnText(X, Y: Integer; const Text: string);
{ insert column text on X:[0..Max_X], Y }
var
S, Line: string;
P, F: PChar;
L: Integer;
begin
Inc(X); // increment for string functions
if Y < 0 then Y := 0;
Inc(FJvEditor.FUpdateLock);
BeginUpdate;
try
P := PChar(Text);
F := P;
while P[0] <> #0 do
begin
while not (P[0] in [#0, #10, #13]) do Inc(P);
SetString(S, F, P - F);
while Y >= Count do Add('');
Line := Strings[Y];
L := (X - 1) - Length(Line);
if L > 0 then Line := Line + Spaces(L);
System.Insert(S, Line, X);
Internal[Y] := Line;
if P[0] = #13 then Inc(P);
if P[0] = #10 then Inc(P);
F := P;
Inc(Y);
end;
finally
EndUpdate;
Dec(FJvEditor.FUpdateLock);
end;
end;
//=== TJvEditorClient ========================================================
function TJvEditorClient.GetCanvas: TCanvas;
begin
Result := FJvEditor.Canvas;
end;
function TJvEditorClient.Left: Integer;
begin
Result := FJvEditor.GutterWidth + 2;
end;
function TJvEditorClient.Height: Integer;
begin
Result := FJvEditor.ClientHeight;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -