CEdit: fixed whole word search

git-svn-id: svn://kolibrios.org@9907 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2023-03-18 12:35:25 +00:00
parent f8df2f2297
commit 3ade12b666
6 changed files with 141 additions and 118 deletions

Binary file not shown.

View File

@ -99,7 +99,7 @@ delim = =
[lang_Fasm] [lang_Fasm]
KW1 = KW1 =
KW2 = KW2 = byte,word,dword,db,dw,dd
KW3 = KW3 =
delim = {}[]<>=:,()&*/|+-\# delim = {}[]<>=:,()&*/|+-\#

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 (06-mar-2023)"; HEADER = "CEdit (18-mar-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";

View File

@ -26,7 +26,7 @@ CONST
itemSize = 64; itemSize = 64;
TYPE TYPE
tBuffer* = CB.tBuffer; tBuffer = CB.tBuffer;
tIdxTable = ARRAY 65536, 2 OF INTEGER; tIdxTable = ARRAY 65536, 2 OF INTEGER;
@ -115,15 +115,20 @@ BEGIN
END next; END next;
PROCEDURE find* (text: tBuffer; s: ARRAY OF WCHAR; whole: BOOLEAN; list: List.tList); PROCEDURE find* (text: tBuffer; s: ARRAY OF WCHAR; whole: BOOLEAN; list: List.tList; offset: INTEGER);
VAR VAR
k, pos, n, x, prev_item_pos: INTEGER; k, pos, n, i, x, prev_item_pos: INTEGER;
item: tPos; item: tPos;
c1, c2: WCHAR; c1, c2: WCHAR;
flag: BOOLEAN; flag: BOOLEAN;
BEGIN BEGIN
ASSERT(table # NIL); ASSERT(table # NIL);
n := LENGTH(s); n := LENGTH(s);
i := 0;
WHILE (i < n) & whole DO
whole := Utils.isWordChar(s[i]);
INC(i)
END;
k := table.data[ORD(s[0]), 1]; k := table.data[ORD(s[0]), 1];
pos := table.data[ORD(s[0]), 0]; pos := table.data[ORD(s[0]), 0];
prev_item_pos := 0; prev_item_pos := 0;
@ -138,8 +143,7 @@ BEGIN
c1 := 0X c1 := 0X
END; END;
SYSTEM.GET(text.dataPtr + (x + n)*SYSTEM.SIZE(WCHAR), c2); SYSTEM.GET(text.dataPtr + (x + n)*SYSTEM.SIZE(WCHAR), c2);
flag := Utils.isLetter(c1) OR Utils.isLetter(c2) OR Utils.isDigit(c1) OR Utils.isDigit(c2) OR flag := Utils.isWordChar(c1) OR Utils.isWordChar(c2)
(c1 = "_") OR (c2 = "_")
END; END;
IF ~flag & (x >= prev_item_pos) THEN IF ~flag & (x >= prev_item_pos) THEN
prev_item_pos := x + n; prev_item_pos := x + n;
@ -149,7 +153,7 @@ BEGIN
item.cnt := 0; item.cnt := 0;
List.append(list, item) List.append(list, item)
END; END;
item.pos[item.cnt] := x; item.pos[item.cnt] := x + offset;
INC(item.cnt) INC(item.cnt)
END END
END; END;

View File

@ -858,42 +858,81 @@ BEGIN
END parse; END parse;
PROCEDURE plain (text: tText): CB.tBuffer; PROCEDURE plain (text: tText; textStart, textEnd: tPoint; _copy: BOOLEAN): CB.tBuffer;
VAR VAR
buf: CB.tBuffer; first, line: tLine;
size: INTEGER; cnt, n: INTEGER;
line: tLine; buffer: CB.tBuffer;
PROCEDURE append (buffer: CB.tBuffer; line: tLine; first, last: INTEGER; _copy: BOOLEAN);
BEGIN BEGIN
size := 0; IF first <= last THEN
CB.append(buffer, line, first, last)
ELSE
IF (U.OS = "KOS") & _copy THEN
CB.appends(buffer, SPACE, 0, 0)
END
END
END append;
BEGIN
IF ~_copy THEN
cnt := -lenEOL;
line := text.first(tLine); line := text.first(tLine);
WHILE line # NIL DO WHILE line # NIL DO
line.pos := size; INC(cnt, lenEOL);
INC(size, line.length); line.pos := cnt;
NextLine(line); INC(cnt, line.length);
IF line # NIL THEN NextLine(line)
INC(size, CB.lenEOL)
END END
END; END;
buf := CB.create(size + 2);
line := text.first(tLine); first := getLine2(text, textStart.Y);
WHILE line # NIL DO line := first;
CB.append(buf, line, 0, line.length - 1);
NextLine(line); n := textEnd.Y - textStart.Y;
IF line # NIL THEN cnt := 0;
CB.eol(buf) WHILE n >= 0 DO
END INC(cnt, line.length + lenEOL);
IF (U.OS = "KOS") & _copy & (line.length = 0) THEN
INC(cnt)
END; END;
CB.appends(buf, 0X, 0, 0); NextLine(line);
CB.appends(buf, 0X, 0, 0) DEC(n)
RETURN buf END;
buffer := CB.create(cnt + 2); (* +2 wchars EOT *)
n := textEnd.Y - textStart.Y;
line := first;
IF n = 0 THEN
append(buffer, line, textStart.X, textEnd.X - 1, _copy)
ELSE
append(buffer, line, textStart.X, line.length - 1, _copy);
REPEAT
DEC(n);
CB.eol(buffer);
NextLine(line);
IF n > 0 THEN
append(buffer, line, 0, line.length - 1, _copy)
END
UNTIL n = 0;
append(buffer, line, 0, textEnd.X - 1, _copy)
END
RETURN buffer
END plain; END plain;
PROCEDURE search* (text: tText; s: ARRAY OF WCHAR; cs, whole: BOOLEAN): BOOLEAN; PROCEDURE _search (text: tText; s: ARRAY OF WCHAR; cs, whole: BOOLEAN; textStart, textEnd: tPoint): BOOLEAN;
VAR VAR
pos: List.tItem; pos: List.tItem;
res: BOOLEAN; res: BOOLEAN;
plainText, idxData: Search.tBuffer; plainText, idxData: CB.tBuffer;
first: tLine;
BEGIN BEGIN
res := TRUE; res := TRUE;
plainText := NIL; plainText := NIL;
@ -909,9 +948,12 @@ BEGIN
U.lowcase(text.searchText) U.lowcase(text.searchText)
END; END;
IF text.searchText # "" THEN IF text.searchText # "" THEN
plainText := plain(text); first := getLine2(text, textStart.Y);
plainText := plain(text, textStart, textEnd, FALSE);
CB.appends(plainText, 0X, 0, 0);
CB.appends(plainText, 0X, 0, 0);
idxData := Search.index(plainText, cs); idxData := Search.index(plainText, cs);
Search.find(plainText, text.searchText, whole, text.foundList); Search.find(plainText, text.searchText, whole, text.foundList, first.pos + textStart.X);
res := text.foundList.count > 0 res := text.foundList.count > 0
ELSE ELSE
Search.close Search.close
@ -921,6 +963,28 @@ BEGIN
text.search := FALSE; text.search := FALSE;
text.foundSel := 0 text.foundSel := 0
RETURN res RETURN res
END _search;
PROCEDURE search* (text: tText; s: ARRAY OF WCHAR; cs, whole: BOOLEAN): BOOLEAN;
VAR
textStart, textEnd: tPoint;
(*
PROCEDURE _getSelect (text: tText; VAR selBeg, selEnd: tPoint);
BEGIN
selBeg := text.cursor^;
selEnd := text.select^;
IF (selBeg.Y > selEnd.Y) OR (selBeg.Y = selEnd.Y) & (selBeg.X > selEnd.X) THEN
selBeg := text.select^;
selEnd := text.cursor^
END
END _getSelect;*)
BEGIN
textStart.Y := 0; textStart.X := 0;
textEnd.Y := text.count - 1; textEnd.X := text.last(tLine).length;
//_getSelect(text, textStart, textEnd)
RETURN _search(text, s, cs, whole, textStart, textEnd)
END search; END search;
@ -1572,62 +1636,17 @@ BEGIN
END getSelCnt; END getSelCnt;
PROCEDURE copy (text: tText); PROCEDURE Copy (text: tText);
VAR VAR
selBeg, selEnd: tPoint; selStart, selEnd: tPoint;
first, line: tLine;
cnt, n: INTEGER;
buffer: CB.tBuffer; buffer: CB.tBuffer;
PROCEDURE append (buffer: CB.tBuffer; line: tLine; first, last: INTEGER);
BEGIN BEGIN
IF first <= last THEN getSelect(text, selStart, selEnd);
CB.append(buffer, line, first, last) buffer := plain(text, selStart, selEnd, TRUE);
ELSE
IF U.OS = "KOS" THEN
CB.appends(buffer, SPACE, 0, 0)
END
END
END append;
BEGIN
getSelect(text, selBeg, selEnd);
first := getLine2(text, selBeg.Y);
line := first;
n := selEnd.Y - selBeg.Y;
cnt := 0;
WHILE n >= 0 DO
INC(cnt, line.length + (lenEOL + ORD(U.OS = "KOS")));
NextLine(line);
DEC(n)
END;
buffer := CB.create(cnt + 2); (* +2 wchars EOT *)
n := selEnd.Y - selBeg.Y;
line := first;
IF n = 0 THEN
append(buffer, line, selBeg.X, selEnd.X - 1)
ELSE
append(buffer, line, selBeg.X, line.length - 1);
REPEAT
DEC(n);
CB.eol(buffer);
NextLine(line);
IF n > 0 THEN
append(buffer, line, 0, line.length - 1)
END
UNTIL n = 0;
append(buffer, line, 0, selEnd.X - 1)
END;
CB.eot(buffer); CB.eot(buffer);
CB.put(buffer); CB.put(buffer);
CB.destroy(buffer) CB.destroy(buffer)
END copy; END Copy;
PROCEDURE paste (text: tText); PROCEDURE paste (text: tText);
@ -1969,11 +1988,6 @@ BEGIN
END MoveLines; END MoveLines;
PROCEDURE isWordChar (c: WCHAR): BOOLEAN;
RETURN U.isLetter(c) OR U.isDigit(c) OR (c = "_")
END isWordChar;
PROCEDURE getSelectedText* (text: tText; VAR s: ARRAY OF WCHAR); PROCEDURE getSelectedText* (text: tText; VAR s: ARRAY OF WCHAR);
VAR VAR
n: INTEGER; n: INTEGER;
@ -2006,12 +2020,12 @@ BEGIN
END; END;
IF str # "" THEN IF str # "" THEN
i := 0; i := 0;
WHILE (i < n) & isWordChar(str[i]) DO WHILE (i < n) & U.isWordChar(str[i]) DO
INC(i) INC(i)
END; END;
IF (i # n) OR IF (i # n) OR
((x1 > 0) & isWordChar(Lines.getChar(curLine, x1 - 1))) OR ((x1 > 0) & U.isWordChar(Lines.getChar(curLine, x1 - 1))) OR
((x2 < curLine.length) & isWordChar(Lines.getChar(curLine, x2))) THEN ((x2 < curLine.length) & U.isWordChar(Lines.getChar(curLine, x2))) THEN
str := "" str := ""
END END
END; END;
@ -2029,8 +2043,8 @@ VAR
c: WCHAR; c: WCHAR;
BEGIN BEGIN
c := Lines.getChar(line, pos); c := Lines.getChar(line, pos);
IF isWordChar(c) THEN IF U.isWordChar(c) THEN
WHILE (pos < line.length) & isWordChar(Lines.getChar(line, pos)) DO WHILE (pos < line.length) & U.isWordChar(Lines.getChar(line, pos)) DO
INC(pos) INC(pos)
END END
ELSIF Lines.isSpace(c) THEN ELSIF Lines.isSpace(c) THEN
@ -2038,7 +2052,7 @@ BEGIN
INC(pos) INC(pos)
END END
ELSE ELSE
WHILE (pos < line.length) & ~Lines.isSpace(Lines.getChar(line, pos)) & ~isWordChar(Lines.getChar(line, pos)) DO WHILE (pos < line.length) & ~Lines.isSpace(Lines.getChar(line, pos)) & ~U.isWordChar(Lines.getChar(line, pos)) DO
INC(pos) INC(pos)
END END
END END
@ -2151,7 +2165,7 @@ BEGIN
|ORD("C"), ORD("X"): |ORD("C"), ORD("X"):
IF ctrl THEN IF ctrl THEN
IF selected(text) THEN IF selected(text) THEN
copy(text); Copy(text);
IF code = ORD("X") THEN IF code = ORD("X") THEN
delSelect(text) delSelect(text)
END END
@ -2208,18 +2222,18 @@ BEGIN
cursorX := text.cursor.X; cursorX := text.cursor.X;
line := text.curLine; line := text.curLine;
x1 := cursorX - 1; x1 := cursorX - 1;
IF (cursorX < line.length) & isWordChar(Lines.getChar(line, cursorX)) THEN IF (cursorX < line.length) & U.isWordChar(Lines.getChar(line, cursorX)) THEN
x2 := cursorX; x2 := cursorX;
WHILE (x2 < line.length) & isWordChar(Lines.getChar(line, x2)) DO WHILE (x2 < line.length) & U.isWordChar(Lines.getChar(line, x2)) DO
INC(x2) INC(x2)
END END
ELSE ELSE
WHILE (x1 >= 0) & ~isWordChar(Lines.getChar(line, x1)) DO WHILE (x1 >= 0) & ~U.isWordChar(Lines.getChar(line, x1)) DO
DEC(x1) DEC(x1)
END; END;
x2 := x1 + 1 x2 := x1 + 1
END; END;
WHILE (x1 >= 0) & isWordChar(Lines.getChar(line, x1)) DO WHILE (x1 >= 0) & U.isWordChar(Lines.getChar(line, x1)) DO
DEC(x1) DEC(x1)
END; END;
INC(x1); INC(x1);

View File

@ -325,4 +325,9 @@ BEGIN
END inString; END inString;
PROCEDURE isWordChar* (c: WCHAR): BOOLEAN;
RETURN isLetter(c) OR isDigit(c) OR (c = "_")
END isWordChar;
END Utils. END Utils.