CEdit: added [shift+mouse wheel] for horizontal scrolling;

search improved.


git-svn-id: svn://kolibrios.org@9915 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2023-05-07 17:19:42 +00:00
parent 3dc259f833
commit 653161d498
5 changed files with 353 additions and 304 deletions

Binary file not shown.

View File

@ -42,6 +42,8 @@
F9 выполнить F9 выполнить
ctrl+F8 отладка ctrl+F8 отладка
shift+wheel горизонтальная прокрутка
перемещение по тексту: перемещение по тексту:
(ctrl+)Home, (ctrl+)End, (ctrl+)PageUp, (ctrl+)PageDown (ctrl+)Home, (ctrl+)End, (ctrl+)PageUp, (ctrl+)PageDown
ctrl+Left, ctrl+Right ctrl+Left, ctrl+Right

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar; RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST CONST
HEADER = "CEdit (13-apr-2023)"; HEADER = "CEdit (07-may-2023)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "sh|inc|txt|asm|ob07|c|cpp|h|pas|pp|lua|ini|json"; EditFilter = "sh|inc|txt|asm|ob07|c|cpp|h|pas|pp|lua|ini|json";
@ -169,7 +169,7 @@ CONST
SHIFT = Menu.SHIFT; SHIFT = Menu.SHIFT;
CTRL = Menu.CTRL; CTRL = Menu.CTRL;
ClippingArea = 50; ClippingArea = 32 + T.LineSpacing;
VAR VAR
@ -354,7 +354,11 @@ BEGIN
T.getSelCnt(text, chars, lines); T.getSelCnt(text, chars, lines);
SB.setWidth(canvas.width + scrollWidth); SB.setWidth(canvas.width + scrollWidth);
SB.setPos(line, col); SB.setPos(line, col);
SB.setSel(chars, lines); IF text.foundSel # 0 THEN
SB.setSel("", text.foundCur, text.foundCnt, " / ")
ELSE
SB.setSel("sel: ", chars, lines, " | ")
END;
SB.setEnc(E.eolNames[T.getEol(text)], E.names[T.getEnc(text)]); SB.setEnc(E.eolNames[T.getEol(text)], E.names[T.getEnc(text)]);
SB.draw(LEFT, height - BOTTOM + scrollWidth - 1); SB.draw(LEFT, height - BOTTOM + scrollWidth - 1);
Tabs.modify(tabs, getIdx(text), text.modified) Tabs.modify(tabs, getIdx(text), text.modified)
@ -1591,75 +1595,75 @@ END CreateMenuBookmark;
PROCEDURE Shortcuts; PROCEDURE Shortcuts;
BEGIN BEGIN
Menu.AddShortcut(17 + CTRL, menuClose); Menu.AddShortcut(17 + CTRL, menuClose);
Menu.AddShortcut(21 + CTRL, menuRedo); Menu.AddShortcut(21 + CTRL, menuRedo);
Menu.AddShortcut(30 + CTRL, menuSelectAll); Menu.AddShortcut(30 + CTRL, menuSelectAll);
Menu.AddShortcut(32 + CTRL, menuDuplicate); Menu.AddShortcut(32 + CTRL, menuDuplicate);
Menu.AddShortcut(33 + CTRL, menuFind); Menu.AddShortcut(33 + CTRL, menuFind);
Menu.AddShortcut(35 + CTRL, menuFind); Menu.AddShortcut(35 + CTRL, menuFind);
Menu.AddShortcut(34 + CTRL, menuGoto); Menu.AddShortcut(34 + CTRL, menuGoto);
Menu.AddShortcut(44 + CTRL, menuUndo); Menu.AddShortcut(44 + CTRL, menuUndo);
Menu.AddShortcut(45 + CTRL, menuCut); Menu.AddShortcut(45 + CTRL, menuCut);
Menu.AddShortcut(46 + CTRL, menuCopy); Menu.AddShortcut(46 + CTRL, menuCopy);
Menu.AddShortcut(47 + CTRL, menuPaste); Menu.AddShortcut(47 + CTRL, menuPaste);
Menu.AddShortcut(24 + CTRL, menuOpen); Menu.AddShortcut(24 + CTRL, menuOpen);
Menu.AddShortcut(31 + CTRL, menuSave); Menu.AddShortcut(31 + CTRL, menuSave);
Menu.AddShortcut(49 + CTRL, menuNew); Menu.AddShortcut(49 + CTRL, menuNew);
Menu.AddShortcut(67 + CTRL, menuBuild); Menu.AddShortcut(67 + CTRL, menuBuild);
Menu.AddShortcut(66 + CTRL, menuDebug); Menu.AddShortcut(66 + CTRL, menuDebug);
Menu.AddShortcut(83 + CTRL, menuRemove); Menu.AddShortcut(83 + CTRL, menuRemove);
Menu.AddShortcut(22 + CTRL, menuUpper); Menu.AddShortcut(22 + CTRL, menuUpper);
Menu.AddShortcut(38 + CTRL, menuLower); Menu.AddShortcut(38 + CTRL, menuLower);
Menu.AddShortcut(60 + CTRL, menuToggleBookmark); Menu.AddShortcut(60 + CTRL, menuToggleBookmark);
Menu.AddShortcut(72 + CTRL, menuMoveUp); Menu.AddShortcut(72 + CTRL, menuMoveUp);
Menu.AddShortcut(80 + CTRL, menuMoveDown); Menu.AddShortcut(80 + CTRL, menuMoveDown);
Menu.AddShortcut(83, menuDelete); Menu.AddShortcut(83, menuDelete);
Menu.AddShortcut(67, menuRun); Menu.AddShortcut(67, menuRun);
Menu.AddShortcut(15, menuIncInd); Menu.AddShortcut(15, menuIncInd);
Menu.AddShortcut(14 + SHIFT, menuDecInd); Menu.AddShortcut(14 + SHIFT, menuDecInd);
Menu.AddShortcut(60 + SHIFT, menuPrevBookmark); Menu.AddShortcut(60 + SHIFT, menuPrevBookmark);
Menu.AddShortcut(60, menuNextBookmark); Menu.AddShortcut(60, menuNextBookmark);
Menu.AddShortcut(61 + SHIFT, menuFindPrev); Menu.AddShortcut(61 + SHIFT, menuFindPrev);
Menu.AddShortcut(61, menuFindNext); Menu.AddShortcut(61, menuFindNext);
END Shortcuts; END Shortcuts;
PROCEDURE HideSearch; PROCEDURE HideSearch;
BEGIN BEGIN
SetFocus(FindEdit, FALSE); SetFocus(FindEdit, FALSE);
searchOpened := FALSE; searchOpened := FALSE;
LEFT := LEFT_PADDING; LEFT := LEFT_PADDING;
resize; resize;
draw_window draw_window
END HideSearch; END HideSearch;
PROCEDURE KeyDown (key: INTEGER); PROCEDURE KeyDown (key: INTEGER);
VAR VAR
keyCode, ah: INTEGER; keyCode, ah: INTEGER;
shift, ctrl, rep: BOOLEAN; shift, ctrl, rep: BOOLEAN;
BEGIN BEGIN
K.getKBState(shift, ctrl); K.getKBState(shift, ctrl);
rep := FALSE; rep := FALSE;
keyCode := key DIV 65536; keyCode := key DIV 65536;
(* Numpad *) (* Numpad *)
ah := (key DIV 256) MOD 256; ah := (key DIV 256) MOD 256;
CASE keyCode OF CASE keyCode OF
|83: IF ah = 46 THEN keyCode := 52 END (* . / Del *) |83: IF ah = 46 THEN keyCode := 52 END (* . / Del *)
|82: IF ah = 48 THEN keyCode := 11 END (* 0 / Ins *) |82: IF ah = 48 THEN keyCode := 11 END (* 0 / Ins *)
|79: IF ah = 49 THEN keyCode := 2 END (* 1 / End *) |79: IF ah = 49 THEN keyCode := 2 END (* 1 / End *)
|80: IF ah = 50 THEN keyCode := 3 END (* 2 / Down *) |80: IF ah = 50 THEN keyCode := 3 END (* 2 / Down *)
|81: IF ah = 51 THEN keyCode := 4 END (* 3 / PgDn *) |81: IF ah = 51 THEN keyCode := 4 END (* 3 / PgDn *)
|75: IF ah = 52 THEN keyCode := 5 END (* 4 / <- *) |75: IF ah = 52 THEN keyCode := 5 END (* 4 / <- *)
|76: IF ah = 55 THEN keyCode := -1 END (* 5 / --- *) |76: IF ah = 55 THEN keyCode := -1 END (* 5 / --- *)
|77: IF ah = 54 THEN keyCode := 7 END (* 6 / -> *) |77: IF ah = 54 THEN keyCode := 7 END (* 6 / -> *)
|71: IF ah = 55 THEN keyCode := 8 END (* 7 / Home *) |71: IF ah = 55 THEN keyCode := 8 END (* 7 / Home *)
|72: IF ah = 56 THEN keyCode := 9 END (* 8 / Up *) |72: IF ah = 56 THEN keyCode := 9 END (* 8 / Up *)
|73: IF ah = 57 THEN keyCode := 10 END (* 9 / PgUp *) |73: IF ah = 57 THEN keyCode := 10 END (* 9 / PgUp *)
ELSE ELSE
(* nothing to do *) (* nothing to do *)
END; END;
IF confirm THEN IF confirm THEN
IF keyCode = 28 THEN (* Enter *) IF keyCode = 28 THEN (* Enter *)
@ -1928,7 +1932,7 @@ BEGIN
goto goto
END; END;
IF ~middle THEN IF ~middle THEN
IF exit THEN IF exit THEN
Close Close
ELSE ELSE
@ -1940,24 +1944,25 @@ END BtnClick;
PROCEDURE MouseEvent (VAR resized: BOOLEAN; VAR firstClickX, firstClickY, time: INTEGER); PROCEDURE MouseEvent (VAR resized: BOOLEAN; VAR firstClickX, firstClickY, time: INTEGER);
CONST CONST
DELAY = 10; DELAY = 10;
VAR VAR
msState: SET; msState: SET;
scroll, x, y, scrollX, scrollY: INTEGER; scroll, x, y, scrollX, scrollY: INTEGER;
pos1, pos2: T.tPoint; pos1, pos2: T.tPoint;
shift, ctrl: BOOLEAN;
PROCEDURE EditBox (VAR eb: EB.tEditBox); PROCEDURE EditBox (VAR eb: EB.tEditBox);
VAR VAR
focus: BOOLEAN; focus: BOOLEAN;
BEGIN BEGIN
focus := EditBox_Focus(eb); focus := EditBox_Focus(eb);
EB.mouse(eb); EB.mouse(eb);
IF focus # EditBox_Focus(eb) THEN IF focus # EditBox_Focus(eb) THEN
SetFocus(eb, TRUE); SetFocus(eb, TRUE);
repaint repaint
END END
END EditBox; END EditBox;
BEGIN BEGIN
@ -1969,7 +1974,12 @@ BEGIN
END; END;
scroll := K.Scroll(); scroll := K.Scroll();
IF scroll # 0 THEN IF scroll # 0 THEN
T.scroll(text, 0, scroll*3); K.getKBState(shift, ctrl);
IF shift THEN
T.scroll(text, scroll*3, 0)
ELSE
T.scroll(text, 0, scroll*3)
END;
repaint repaint
END; END;
IF leftButton THEN IF leftButton THEN
@ -1987,11 +1997,11 @@ BEGIN
Scroll.mouse(hScroll); Scroll.mouse(hScroll);
Scroll.mouse(vScroll); Scroll.mouse(vScroll);
msState := K.MouseState(); msState := K.MouseState();
T.getScroll(text, scrollX, scrollY); T.getScroll(text, scrollX, scrollY);
IF (hScroll.value # scrollX) OR (vScroll.value # scrollY) THEN IF (hScroll.value # scrollX) OR (vScroll.value # scrollY) THEN
T.scroll(text, hScroll.value - scrollX, vScroll.value - scrollY); T.scroll(text, hScroll.value - scrollX, vScroll.value - scrollY);
repaint repaint
END; END;
IF (8 IN msState) & ~(24 IN msState) THEN IF (8 IN msState) & ~(24 IN msState) THEN
mouse(firstClickX, firstClickY); mouse(firstClickX, firstClickY);
@ -2100,110 +2110,110 @@ END receiveIPC;
PROCEDURE main; PROCEDURE main;
VAR VAR
fileName, filePath: RW.tFileName; fileName, filePath: RW.tFileName;
width, height, cliWidth, cliHeight: INTEGER; width, height, cliWidth, cliHeight: INTEGER;
resized: BOOLEAN; resized: BOOLEAN;
firstClickX, firstClickY, time, blink, i: INTEGER; firstClickX, firstClickY, time, blink, i: INTEGER;
key, scr: INTEGER; key, scr: INTEGER;
text_ptr, text_size, errno: INTEGER; text_ptr, text_size, errno: INTEGER;
BEGIN BEGIN
mainTID := K.ThreadID(); mainTID := K.ThreadID();
header := ""; header := "";
K.GetSystemColors; K.GetSystemColors;
switch := FALSE; switch := FALSE;
closing := FALSE; closing := FALSE;
textsCount := 0; textsCount := 0;
curText := 0; curText := 0;
Args.GetArg(0, AppPath); Args.GetArg(0, AppPath);
Ini.load(AppPath); Ini.load(AppPath);
Ini.getSettings; Ini.getSettings;
runScript := Ini.runScript; runScript := Ini.runScript;
buildScript := Ini.buildScript; buildScript := Ini.buildScript;
debugScript := Ini.debugScript; debugScript := Ini.debugScript;
leftButton := FALSE; leftButton := FALSE;
resized := FALSE; resized := FALSE;
newtab := FALSE; newtab := FALSE;
K.ScreenSize(winWidth, winHeight); K.ScreenSize(winWidth, winHeight);
scrollWidth := winHeight DIV 35; scrollWidth := winHeight DIV 35;
winWidth := (winWidth*80) DIV 100 - (128 + 30); winWidth := (winWidth*80) DIV 100 - (128 + 30);
winHeight := winHeight - (128 + 30); winHeight := winHeight - (128 + 30);
winWidth := MAX(winWidth, minWinWidth); winWidth := MAX(winWidth, minWinWidth);
winHeight := MAX(winHeight, minWinHeight); winHeight := MAX(winHeight, minWinHeight);
cliWidth := winWidth; cliWidth := winWidth;
cliHeight := winHeight; cliHeight := winHeight;
LEFT := LEFT_PADDING; LEFT := LEFT_PADDING;
RIGHT := scrollWidth - 2; RIGHT := scrollWidth - 2;
BOTTOM := SB.height() + scrollWidth - 1; BOTTOM := SB.height() + scrollWidth - 1;
SkinHeight := K.SkinHeight(); SkinHeight := K.SkinHeight();
canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 11 + RIGHT_PADDING), winHeight - (TOP + BOTTOM + 5 - ClippingArea) - SkinHeight); canvas := G.CreateCanvas(winWidth - (LEFT + RIGHT + 11 + RIGHT_PADDING), winHeight - (TOP + BOTTOM + 5 - ClippingArea) - SkinHeight);
DEC(canvas.height, ClippingArea); DEC(canvas.height, ClippingArea);
tabs := Tabs.create(); tabs := Tabs.create();
Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight); Tabs.setArea(tabs, LEFT, TOP - Tabs.tabHeight, canvas.width, Tabs.tabHeight);
font := G.fonts[Ini.font]; font := G.fonts[Ini.font];
G.SetFont(canvas, font); G.SetFont(canvas, font);
T.init(resetTimer, Ini.lineNumbers, Ini.autoIndents, Ini.autoBrackets, Ini.trimSpace); T.init(resetTimer, Ini.lineNumbers, Ini.autoIndents, Ini.autoBrackets, Ini.trimSpace);
Ini.selectSection(Ini.theme); Ini.selectSection(Ini.theme);
T.setCanvas(canvas); T.setCanvas(canvas);
mainMenu := Menu.CreateMain(mainMenuBtn); mainMenu := Menu.CreateMain(mainMenuBtn);
Menu.init(resetTimer); Menu.init(resetTimer);
context := CreateContextMenu(); context := CreateContextMenu();
menuFile := CreateMenuFile(); menuFile := CreateMenuFile();
subCurLine := CreateMenuCurLine(); subCurLine := CreateMenuCurLine();
subIndent := CreateMenuIndent(); subIndent := CreateMenuIndent();
subCase := CreateMenuCase(); subCase := CreateMenuCase();
menuEdit := CreateMenuEdit(); menuEdit := CreateMenuEdit();
subCurLine.parent := menuEdit; subCurLine.parent := menuEdit;
subIndent.parent := menuEdit; subIndent.parent := menuEdit;
subCase.parent := menuEdit; subCase.parent := menuEdit;
subBookmark := CreateMenuBookmark(); subBookmark := CreateMenuBookmark();
menuSearch := CreateMenuSearch(); menuSearch := CreateMenuSearch();
subBookmark.parent := menuSearch; subBookmark.parent := menuSearch;
subEOL := CreateMenuEOL(); subEOL := CreateMenuEOL();
menuEncoding := CreateMenuEncoding(); menuEncoding := CreateMenuEncoding();
subEOL.parent := menuEncoding; subEOL.parent := menuEncoding;
menuView := CreateMenuView(); menuView := CreateMenuView();
menuLanguage := CreateMenuLanguage(); menuLanguage := CreateMenuLanguage();
menuProgram := CreateMenuProgram(); menuProgram := CreateMenuProgram();
menuTools := CreateMenuTools(); menuTools := CreateMenuTools();
menuOptions := CreateMenuOptions(); menuOptions := CreateMenuOptions();
Menu.AddMainItem(mainMenu, "file", menuFile); Menu.AddMainItem(mainMenu, "file", menuFile);
Menu.AddMainItem(mainMenu, "edit", menuEdit); Menu.AddMainItem(mainMenu, "edit", menuEdit);
Menu.AddMainItem(mainMenu, "search", menuSearch); Menu.AddMainItem(mainMenu, "search", menuSearch);
Menu.AddMainItem(mainMenu, "encoding", menuEncoding); Menu.AddMainItem(mainMenu, "encoding", menuEncoding);
Menu.AddMainItem(mainMenu, "view", menuView); Menu.AddMainItem(mainMenu, "view", menuView);
Menu.AddMainItem(mainMenu, "language", menuLanguage); Menu.AddMainItem(mainMenu, "language", menuLanguage);
Menu.AddMainItem(mainMenu, "program", menuProgram); Menu.AddMainItem(mainMenu, "program", menuProgram);
Menu.AddMainItem(mainMenu, "tools", menuTools); Menu.AddMainItem(mainMenu, "tools", menuTools);
Menu.AddMainItem(mainMenu, "options", menuOptions); Menu.AddMainItem(mainMenu, "options", menuOptions);
Shortcuts; Shortcuts;
Toolbar.create(toolbar, LEFT_PADDING + 5, toolbarTop); Toolbar.create(toolbar, LEFT_PADDING + 5, toolbarTop);
Toolbar.add(toolbar, btnNew, Icons.icoNew, ""); Toolbar.add(toolbar, btnNew, Icons.icoNew, "");
Toolbar.add(toolbar, btnOpen, Icons.icoOpen, ""); Toolbar.add(toolbar, btnOpen, Icons.icoOpen, "");
Toolbar.add(toolbar, btnSave, Icons.icoSave, ""); Toolbar.add(toolbar, btnSave, Icons.icoSave, "");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnSearch, Icons.icoSearch, ""); Toolbar.add(toolbar, btnSearch, Icons.icoSearch, "");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnUndo, Icons.icoUndo, ""); Toolbar.add(toolbar, btnUndo, Icons.icoUndo, "");
Toolbar.add(toolbar, btnRedo, Icons.icoRedo, ""); Toolbar.add(toolbar, btnRedo, Icons.icoRedo, "");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnUpper, -1, "AB"); Toolbar.add(toolbar, btnUpper, -1, "AB");
Toolbar.add(toolbar, btnLower, -1, "ab"); Toolbar.add(toolbar, btnLower, -1, "ab");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnBuild, Icons.icoBuild, ""); Toolbar.add(toolbar, btnBuild, Icons.icoBuild, "");
Toolbar.add(toolbar, btnRun, Icons.icoRun, ""); Toolbar.add(toolbar, btnRun, Icons.icoRun, "");
filePath := "/sys"; filePath := "/sys";
IF Args.argc = 1 THEN IF Args.argc = 1 THEN
text := T.New(); text := T.New();
insert(0, text); insert(0, text);
T.SetPos(text, 0, 0) T.SetPos(text, 0, 0)
END; END;
FOR i := 1 TO Args.argc - 1 DO FOR i := 1 TO Args.argc - 1 DO
Args.GetArg(i, fileName); Args.GetArg(i, fileName);
IF fileName[0] # "*" THEN IF fileName[0] # "*" THEN
@ -2226,71 +2236,71 @@ BEGIN
END; END;
SwitchTab(textsCount - 1); SwitchTab(textsCount - 1);
Scroll.create(FALSE, canvas.width + 1, scrollWidth, scrollWidth, scrollWidth*3 DIV 2, ScrollChange, hScroll); Scroll.create(FALSE, canvas.width + 1, scrollWidth, scrollWidth, scrollWidth*3 DIV 2, ScrollChange, hScroll);
Scroll.create(TRUE, scrollWidth, canvas.height + 2, scrollWidth, scrollWidth*3 DIV 2, ScrollChange, vScroll); Scroll.create(TRUE, scrollWidth, canvas.height + 2, scrollWidth, scrollWidth*3 DIV 2, ScrollChange, vScroll);
T.resize(canvas.width, canvas.height); T.resize(canvas.width, canvas.height);
confirm := FALSE; confirm := FALSE;
notFound := FALSE; notFound := FALSE;
menuFindClicked := FALSE; menuFindClicked := FALSE;
menuActive := FALSE; menuActive := FALSE;
search := FALSE; search := FALSE;
searchOpened := FALSE; searchOpened := FALSE;
createSearchForm; createSearchForm;
new_searchText := ""; new_searchText := "";
searchText := ""; searchText := "";
cs := FALSE; cs := FALSE;
whole := FALSE; whole := FALSE;
replaced := 0; replaced := 0;
OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, ""); OD := OpenDlg.Create(draw_window, OpenDlg.topen, filePath, "");
IPC[1] := 0; IPC[1] := 0;
IPC[0] := 0; IPC[0] := 0;
K.SetIPC(IPC); K.SetIPC(IPC);
K.SetEventsMask({0, 1, 2, 5, 6, 31}); K.SetEventsMask({0, 1, 2, 5, 6, 31});
draw_window; draw_window;
blink := Ini.blink; blink := Ini.blink;
IF blink <= 0 THEN IF blink <= 0 THEN
blink := 0 blink := 0
ELSIF blink < 30 THEN ELSIF blink < 30 THEN
blink := 30 blink := 30
END; END;
timerEnabled := TRUE; timerEnabled := TRUE;
CursorTime := K.GetTickCount(); CursorTime := K.GetTickCount();
WHILE TRUE DO WHILE TRUE DO
CurrentTime := K.GetTickCount(); CurrentTime := K.GetTickCount();
IF (CurrentTime - CursorTime > blink) & (blink > 0) & timerEnabled & ~K.RolledUp() THEN IF (CurrentTime - CursorTime > blink) & (blink > 0) & timerEnabled & ~K.RolledUp() THEN
CursorTime := CurrentTime; CursorTime := CurrentTime;
T.cursor(text); T.cursor(text);
drawText drawText
END; END;
CASE K.EventTimeout(10) OF CASE K.EventTimeout(10) OF
|0: |0:
|1: Redraw(resized, width, height, cliWidth, cliHeight) |1: Redraw(resized, width, height, cliWidth, cliHeight)
|2: |2:
key := K.GetKey(); key := K.GetKey();
IF ~K.RolledUp() THEN IF ~K.RolledUp() THEN
KeyDown(key) KeyDown(key)
END END
|3: BtnClick |3: BtnClick
|6: |6:
IF ~K.RolledUp() THEN IF ~K.RolledUp() THEN
MouseEvent(resized, firstClickX, firstClickY, time) MouseEvent(resized, firstClickX, firstClickY, time)
ELSE ELSE
scr := K.Scroll() scr := K.Scroll()
END END
|7: receiveIPC |7: receiveIPC
END; END;
IF newtab THEN IF newtab THEN
Redraw(resized, width, height, cliWidth, cliHeight); Redraw(resized, width, height, cliWidth, cliHeight);
newtab := FALSE newtab := FALSE
END END
END END
END main; END main;
BEGIN BEGIN
main main
END CEdit. END CEdit.

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -50,16 +50,16 @@ BEGIN
END setPos; END setPos;
PROCEDURE setSel* (chars, lines: INTEGER); PROCEDURE setSel* (text: ARRAY OF WCHAR; first, second: INTEGER; delimiter: ARRAY OF WCHAR);
VAR VAR
s1, s2: tString; s1, s2: tString;
BEGIN BEGIN
IF chars # 0 THEN IF first # 0 THEN
s1 := "sel: "; s1 := text;
U.int2str(chars, s2); U.int2str(first, s2);
U.append(s1, s2); U.append(s1, s2);
U.append(s1, " | "); U.append(s1, delimiter);
U.int2str(lines, s2); U.int2str(second, s2);
U.append(s1, s2); U.append(s1, s2);
SB.sel := s1 SB.sel := s1
ELSE ELSE

