* Fixed some keyboard issues

This commit is contained in:
sg 1999-12-30 21:10:24 +00:00
parent 7878572843
commit d3eee8c9f4

View File

@ -1,22 +1,15 @@
{
$Id$
"shedit" - Text editor with syntax highlighting
Copyright (C) 1999 Sebastian Guenther (sguenther@gmx.de)
"SHEdit" - Text editor with syntax highlighting
Copyright (C) 1999 Sebastian Guenther (sg@freepascal.org)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
@ -55,30 +48,23 @@ end;
procedure TSHTextEdit.AdjustCursorToRange;
begin
if FCursorY<Renderer.VertPos then
begin
if FCursorY < FWidget.VertPos then begin
HideCursor;
FCursorY:=Renderer.VertPos;
FCursorY := FWidget.VertPos;
ShowCursor;
end
else
if FCursorY>Renderer.VertPos+Renderer.PageHeight then
begin
end else if FCursorY > FWidget.VertPos + FWidget.PageHeight then begin
HideCursor;
FCursorY:=Renderer.VertPos+Renderer.PageHeight-1;
FCursorY := FWidget.VertPos + FWidget.PageHeight - 1;
ShowCursor;
end;
if FCursorX<Renderer.HorzPos then
begin
if FCursorX < FWidget.HorzPos then begin
HideCursor;
FCursorX:=Renderer.HorzPos;
FCursorX := FWidget.HorzPos;
ShowCursor;
end
else
if FCursorX>Renderer.HorzPos+Renderer.PageWidth then
begin
end else if FCursorX > FWidget.HorzPos + FWidget.PageWidth then begin
HideCursor;
FCursorX:=Renderer.HorzPos+Renderer.PageWidth-1;
FCursorX := FWidget.HorzPos + FWidget.PageWidth - 1;
ShowCursor;
end;
end;
@ -88,27 +74,23 @@ procedure TSHTextEdit.AdjustRangeToCursor;
var
py : integer;
begin
if FCursorY< Renderer.VertPos then
Renderer.VertPos:=FCursorY
else
if FCursorY>=Renderer.VertPos+Renderer.PageHeight then
begin
py := FCursorY - Renderer.PageHeight + 1;
if FCursorY < FWidget.VertPos then
FWidget.VertPos := FCursorY
else if FCursorY >= FWidget.VertPos + FWidget.PageHeight then begin
py := FCursorY - FWidget.PageHeight + 1;
if py < 0 then
Renderer.VertPos:=0
FWidget.VertPos:=0
else
Renderer.VertPos:=py;
FWidget.VertPos:=py;
end;
if FCursorX<Renderer.HorzPos then
Renderer.HorzPos:=FCursorX
else
if FCursorX>=Renderer.HorzPos+Renderer.PageWidth then
begin
py := FCursorX - Renderer.PageWidth +1;
if FCursorX < FWidget.HorzPos then
FWidget.HorzPos := FCursorX
else if FCursorX >= FWidget.HorzPos + FWidget.PageWidth then begin
py := FCursorX - FWidget.PageWidth + 1;
if py < 0 then
Renderer.HorzPos:=0
FWidget.HorzPos := 0
else
Renderer.HorzPos:=py;
FWidget.HorzPos := py;
end;
end;
@ -185,7 +167,7 @@ end;
procedure TSHTextEdit.CursorPageUp;
begin
dec(FCursorY,Renderer.PageHeight);
Dec(FCursorY, FWidget.PageHeight);
if FCursorY<0 then
FCursorY:=0;
AdjustRangeToCursor;
@ -194,7 +176,7 @@ end;
procedure TSHTextEdit.CursorPageDown;
begin
inc(FCursorY,Renderer.PageHeight);
Inc(FCursorY, FWidget.PageHeight);
if FCursorY > FDoc.LineCount-1 then
FCursorY:=FDoc.LineCount-1;
AdjustRangeToCursor;
@ -317,15 +299,14 @@ begin
cbtext := cbtext + Copy(FDoc.LineText[FSel.OEndY], 1, FSel.OEndX);
end;
Renderer.SetClipboard(cbtext);
FWidget.SetClipboard(cbtext);
end;
procedure TSHTextEdit.ClipboardPaste;
var
cbtext: String;
begin
cbtext := Renderer.GetClipboard;
cbtext := FWidget.GetClipboard;
ExecKeys(cbtext, True);
end;
@ -473,30 +454,28 @@ procedure TSHTextEdit.KeyPressed(KeyCode: LongWord; ShiftState: TShiftState);
begin
// WriteLn('Redraw: ', x1, '/', y1, ' - ', x2, '/', y2);
if y1 = y2 then
Renderer.InvalidateRect(x1,y1,x2,y2)
else
begin
Renderer.InvalidateRect(x1,y1,x1+Renderer.PageWidth,y1);
FWidget.InvalidateRect(x1, y1, x2, y2)
else begin
FWidget.InvalidateRect(x1, y1, x1 + FWidget.PageWidth, y1);
if y1 < y2 - 1 then
Renderer.InvalidateRect(0,y1+1,Renderer.PageWidth,y2 - 1);
Renderer.InvalidateRect(0,y2,x2,y2+1);
FWidget.InvalidateRect(0, y1+1, FWidget.PageWidth, y2 - 1);
FWidget.InvalidateRect(0, y2, x2, y2+1);
end;
end;
var
i: Integer;
shortcut: TShortcut;
AssignmentMatched, OldSelValid: Boolean;
ShortcutFound, OldSelValid: Boolean;
OldSelStartX, OldSelStartY, OldSelEndX, OldSelEndY: Integer;
begin
// WriteLn('Text Widget: Key pressed: "', Key, '" ', KeyCode);
// WriteLn('TSHTextEdit: Key pressed: ', KeyCode);
HideCursor;
LastCursorX := FCursorX;
LastCursorY := FCursorY;
OldSelValid := FSel.IsValid;
if OldSelValid then
begin
if OldSelValid then begin
OldSelStartX := FSel.OStartX;
OldSelStartY := FSel.OStartY;
OldSelEndX := FSel.OEndX;
@ -504,21 +483,24 @@ begin
end;
// Check for keyboard shortcuts
AssignmentMatched := False;
for i := 0 to Shortcuts.Count - 1 do
begin
ShortcutFound := False;
for i := 0 to Shortcuts.Count - 1 do begin
shortcut := TShortcut(Shortcuts.Items[i]);
if (KeyCode = shortcut.KeyCode) and
(ShiftState * [ssShift, ssCtrl, ssAlt] = shortcut.ShiftState) then
begin
shortcut.Action.Method;
(ShiftState * [ssShift, ssCtrl, ssAlt] = shortcut.ShiftState) then begin
ShortcutFound := True;
break;
end;
end;
if ShortcutFound then begin
// WriteLn(shortcut.Action.Descr);
shortcut.Action.Method; // Execute associated action
// Handle the selection extending
case shortcut.Action.SelectionAction of
selNothing: ;
selExtend :
begin
if not FSel.IsValid then
begin
selExtend: begin
if not FSel.IsValid then begin
FSel.StartX:=LastCursorX;
FSel.StartY:=LastCursorY;
end;
@ -526,16 +508,10 @@ begin
FSel.EndY:=FCursorY;
end;
selClear:
begin
FSel.Clear;
end;
end;
AssignmentMatched := True;
break;
end;
end;
if (not AssignmentMatched) and (ShiftState * [ssCtrl, ssAlt] = []) then
end else
if (KeyCode <= 255) and (ShiftState * [ssCtrl, ssAlt] = []) then
ExecKey(Chr(KeyCode), False);
// Check selection
@ -547,17 +523,13 @@ begin
else WriteLn;}
// Handle the rewriting of selections
if not OldSelValid then
begin
if not OldSelValid then begin
if FSel.IsValid then
RedrawArea(FSel.OStartX, FSel.OStartY, FSel.OEndX, FSel.OEndY);
end
else
begin
end else begin
if not FSel.IsValid then
RedrawArea(OldSelStartX, OldSelStartY, OldSelEndX, OldSelEndY)
else
begin
else begin
// Do OldSel and FSel intersect?
if (OldSelEndY < FSel.OStartY) or (OldSelStartY > FSel.OEndY) or
((OldSelEndY = FSel.OStartY) and (OldSelEndX <= FSel.OStartX)) or
@ -565,9 +537,7 @@ begin
begin
RedrawArea(OldSelStartX, OldSelStartY, OldSelEndX, OldSelEndY);
RedrawArea(FSel.OStartX, FSel.OStartY, FSel.OEndX, FSel.OEndY);
end
else
begin
end else begin
// Intersection => determine smallest possible area(s) to redraw
// 1. Check if the start position has changed
if (OldSelStartX <> FSel.OStartX) or (OldSelStartY <> FSel.OStartY) then
@ -592,9 +562,8 @@ end;
{
$Log$
Revision 1.6 1999-12-12 17:50:50 sg
* Fixed drawing of selection
* Several small corrections (removed superfluous local variables etc.)
Revision 1.7 1999-12-30 21:10:24 sg
* Fixed some keyboard issues
Revision 1.5 1999/12/10 15:01:02 peter
* first things for selection