cedit: search selected text

FB2 Reader: minor fix

git-svn-id: svn://kolibrios.org@9197 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2021-09-21 18:16:56 +00:00
parent 7763a294f3
commit f3105b9785
5 changed files with 77 additions and 22 deletions

Binary file not shown.

Binary file not shown.

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Icons, Tabs, Timer; RW, Ini, EB := EditBox, Icons, Tabs, Timer;
CONST CONST
header = "CEdit (17-sep-2021)"; header = "CEdit (21-sep-2021)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
@ -1087,13 +1087,39 @@ BEGIN
END Script; END Script;
PROCEDURE ShowSearchPanel; PROCEDURE ShowSearchPanel (goto: BOOLEAN);
VAR
i: INTEGER;
flag: BOOLEAN;
BEGIN BEGIN
flag := FALSE;
IF T.selected(text) & ~goto THEN
T.getSelectedText(text, new_searchText);
IF new_searchText # "" THEN
i := 0;
WHILE (new_searchText[i] # 0X) & (new_searchText[i] # Lines.TAB) DO
INC(i)
END;
IF new_searchText[i] = 0X THEN
searchText := new_searchText;
EB.setValue(FindEdit, searchText);
notFound := ~T.search(text, searchText, cs, whole);
flag := TRUE
END
END
END;
IF ~search THEN IF ~search THEN
Search Search
ELSIF ~searchOpened THEN ELSIF ~searchOpened THEN
search := FALSE; search := FALSE;
Search Search
END;
IF flag THEN
SetFocus(FindEdit, FALSE)
ELSIF goto THEN
SetFocus(GotoEdit, TRUE)
ELSE
SetFocus(FindEdit, TRUE)
END END
END ShowSearchPanel; END ShowSearchPanel;
@ -1305,8 +1331,7 @@ BEGIN
T.redo(text); T.redo(text);
repaint repaint
|menuFind: |menuFind:
ShowSearchPanel; ShowSearchPanel(FALSE)
SetFocus(FindEdit, TRUE)
|menuFindNext: |menuFindNext:
notFound := ~T.findNext(text, BKW.value); notFound := ~T.findNext(text, BKW.value);
menuFindClicked := TRUE menuFindClicked := TRUE
@ -1314,8 +1339,7 @@ BEGIN
notFound := ~T.findNext(text, ~BKW.value); notFound := ~T.findNext(text, ~BKW.value);
menuFindClicked := TRUE menuFindClicked := TRUE
|menuGoto: |menuGoto:
ShowSearchPanel; ShowSearchPanel(TRUE)
SetFocus(GotoEdit, TRUE)
|menuToggleBookmark: |menuToggleBookmark:
T.toggleLabel(text) T.toggleLabel(text)
|menuNextBookmark: |menuNextBookmark:
@ -1762,12 +1786,10 @@ BEGIN
SwitchTab((curText + 1) MOD textsCount) SwitchTab((curText + 1) MOD textsCount)
ELSIF (keyCode = 33) & ctrl THEN ELSIF (keyCode = 33) & ctrl THEN
key := -1; key := -1;
ShowSearchPanel; ShowSearchPanel(FALSE)
SetFocus(FindEdit, TRUE)
ELSIF (keyCode = 34) & ctrl THEN ELSIF (keyCode = 34) & ctrl THEN
key := -1; key := -1;
ShowSearchPanel; ShowSearchPanel(TRUE)
SetFocus(GotoEdit, TRUE)
ELSE ELSE
IF EditBox_Focus(FindEdit) THEN IF EditBox_Focus(FindEdit) THEN
EB.key(FindEdit, key); EB.key(FindEdit, key);
@ -1905,7 +1927,8 @@ BEGIN
save(text); save(text);
repaint repaint
|btnSearch: |btnSearch:
ShowSearchPanel ShowSearchPanel(FALSE);
repaint
|btnCloseSearch: |btnCloseSearch:
Search Search
|btnHideSearch: |btnHideSearch:

View File

@ -19,7 +19,11 @@
MODULE EditBox; MODULE EditBox;
IMPORT sys := SYSTEM, KOSAPI; IMPORT SYSTEM, KOSAPI, Encodings;
CONST
MAX_LENGTH = 1024;
TYPE TYPE
@ -50,14 +54,14 @@ TYPE
VAR VAR
key_proc: EditBoxKey; key_proc: EditBoxKey;
paint *: PROCEDURE (eb: tEditBox); paint *: PROCEDURE (eb: tEditBox);
mouse *: PROCEDURE (eb: tEditBox); mouse *: PROCEDURE (eb: tEditBox);
setValue *: PROCEDURE (eb: tEditBox; text: INTEGER); _setValue : PROCEDURE (eb: tEditBox; text: INTEGER);
PROCEDURE _key (key: INTEGER; key_proc: EditBoxKey; text: tEditBox); PROCEDURE _key (key: INTEGER; key_proc: EditBoxKey; text: tEditBox);
BEGIN BEGIN
sys.CODE( SYSTEM.CODE(
08BH, 045H, 008H, (* mov eax, dword [ebp + 8] *) 08BH, 045H, 008H, (* mov eax, dword [ebp + 8] *)
08BH, 055H, 00CH, (* mov edx, dword [ebp + 12] *) 08BH, 055H, 00CH, (* mov edx, dword [ebp + 12] *)
08BH, 04DH, 010H, (* mov ecx, dword [ebp + 16] *) 08BH, 04DH, 010H, (* mov ecx, dword [ebp + 16] *)
@ -83,7 +87,7 @@ BEGIN
ASSERT(max < LEN(str)); ASSERT(max < LEN(str));
i := 0; i := 0;
REPEAT REPEAT
sys.GET(ptr, str[i]); SYSTEM.GET(ptr, str[i]);
INC(i); INC(i);
INC(ptr) INC(ptr)
UNTIL (str[i - 1] = 0X) OR (i = max); UNTIL (str[i - 1] = 0X) OR (i = max);
@ -91,6 +95,21 @@ BEGIN
END getValue; END getValue;
PROCEDURE setValue* (text: tEditBox; str: ARRAY OF WCHAR);
VAR
i: INTEGER;
temp: ARRAY MAX_LENGTH OF CHAR;
BEGIN
ASSERT(LENGTH(str) < LEN(temp));
i := 0;
REPEAT
temp[i] := CHR(Encodings.UNI[ORD(str[i]), Encodings.CP866] MOD 256);
INC(i)
UNTIL str[i - 1] = 0X;
_setValue(text, SYSTEM.ADR(temp[0]))
END setValue;
PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; editbox_interlock: tEditBox): tEditBox; PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; editbox_interlock: tEditBox): tEditBox;
VAR VAR
new_textbox: tEditBox; new_textbox: tEditBox;
@ -122,7 +141,7 @@ VAR
BEGIN BEGIN
a := KOSAPI.GetProcAdr(name, Lib); a := KOSAPI.GetProcAdr(name, Lib);
ASSERT(a # 0); ASSERT(a # 0);
sys.PUT(v, a) SYSTEM.PUT(v, a)
END GetProc; END GetProc;
@ -132,10 +151,10 @@ VAR
BEGIN BEGIN
Lib := KOSAPI.LoadLib("/rd/1/lib/box_lib.obj"); Lib := KOSAPI.LoadLib("/rd/1/lib/box_lib.obj");
ASSERT(Lib # 0); ASSERT(Lib # 0);
GetProc(Lib, sys.ADR(paint), "edit_box"); GetProc(Lib, SYSTEM.ADR(paint), "edit_box");
GetProc(Lib, sys.ADR(key_proc), "edit_box_key"); GetProc(Lib, SYSTEM.ADR(key_proc), "edit_box_key");
GetProc(Lib, sys.ADR(mouse), "edit_box_mouse"); GetProc(Lib, SYSTEM.ADR(mouse), "edit_box_mouse");
GetProc(Lib, sys.ADR(setValue), "edit_box_set_text"); GetProc(Lib, SYSTEM.ADR(_setValue), "edit_box_set_text");
END main; END main;

View File

@ -1776,6 +1776,19 @@ PROCEDURE isWordChar (c: WCHAR): BOOLEAN;
END isWordChar; END isWordChar;
PROCEDURE getSelectedText* (text: tText; VAR s: ARRAY OF WCHAR);
VAR
n: INTEGER;
selBeg, selEnd: tPoint;
BEGIN
s[0] := 0X;
IF selected(text) & (text.cursor.Y = text.select.Y) THEN
getSelect(text, selBeg, selEnd);
n := getString(text.curLine, selBeg.X, selEnd.X - selBeg.X, s)
END
END getSelectedText;
PROCEDURE wordSel* (text: tText); PROCEDURE wordSel* (text: tText);
VAR VAR
n, i, x1, x2: INTEGER; n, i, x1, x2: INTEGER;