View File

@ -40,7 +40,7 @@ CONST
mark_width = 2; mark_width = 2;
pad_left = mark_width + 3; pad_left = mark_width + 3;
pad_top = 1; pad_top = 1;
inter = 2; LineSpacing* = 2;
TYPE TYPE
@ -74,7 +74,7 @@ TYPE
lang*: INTEGER; lang*: INTEGER;
enc, eol: INTEGER; enc, eol: INTEGER;
foundList: List.tList; foundList: List.tList;
foundSel: INTEGER; foundSel*, foundCur*, foundCnt*: INTEGER;
searchText: tString; searchText: tString;
LinesVector: Lines.tVector; LinesVector: Lines.tVector;
chLog*: ChangeLog.tLog; chLog*: ChangeLog.tLog;
@ -2389,8 +2389,8 @@ BEGIN
IF ~((scrollY > cursor.Y) OR (scrollY + textsize.Y + 1 <= cursor.Y) OR IF ~((scrollY > cursor.Y) OR (scrollY + textsize.Y + 1 <= cursor.Y) OR
(scrollX > cursor.X) OR (scrollX + textsize.X <= cursor.X)) THEN (scrollX > cursor.X) OR (scrollX + textsize.X <= cursor.X)) THEN
x := (cursor.X - scrollX)*charWidth + padding.left; x := (cursor.X - scrollX)*charWidth + padding.left;
y1 := (cursor.Y - scrollY)*charHeight + padding.top + (inter DIV 2 + 1); y1 := (cursor.Y - scrollY)*charHeight + padding.top + (LineSpacing DIV 2 + 1);
y2 := y1 + charHeight - (inter + 2); y2 := y1 + charHeight - (LineSpacing + 2);
G.notVLine(canvas, x, y1, y2); G.notVLine(canvas, x, y1, y2);
G.notVLine(canvas, x - 1, y1, y2) G.notVLine(canvas, x - 1, y1, y2)
END END
@ -2400,17 +2400,18 @@ END cursor;
PROCEDURE drawSelect (text: tText; line: tLine; selBeg, selEnd, y: INTEGER); PROCEDURE drawSelect (text: tText; line: tLine; selBeg, selEnd, y: INTEGER);
VAR VAR
Len, pos, x, firstCharIdx: INTEGER; Len, pos, x, firstCharIdx: INTEGER;
BEGIN BEGIN
firstCharIdx := MAX(text.scroll.X, selBeg); firstCharIdx := MAX(text.scroll.X, selBeg);
Len := MAX(MIN(line.length - firstCharIdx, selEnd - firstCharIdx), 0); Len := MAX(MIN(line.length - firstCharIdx, selEnd - firstCharIdx), 0);
Len := MIN(Len, textsize.X - pos + 1); Len := MIN(Len, textsize.X - pos + 1);
SetColor(colors.seltext, colors.selback); SetColor(colors.seltext, colors.selback);
pos := MAX((selBeg - text.scroll.X), 0); pos := MAX((selBeg - text.scroll.X), 0);
x := pos*charWidth + padding.left; x := pos*charWidth + padding.left;
G.SetColor(canvas, colors.selback); G.SetColor(canvas, colors.selback);
G.FillRect(canvas, x - 1, y - inter DIV 2, x + Len*charWidth, y - inter DIV 2 + charHeight); G.FillRect(canvas, x - 1, y - LineSpacing DIV 2,
G.TextOut(canvas, pos*charWidth + padding.left, y, Lines.getPChar(line, firstCharIdx), Len, colors.seltext) x + Len*charWidth, y - LineSpacing DIV 2 + charHeight);
G.TextOut(canvas, pos*charWidth + padding.left, y, Lines.getPChar(line, firstCharIdx), Len, colors.seltext)
END drawSelect; END drawSelect;
@ -2485,7 +2486,7 @@ BEGIN
setPadding(pad_left + wNum*2, padding.top) setPadding(pad_left + wNum*2, padding.top)
END; END;
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
y := padding.top + inter DIV 2; y := padding.top + LineSpacing DIV 2;
n := text.scroll.Y; n := text.scroll.Y;
firstLine := getLine2(text, n); firstLine := getLine2(text, n);
@ -2494,7 +2495,8 @@ BEGIN
cnt := textsize.Y; cnt := textsize.Y;
y := y + charHeight*(text.cursor.Y - text.scroll.Y); y := y + charHeight*(text.cursor.Y - text.scroll.Y);
G.SetColor(canvas, colors.back); G.SetColor(canvas, colors.back);
G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight); G.FillRect(canvas, padding.left - 2, y - LineSpacing DIV 2,
size.X - 1, y - LineSpacing DIV 2 + charHeight);
n := text.cursor.Y n := text.cursor.Y
ELSE ELSE
line := firstLine; line := firstLine;
@ -2505,7 +2507,8 @@ BEGIN
backColor := colors.back; backColor := colors.back;
IF (line = text.curLine) & ~selected(text) THEN IF (line = text.curLine) & ~selected(text) THEN
G.SetColor(canvas, colors.curline); G.SetColor(canvas, colors.curline);
G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight); G.FillRect(canvas, padding.left - 2, y - LineSpacing DIV 2,
size.X - 1, y - LineSpacing DIV 2 + charHeight);
backColor := colors.curline backColor := colors.curline
END; END;
SetColor(colors.text, backColor); SetColor(colors.text, backColor);
@ -2524,7 +2527,7 @@ BEGIN
ELSIF (selBeg.Y # n) & (selEnd.Y = n) THEN ELSIF (selBeg.Y # n) & (selEnd.Y = n) THEN
drawSelect(text, line, 0, selEnd.X, y) drawSelect(text, line, 0, selEnd.X, y)
END; END;
mark(line, y - inter DIV 2); mark(line, y - LineSpacing DIV 2);
NextLine(line); NextLine(line);
INC(y, charHeight); INC(y, charHeight);
INC(n); INC(n);
@ -2535,7 +2538,7 @@ BEGIN
G.FillRect(canvas, 0, 0, padding.left - pad_left (*+ 1*), size.Y - 1); G.FillRect(canvas, 0, 0, padding.left - pad_left (*+ 1*), size.Y - 1);
line := firstLine; line := firstLine;
SetColor(colors.numtext, colors.numback); SetColor(colors.numtext, colors.numback);
y := padding.top + inter DIV 2; y := padding.top + LineSpacing DIV 2;
n := MIN(text.scroll.Y + textsize.Y + 1, text.count); n := MIN(text.scroll.Y + textsize.Y + 1, text.count);
FOR i := text.scroll.Y + 1 TO n DO FOR i := text.scroll.Y + 1 TO n DO
IF lineNumbers THEN IF lineNumbers THEN
@ -2544,13 +2547,14 @@ BEGIN
G.TextOut2(canvas, (numWidth - U.lg10(i) - 1)*wNum - wNum DIV 2, y, s, LENGTH(s)) G.TextOut2(canvas, (numWidth - U.lg10(i) - 1)*wNum - wNum DIV 2, y, s, LENGTH(s))
ELSE ELSE
G.SetColor(canvas, colors.numtext); G.SetColor(canvas, colors.numtext);
G.HLine(canvas, y - inter DIV 2 + charHeight DIV 2, xNum - wNum DIV (1 + ORD(i MOD 5 # 0)), xNum) G.HLine(canvas, y - LineSpacing DIV 2 + charHeight DIV 2,
xNum - wNum DIV (1 + ORD(i MOD 5 # 0)), xNum)
END END
END; END;
IF line.label THEN IF line.label THEN
FOR x := wNum DIV 2 TO (padding.left - pad_left) - wNum DIV 2 DO FOR x := wNum DIV 2 TO (padding.left - pad_left) - wNum DIV 2 DO
G.notVLine(canvas, x, y, y + charHeight - (inter + 1)); G.notVLine(canvas, x, y, y + charHeight - (LineSpacing + 1));
G.xorVLine(canvas, x, y, y + charHeight - (inter + 1)) G.xorVLine(canvas, x, y, y + charHeight - (LineSpacing + 1))
END END
END; END;
NextLine(line); NextLine(line);
@ -2569,7 +2573,7 @@ BEGIN
p := text.foundList.first(Search.tPos); p := text.foundList.first(Search.tPos);
pos := Search.next(p, i); pos := Search.next(p, i);
WHILE pos # -1 DO WHILE pos # -1 DO
y := padding.top + inter DIV 2; y := padding.top + LineSpacing DIV 2;
IF text.smallMove THEN IF text.smallMove THEN
y := y + charHeight*(text.cursor.Y - text.scroll.Y) y := y + charHeight*(text.cursor.Y - text.scroll.Y)
END; END;
@ -2587,7 +2591,7 @@ BEGIN
n := LENGTH(text.searchText)*charWidth; n := LENGTH(text.searchText)*charWidth;
WHILE n > 0 DO WHILE n > 0 DO
IF x >= padding.left THEN IF x >= padding.left THEN
G.notVLine(canvas, x, y, y + charHeight - inter) G.notVLine(canvas, x, y, y + charHeight - LineSpacing)
END; END;
INC(x); INC(x);
DEC(n) DEC(n)
@ -2601,11 +2605,11 @@ BEGIN
IF text.foundSel > 0 THEN IF text.foundSel > 0 THEN
x := (text.cursor.X - text.scroll.X)*charWidth + padding.left; x := (text.cursor.X - text.scroll.X)*charWidth + padding.left;
y := (text.cursor.Y - text.scroll.Y)*charHeight + padding.top + inter DIV 2; y := (text.cursor.Y - text.scroll.Y)*charHeight + padding.top + LineSpacing DIV 2;
n := text.foundSel*charWidth; n := text.foundSel*charWidth;
WHILE n > 0 DO WHILE n > 0 DO
IF x >= padding.left THEN IF x >= padding.left THEN
G.xorVLine(canvas, x, y, y + charHeight - inter) G.xorVLine(canvas, x, y, y + charHeight - LineSpacing)
END; END;
INC(x); INC(x);
DEC(n) DEC(n)
@ -2689,7 +2693,7 @@ PROCEDURE setCanvas* (_canvas: G.tCanvas);
BEGIN BEGIN
canvas := _canvas; canvas := _canvas;
charWidth := _canvas.font.width; charWidth := _canvas.font.width;
charHeight := _canvas.font.height + inter charHeight := _canvas.font.height + LineSpacing
END setCanvas; END setCanvas;
@ -2763,54 +2767,87 @@ END open;
PROCEDURE findNext* (text: tText; prev: BOOLEAN): BOOLEAN; PROCEDURE findNext* (text: tText; prev: BOOLEAN): BOOLEAN;
VAR VAR
cursorPos, x, y, X, Y, Len: INTEGER; cursorPos, x, y, X, Y, Len: INTEGER;
line: tLine; line: tLine;
res: BOOLEAN; res: BOOLEAN;
pos, i, pos0: INTEGER; pos, i, pos0, first, last, num, cnt: INTEGER;
p: Search.tPos; p: Search.tPos;
BEGIN BEGIN
X := text.cursor.X; X := text.cursor.X;
Y := text.cursor.Y; Y := text.cursor.Y;
text.cursor.X := MIN(text.cursor.X, text.curLine.length); text.cursor.X := MIN(text.cursor.X, text.curLine.length);
cursorPos := text.curLine.pos + text.cursor.X - ORD(prev) - ORD(~prev & (text.foundSel = 0)); cursorPos := text.curLine.pos + text.cursor.X - ORD(prev) - ORD(~prev & (text.foundSel = 0));
pos0 := -1; pos0 := -1;
i := 0;
p := text.foundList.first(Search.tPos); cnt := 0;
pos := Search.next(p, i); IF text.foundList.count # 0 THEN
WHILE (pos # -1) & (pos <= cursorPos) DO p := text.foundList.first(Search.tPos);
pos0 := pos; first := p.pos[0];
pos := Search.next(p, i) WHILE p # NIL DO
END; INC(cnt, p.cnt);
IF prev THEN p := p.next(Search.tPos)
pos := pos0 END;
END; p := text.foundList.last(Search.tPos);
res := pos # -1; last := p.pos[p.cnt - 1]
IF res THEN ELSE
y := 0; first := -1;
line := text.first(tLine); last := -1
WHILE (line.pos <= pos) & (line.next # NIL) DO END;
NextLine(line); text.foundCnt := cnt;
INC(y)
END; num := 1;
IF (line.next # NIL) OR (line.pos > pos) THEN i := 0;
PrevLine(line); p := text.foundList.first(Search.tPos);
DEC(y) pos := Search.next(p, i);
END; WHILE (pos # -1) & (pos <= cursorPos) DO
resetSelect(text); pos0 := pos;
searchScroll(text, y); pos := Search.next(p, i);
x := pos - line.pos; INC(num)
Len := LENGTH(text.searchText); END;
IF x + Len > text.scroll.X + textsize.X THEN IF prev THEN
text.scroll.X := MAX(x + Len - textsize.X + 3, 0) pos := pos0;
ELSIF x < text.scroll.X THEN DEC(num)
text.scroll.X := MAX(x - 3, 0) END;
END;
SetPos(text, x, y); IF pos = -1 THEN
text.foundSel := Len IF prev THEN
ELSE pos := last;
SetPos(text, X, Y) num := cnt
END ELSE
RETURN res pos := first;
num := 1
END
END;
res := pos # -1;
IF res THEN
y := 0;
line := text.first(tLine);
WHILE (line.pos <= pos) & (line.next # NIL) DO
NextLine(line);
INC(y)
END;
IF (line.next # NIL) OR (line.pos > pos) THEN
PrevLine(line);
DEC(y)
END;
resetSelect(text);
searchScroll(text, y);
x := pos - line.pos;
Len := LENGTH(text.searchText);
IF x + Len > text.scroll.X + textsize.X THEN
text.scroll.X := MAX(x + Len - textsize.X + 3, 0)
ELSIF x < text.scroll.X THEN
text.scroll.X := MAX(x - 3, 0)
END;
SetPos(text, x, y);
text.foundSel := Len;
text.foundCur := num
ELSE
SetPos(text, X, Y);
text.foundCur := 0
END
RETURN res
END findNext; END findNext;