CEdit: fixed whole word search
git-svn-id: svn://kolibrios.org@9907 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f8df2f2297
commit
3ade12b666
Binary file not shown.
@ -99,7 +99,7 @@ delim = =
|
||||
|
||||
[lang_Fasm]
|
||||
KW1 =
|
||||
KW2 =
|
||||
KW2 = byte,word,dword,db,dw,dd
|
||||
KW3 =
|
||||
delim = {}[]<>=:,()&*/|+-\#
|
||||
|
||||
|
@ -28,7 +28,7 @@ IMPORT
|
||||
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
|
||||
|
||||
CONST
|
||||
HEADER = "CEdit (06-mar-2023)";
|
||||
HEADER = "CEdit (18-mar-2023)";
|
||||
|
||||
ShellFilter = "";
|
||||
EditFilter = "sh|inc|txt|asm|ob07|c|cpp|h|pas|pp|lua|ini|json";
|
||||
|
@ -26,7 +26,7 @@ CONST
|
||||
itemSize = 64;
|
||||
|
||||
TYPE
|
||||
tBuffer* = CB.tBuffer;
|
||||
tBuffer = CB.tBuffer;
|
||||
|
||||
tIdxTable = ARRAY 65536, 2 OF INTEGER;
|
||||
|
||||
@ -115,15 +115,20 @@ BEGIN
|
||||
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
|
||||
k, pos, n, x, prev_item_pos: INTEGER;
|
||||
k, pos, n, i, x, prev_item_pos: INTEGER;
|
||||
item: tPos;
|
||||
c1, c2: WCHAR;
|
||||
flag: BOOLEAN;
|
||||
BEGIN
|
||||
ASSERT(table # NIL);
|
||||
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];
|
||||
pos := table.data[ORD(s[0]), 0];
|
||||
prev_item_pos := 0;
|
||||
@ -138,8 +143,7 @@ BEGIN
|
||||
c1 := 0X
|
||||
END;
|
||||
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
|
||||
(c1 = "_") OR (c2 = "_")
|
||||
flag := Utils.isWordChar(c1) OR Utils.isWordChar(c2)
|
||||
END;
|
||||
IF ~flag & (x >= prev_item_pos) THEN
|
||||
prev_item_pos := x + n;
|
||||
@ -149,7 +153,7 @@ BEGIN
|
||||
item.cnt := 0;
|
||||
List.append(list, item)
|
||||
END;
|
||||
item.pos[item.cnt] := x;
|
||||
item.pos[item.cnt] := x + offset;
|
||||
INC(item.cnt)
|
||||
END
|
||||
END;
|
||||
|
@ -858,42 +858,81 @@ BEGIN
|
||||
END parse;
|
||||
|
||||
|
||||
PROCEDURE plain (text: tText): CB.tBuffer;
|
||||
PROCEDURE plain (text: tText; textStart, textEnd: tPoint; _copy: BOOLEAN): CB.tBuffer;
|
||||
VAR
|
||||
buf: CB.tBuffer;
|
||||
size: INTEGER;
|
||||
line: tLine;
|
||||
first, line: tLine;
|
||||
cnt, n: INTEGER;
|
||||
buffer: CB.tBuffer;
|
||||
|
||||
|
||||
PROCEDURE append (buffer: CB.tBuffer; line: tLine; first, last: INTEGER; _copy: BOOLEAN);
|
||||
BEGIN
|
||||
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
|
||||
size := 0;
|
||||
line := text.first(tLine);
|
||||
WHILE line # NIL DO
|
||||
line.pos := size;
|
||||
INC(size, line.length);
|
||||
NextLine(line);
|
||||
IF line # NIL THEN
|
||||
INC(size, CB.lenEOL)
|
||||
END
|
||||
END;
|
||||
buf := CB.create(size + 2);
|
||||
line := text.first(tLine);
|
||||
WHILE line # NIL DO
|
||||
CB.append(buf, line, 0, line.length - 1);
|
||||
NextLine(line);
|
||||
IF line # NIL THEN
|
||||
CB.eol(buf)
|
||||
END
|
||||
END;
|
||||
CB.appends(buf, 0X, 0, 0);
|
||||
CB.appends(buf, 0X, 0, 0)
|
||||
RETURN buf
|
||||
IF ~_copy THEN
|
||||
cnt := -lenEOL;
|
||||
line := text.first(tLine);
|
||||
WHILE line # NIL DO
|
||||
INC(cnt, lenEOL);
|
||||
line.pos := cnt;
|
||||
INC(cnt, line.length);
|
||||
NextLine(line)
|
||||
END
|
||||
END;
|
||||
|
||||
first := getLine2(text, textStart.Y);
|
||||
line := first;
|
||||
|
||||
n := textEnd.Y - textStart.Y;
|
||||
cnt := 0;
|
||||
WHILE n >= 0 DO
|
||||
INC(cnt, line.length + lenEOL);
|
||||
IF (U.OS = "KOS") & _copy & (line.length = 0) THEN
|
||||
INC(cnt)
|
||||
END;
|
||||
NextLine(line);
|
||||
DEC(n)
|
||||
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;
|
||||
|
||||
|
||||
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
|
||||
pos: List.tItem;
|
||||
res: BOOLEAN;
|
||||
plainText, idxData: Search.tBuffer;
|
||||
plainText, idxData: CB.tBuffer;
|
||||
first: tLine;
|
||||
|
||||
BEGIN
|
||||
res := TRUE;
|
||||
plainText := NIL;
|
||||
@ -909,9 +948,12 @@ BEGIN
|
||||
U.lowcase(text.searchText)
|
||||
END;
|
||||
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);
|
||||
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
|
||||
ELSE
|
||||
Search.close
|
||||
@ -921,16 +963,38 @@ BEGIN
|
||||
text.search := FALSE;
|
||||
text.foundSel := 0
|
||||
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;
|
||||
|
||||
|
||||
PROCEDURE modify (text: tText);
|
||||
BEGIN
|
||||
text.modified := TRUE;
|
||||
text.comments := TRUE;
|
||||
text.search := TRUE;
|
||||
text.guard := TRUE;
|
||||
text.wordSel := TRUE
|
||||
text.modified := TRUE;
|
||||
text.comments := TRUE;
|
||||
text.search := TRUE;
|
||||
text.guard := TRUE;
|
||||
text.wordSel := TRUE
|
||||
END modify;
|
||||
|
||||
|
||||
@ -966,24 +1030,24 @@ END getEol;
|
||||
|
||||
PROCEDURE DelLine (text: tText; line: tLine);
|
||||
BEGIN
|
||||
List._delete(text, line);
|
||||
Lines.destroy(line);
|
||||
modify(text)
|
||||
List._delete(text, line);
|
||||
Lines.destroy(line);
|
||||
modify(text)
|
||||
END DelLine;
|
||||
|
||||
|
||||
PROCEDURE setSelect (text: tText);
|
||||
BEGIN
|
||||
IF text.select = text.cursor THEN
|
||||
text.select2^ := text.cursor^;
|
||||
text.select := text.select2
|
||||
END
|
||||
IF text.select = text.cursor THEN
|
||||
text.select2^ := text.cursor^;
|
||||
text.select := text.select2
|
||||
END
|
||||
END setSelect;
|
||||
|
||||
|
||||
PROCEDURE resetSelect* (text: tText);
|
||||
BEGIN
|
||||
text.select := text.cursor
|
||||
text.select := text.cursor
|
||||
END resetSelect;
|
||||
|
||||
|
||||
@ -1572,62 +1636,17 @@ BEGIN
|
||||
END getSelCnt;
|
||||
|
||||
|
||||
PROCEDURE copy (text: tText);
|
||||
PROCEDURE Copy (text: tText);
|
||||
VAR
|
||||
selBeg, selEnd: tPoint;
|
||||
first, line: tLine;
|
||||
cnt, n: INTEGER;
|
||||
buffer: CB.tBuffer;
|
||||
|
||||
|
||||
PROCEDURE append (buffer: CB.tBuffer; line: tLine; first, last: INTEGER);
|
||||
BEGIN
|
||||
IF first <= last THEN
|
||||
CB.append(buffer, line, first, last)
|
||||
ELSE
|
||||
IF U.OS = "KOS" THEN
|
||||
CB.appends(buffer, SPACE, 0, 0)
|
||||
END
|
||||
END
|
||||
END append;
|
||||
|
||||
|
||||
selStart, selEnd: tPoint;
|
||||
buffer: CB.tBuffer;
|
||||
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;
|
||||
getSelect(text, selStart, selEnd);
|
||||
buffer := plain(text, selStart, selEnd, TRUE);
|
||||
CB.eot(buffer);
|
||||
CB.put(buffer);
|
||||
CB.destroy(buffer)
|
||||
END copy;
|
||||
END Copy;
|
||||
|
||||
|
||||
PROCEDURE paste (text: tText);
|
||||
@ -1969,11 +1988,6 @@ BEGIN
|
||||
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);
|
||||
VAR
|
||||
n: INTEGER;
|
||||
@ -2006,12 +2020,12 @@ BEGIN
|
||||
END;
|
||||
IF str # "" THEN
|
||||
i := 0;
|
||||
WHILE (i < n) & isWordChar(str[i]) DO
|
||||
WHILE (i < n) & U.isWordChar(str[i]) DO
|
||||
INC(i)
|
||||
END;
|
||||
IF (i # n) OR
|
||||
((x1 > 0) & isWordChar(Lines.getChar(curLine, x1 - 1))) OR
|
||||
((x2 < curLine.length) & isWordChar(Lines.getChar(curLine, x2))) THEN
|
||||
((x1 > 0) & U.isWordChar(Lines.getChar(curLine, x1 - 1))) OR
|
||||
((x2 < curLine.length) & U.isWordChar(Lines.getChar(curLine, x2))) THEN
|
||||
str := ""
|
||||
END
|
||||
END;
|
||||
@ -2029,8 +2043,8 @@ VAR
|
||||
c: WCHAR;
|
||||
BEGIN
|
||||
c := Lines.getChar(line, pos);
|
||||
IF isWordChar(c) THEN
|
||||
WHILE (pos < line.length) & isWordChar(Lines.getChar(line, pos)) DO
|
||||
IF U.isWordChar(c) THEN
|
||||
WHILE (pos < line.length) & U.isWordChar(Lines.getChar(line, pos)) DO
|
||||
INC(pos)
|
||||
END
|
||||
ELSIF Lines.isSpace(c) THEN
|
||||
@ -2038,7 +2052,7 @@ BEGIN
|
||||
INC(pos)
|
||||
END
|
||||
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)
|
||||
END
|
||||
END
|
||||
@ -2151,7 +2165,7 @@ BEGIN
|
||||
|ORD("C"), ORD("X"):
|
||||
IF ctrl THEN
|
||||
IF selected(text) THEN
|
||||
copy(text);
|
||||
Copy(text);
|
||||
IF code = ORD("X") THEN
|
||||
delSelect(text)
|
||||
END
|
||||
@ -2208,18 +2222,18 @@ BEGIN
|
||||
cursorX := text.cursor.X;
|
||||
line := text.curLine;
|
||||
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;
|
||||
WHILE (x2 < line.length) & isWordChar(Lines.getChar(line, x2)) DO
|
||||
WHILE (x2 < line.length) & U.isWordChar(Lines.getChar(line, x2)) DO
|
||||
INC(x2)
|
||||
END
|
||||
ELSE
|
||||
WHILE (x1 >= 0) & ~isWordChar(Lines.getChar(line, x1)) DO
|
||||
WHILE (x1 >= 0) & ~U.isWordChar(Lines.getChar(line, x1)) DO
|
||||
DEC(x1)
|
||||
END;
|
||||
x2 := x1 + 1
|
||||
END;
|
||||
WHILE (x1 >= 0) & isWordChar(Lines.getChar(line, x1)) DO
|
||||
WHILE (x1 >= 0) & U.isWordChar(Lines.getChar(line, x1)) DO
|
||||
DEC(x1)
|
||||
END;
|
||||
INC(x1);
|
||||
|
@ -325,4 +325,9 @@ BEGIN
|
||||
END inString;
|
||||
|
||||
|
||||
PROCEDURE isWordChar* (c: WCHAR): BOOLEAN;
|
||||
RETURN isLetter(c) OR isDigit(c) OR (c = "_")
|
||||
END isWordChar;
|
||||
|
||||
|
||||
END Utils.
|
Loading…
Reference in New Issue
Block a user