소스 검색

Implement Ctrl + (Home, End, PgUp, PgDown)

Arthur Yefimov 2 년 전
부모
커밋
8c2fd3733c
2개의 변경된 파일56개의 추가작업 그리고 26개의 파일을 삭제
  1. 39 10
      src/Editor.Mod
  2. 17 16
      src/EditorText.Mod

+ 39 - 10
src/Editor.Mod

@@ -816,17 +816,15 @@ END MoveByLine;
 
 (** Moves input cursor up and down by page *)
 PROCEDURE MoveByPage(c: Editor; down, shiftPressed: BOOLEAN);
-VAR i: INTEGER; moved: BOOLEAN;
+VAR i: INTEGER;
 BEGIN c.text.MaybeRemoveIndent; i := c.h - 3;
   IF down THEN
-    moved := c.text.cur.next # NIL;
     WHILE (i > 0) & (c.text.cur.next # NIL) DO
       c.text.scrFirst := c.text.scrFirst.next; INC(c.text.scrY);
       MoveByLine(c, TRUE, FALSE, shiftPressed);
       DEC(i)
     END
   ELSE (* Up *)
-    moved := c.text.cur.prev # NIL;
     WHILE (i > 0) & (c.text.cur.prev # NIL) DO
       IF c.text.scrY > 0 THEN
         c.text.scrFirst := c.text.scrFirst.prev; DEC(c.text.scrY)
@@ -834,10 +832,29 @@ BEGIN c.text.MaybeRemoveIndent; i := c.h - 3;
       MoveByLine(c, FALSE, FALSE, shiftPressed);
       DEC(i)
     END
-  END;
-  IF moved THEN PrintText(c) END
+  END
 END MoveByPage;
 
+(** Moves input cursor up and down to the edge of the whole file *)
+PROCEDURE MoveToFileEdge(c: Editor; down, shiftPressed: BOOLEAN);
+BEGIN c.text.MaybeRemoveIndent;
+  IF down THEN
+    WHILE c.text.cur.next # NIL DO
+      c.text.scrFirst := c.text.scrFirst.next; INC(c.text.scrY);
+      MoveByLine(c, TRUE, FALSE, shiftPressed)
+    END;
+    c.text.x := c.text.cur.len
+  ELSE (* Up *)
+    c.text.x := 0;
+    WHILE c.text.cur.prev # NIL DO
+      IF c.text.scrY > 0 THEN
+        c.text.scrFirst := c.text.scrFirst.prev; DEC(c.text.scrY)
+      END;
+      MoveByLine(c, FALSE, FALSE, shiftPressed)
+    END
+  END
+END MoveToFileEdge;
+
 (** Moves input cursor left and right by one char *)
 PROCEDURE MoveByChar(c: Editor; right, shiftPressed: BOOLEAN);
 BEGIN
@@ -1110,14 +1127,26 @@ BEGIN OV.WindowKeyDown(c, E); HideMsg(c);
     PrintText(c(Editor))
   | T.kUp:        MoveByLine(c(Editor), FALSE, FALSE, shiftPressed)
   | T.kDown:      MoveByLine(c(Editor), TRUE, FALSE, shiftPressed)
-  | T.kHome:      MoveToLineEdge(c(Editor), FALSE, shiftPressed)
-  | T.kEnd:       MoveToLineEdge(c(Editor), TRUE, shiftPressed)
-  | T.kPgUp:      MoveByPage(c(Editor), FALSE, shiftPressed)
-  | T.kPgDn:      MoveByPage(c(Editor), TRUE, shiftPressed)
+  | T.kHome:
+    IF T.mCtrl IN E.mod THEN MoveToFileEdge(c(Editor), FALSE, shiftPressed)
+    ELSE MoveToLineEdge(c(Editor), FALSE, shiftPressed)
+    END
+  | T.kEnd:
+    IF T.mCtrl IN E.mod THEN MoveToFileEdge(c(Editor), TRUE, shiftPressed)
+    ELSE MoveToLineEdge(c(Editor), TRUE, shiftPressed)
+    END
+  | T.kPgUp:
+    IF T.mCtrl IN E.mod THEN MoveToLineEdge(c(Editor), FALSE, shiftPressed)
+    ELSE MoveByPage(c(Editor), FALSE, shiftPressed)
+    END
+  | T.kPgDn:
+    IF T.mCtrl IN E.mod THEN MoveToLineEdge(c(Editor), TRUE, shiftPressed)
+    ELSE MoveByPage(c(Editor), TRUE, shiftPressed)
+    END
   | T.kBackspace: HandleBackspace(c(Editor))
   | T.kDel, T.kDelPad:     HandleDelete(c(Editor))
   | T.kEnter, T.kEnterPad: HandleEnter(c(Editor))
-  | T.kTab:       HandleTab(c(Editor), shiftPressed)
+  | T.kTab:                HandleTab(c(Editor), shiftPressed)
   ELSE END
 END EditorKeyDown;
 

+ 17 - 16
src/EditorText.Mod

@@ -22,7 +22,7 @@ IMPORT Config, Func, Files, Strings, Out, Utf8;
 CONST
   lineLen = 256;
 
-  (* Character kinds, see CurCharKind below *)
+  (** Character kinds, see CurCharKind below **)
   other*       = 0;
   eol*         = 1;
   whitespace*  = 2;
@@ -35,25 +35,25 @@ TYPE
   Line* = POINTER TO LineDesc;
   LineDesc* = RECORD
     s*: String;
-    len*: INTEGER; (* Actual amount characters before 0X *)
-    lineEndLen*: INTEGER; (* Character count of LF or CRLF (1 or 2) *)
-    comLevel*: INTEGER; (* Comment level in start of string *)
+    len*: INTEGER; (** Actual amount characters before 0X *)
+    lineEndLen*: INTEGER; (** Character count of LF or CRLF (1 or 2) *)
+    comLevel*: INTEGER; (** Comment level in start of string *)
     prev*, next*: Line
   END;
 
   Text* = POINTER TO TextDesc;
   TextDesc* = RECORD
-    x*, y*, scrY*: INTEGER; (* Cursor coordinates *)
-    first*, last*, cur*: Line; (* First, last and current lines *)
-    scrFirst*: Line; (* First line seen on screen *)
-    selected*: BOOLEAN; (* Is something selected *)
-    selL*, selR*, selT*, selB*: INTEGER; (* Selection left, right, top, bot. *)
+    x*, y*, scrY*: INTEGER; (** Cursor coordinates *)
+    first*, last*, cur*: Line; (** First, last and current lines *)
+    scrFirst*: Line; (** First line seen on screen *)
+    selected*: BOOLEAN; (** Is something selected *)
+    selL*, selR*, selT*, selB*: INTEGER; (** Selection left,right,top,bottom *)
     changed*: BOOLEAN;
-    newLineCreated*: BOOLEAN; (* TRUE after Enter but before any edits/moves *)
-    winLineEndings*: BOOLEAN (* True if most lines had CRLF line endings *)
+    newLineCreated*: BOOLEAN; (** TRUE after Enter but before edits/moves *)
+    winLineEndings*: BOOLEAN (** True if most lines had CRLF line endings *)
   END;
 
-(* Line *)
+(** Line **)
 
 PROCEDURE InitLine*(L: Line);
 BEGIN L.s[0] := 0X; L.len := 0; L.comLevel := 0; L.prev := NIL; L.next := NIL
@@ -90,7 +90,7 @@ BEGIN
   END
 END Delete;
 
-(* Text *)
+(** Text **)
 
 PROCEDURE InitText*(t: Text);
 BEGIN t.cur := NewLine();
@@ -113,7 +113,8 @@ BEGIN
   t.changed := TRUE
 END RemoveLine;
 
-(* Объединить данную строку со следующей, прицепив её к данной *)
+(** Combine this line with the next one by attaching it to this one
+%RU Объединить данную строку со следующей, прицепив её к данной *)
 PROCEDURE (t: Text) Combine2Lines(L: Line), NEW;
 VAR i: INTEGER;
 BEGIN ASSERT(L.next # NIL, 101); i := 0;
@@ -159,8 +160,8 @@ BEGIN t.selected := TRUE;
   t.MoveToLineCol(t.y + 1, t.x + 1, winH)
 END Select;
 
-(**Returns true if at least one whole line is selected,
-   but leading spaces may still be unselected*)
+(** Returns true if at least one whole line is selected,
+    but leading spaces may still be unselected *)
 PROCEDURE (t: Text) WholeLineSelected*(): BOOLEAN, NEW;
 VAR L: Line;
   i: INTEGER;