CEdit: null character support; reduced memory usage when replacing text and moving lines

git-svn-id: svn://kolibrios.org@9560 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-02 18:57:13 +00:00
parent 544a2a9702
commit a218cacd34
8 changed files with 113 additions and 128 deletions

Binary file not shown.

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -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 (30-dec-2021)"; HEADER = "CEdit (02-jan-2022)";
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";
@ -1793,16 +1793,19 @@ BEGIN
|btnFindNext: |btnFindNext:
IF searchText # "" THEN IF searchText # "" THEN
notFound := ~T.findNext(text, BKW.value); notFound := ~T.findNext(text, BKW.value);
SetFocus(FindEdit, FALSE);
repaint repaint
END END
|btnReplace: |btnReplace:
T.replace(text, replaceText, LENGTH(searchText)); T.replace(text, replaceText, LENGTH(searchText));
SetFocus(FindEdit, FALSE);
repaint repaint
|btnReplaceAll: |btnReplaceAll:
notFound := ~T.search(text, searchText, cs, whole); notFound := ~T.search(text, searchText, cs, whole);
IF ~notFound THEN IF ~notFound THEN
replaced := T.replaceAll(text, replaceText, LENGTH(searchText)); replaced := T.replaceAll(text, replaceText, LENGTH(searchText));
END; END;
SetFocus(FindEdit, FALSE);
repaint repaint
|btnGoto: |btnGoto:
goto; goto;

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -24,7 +24,6 @@ IMPORT SYSTEM, KOSAPI, E := Encodings, Lines, K := KolibriOS;
CONST CONST
TTEXT = 0; TTEXT = 0;
lenEOL* = 2; lenEOL* = 2;
TAB = 9X;
TYPE TYPE
tBuffer* = POINTER TO RECORD tBuffer* = POINTER TO RECORD
@ -60,11 +59,14 @@ BEGIN
ptr := buffer.dataPtr; ptr := buffer.dataPtr;
WHILE cnt > 0 DO WHILE cnt > 0 DO
SYSTEM.GET(ptr, wch); SYSTEM.GET(ptr, wch);
IF wch # Lines.TAB1 THEN IF wch = Lines.TAB1 THEN
SYSTEM.PUT(pchar, CHR(E.UNI[ORD(wch), E.CP866] MOD 256)); DEC(size)
ELSIF wch = Lines.NUL THEN
SYSTEM.PUT(pchar, 0X);
INC(pchar) INC(pchar)
ELSE ELSE
DEC(size); SYSTEM.PUT(pchar, CHR(E.UNI[ORD(wch), E.CP866] MOD 256));
INC(pchar)
END; END;
INC(ptr, 2); INC(ptr, 2);
DEC(cnt) DEC(cnt)

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -282,6 +282,9 @@ BEGIN
ELSE ELSE
color := canvas.textColor color := canvas.textColor
END; END;
IF c = Lines.NUL THEN
c := 0X
END;
KOSAPI.sysfunc6(4, x*65536 + y, font + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8) KOSAPI.sysfunc6(4, x*65536 + y, font + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8)
END; END;
INC(x, canvas.font.width); INC(x, canvas.font.width);

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -26,7 +26,8 @@ CONST
WCHAR_SIZE = 2; WCHAR_SIZE = 2;
SPACE* = 20X; SPACE* = 20X;
TAB* = 9X; TAB* = 9X;
TAB1* = 0FFFEX; NUL* = 0FDD0X;
TAB1* = 0FDD1X;
TYPE TYPE

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -151,6 +151,7 @@ PROCEDURE _insert* (list: tList; item, newItem: tItem);
VAR VAR
next: tItem; next: tItem;
BEGIN BEGIN
IF item # NIL THEN
next := item.next; next := item.next;
IF next # NIL THEN IF next # NIL THEN
movPtr(next.prev, newItem); movPtr(next.prev, newItem);
@ -161,42 +162,17 @@ BEGIN
ELSE ELSE
_append(list, newItem) _append(list, newItem)
END END
ELSE
ASSERT(list.first # NIL);
movPtr(newItem.prev, NIL);
movPtr(newItem.next, list.first);
movPtr(list.first.prev, newItem);
movPtr(list.first, newItem);
movInt(list.count, list.count + 1)
END
END _insert; END _insert;
PROCEDURE _exchange* (list: tList; a, b: tItem);
VAR
a0, b0: tItem;
BEGIN
IF (a # NIL) & (b # NIL) THEN
ASSERT((a.next = b) & (b.prev = a));
a0 := a.prev;
b0 := b.next;
movPtr(b.prev, a0);
movPtr(a.next, b0);
movPtr(b.next, a);
movPtr(a.prev, b);
IF a0 # NIL THEN
IF b0 # NIL THEN
movPtr(a0.next, b);
movPtr(b0.prev, a);
ELSE
movPtr(a0.next, b);
movPtr(list.last, a)
END
ELSE
IF b0 # NIL THEN
movPtr(b0.prev, a);
movPtr(list.first, b)
ELSE
movPtr(list.first, b);
movPtr(list.last, a)
END
END
END
END _exchange;
PROCEDURE append* (list: tList; item: tItem); PROCEDURE append* (list: tList; item: tItem);
BEGIN BEGIN
item.prev := list.last; item.prev := list.last;

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -178,11 +178,14 @@ BEGIN
c := WCHR(file.getChar(file) MOD 65536); c := WCHR(file.getChar(file) MOD 65536);
IF c = Lines.TAB1 THEN IF c = Lines.TAB1 THEN
c := SPACE c := SPACE
ELSIF c = 0X THEN
c := Lines.NUL
END; END;
IF c = CR THEN IF c = CR THEN
eol := TRUE; eol := TRUE;
file.CR := TRUE file.CR := TRUE
ELSIF (c = LF) OR (c = 0X) THEN ELSIF c = LF THEN
IF ~file.CR THEN IF ~file.CR THEN
eol := TRUE eol := TRUE
END; END;
@ -424,7 +427,11 @@ VAR
BEGIN BEGIN
FOR i := 0 TO n - 1 DO FOR i := 0 TO n - 1 DO
c := Lines.getChar(line, i); c := Lines.getChar(line, i);
IF c # Lines.TAB1 THEN IF c = Lines.TAB1 THEN
(* nothing to do *)
ELSIF c = Lines.NUL THEN
file.putChar(file, 0)
ELSE
file.putChar(file, ORD(c)) file.putChar(file, ORD(c))
END END
END END

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -1805,77 +1805,78 @@ BEGIN
END dupLine; END dupLine;
PROCEDURE exchange (text: tText; first, second: tLine);
BEGIN
List._exchange(text, first, second);
Lines.modify(text.curLine);
modify(text);
UpDown(text, 0)
END exchange;
PROCEDURE upLine (text: tText);
BEGIN
DEC(text.cursor.Y);
exchange(text, text.curLine.prev(tLine), text.curLine)
END upLine;
PROCEDURE downLine (text: tText);
BEGIN
INC(text.cursor.Y);
exchange(text, text.curLine, text.curLine.next(tLine))
END downLine;
PROCEDURE MoveLines* (text: tText; down: BOOLEAN); PROCEDURE MoveLines* (text: tText; down: BOOLEAN);
VAR VAR
last: tLine; last, first, line: tLine;
selBeg, selEnd, temp: tPoint; selBeg, selEnd, temp: tPoint;
n, step: INTEGER; step: INTEGER;
frw: BOOLEAN; frw: BOOLEAN;
moveLine: PROCEDURE (text: tText);
BEGIN BEGIN
getSelect(text, selBeg, selEnd); getSelect(text, selBeg, selEnd);
IF (selBeg.Y > 0) & ~down OR (selEnd.Y < text.count - 1) & down THEN IF ((selBeg.Y > 0) & ~down OR (selEnd.Y < text.count - 1) & down) THEN
IF down THEN modify(text);
step := -2; step := ORD(down)*2 - 1;
moveLine := downLine IF selBeg.Y # selEnd.Y THEN
ELSE
step := 2;
moveLine := upLine
END;
frw := (text.cursor.X = selEnd.X) & (text.cursor.Y = selEnd.Y); frw := (text.cursor.X = selEnd.X) & (text.cursor.Y = selEnd.Y);
IF selEnd.Y # selBeg.Y THEN
IF down # frw THEN IF down # frw THEN
temp := text.cursor^; temp := text.cursor^;
SetPos(text, 0, text.select.Y); SetPos(text, 0, text.select.Y);
setSelect(text); setSelect(text);
text.select^ := temp text.select^ := temp
END; END;
ASSERT(selBeg.Y < selEnd.Y);
first := getLine(text, selBeg.Y);
last := getLine(text, selEnd.Y); last := getLine(text, selEnd.Y);
line := first;
Lines.modify(line);
REPEAT
NextLine(line);
Lines.modify(line)
UNTIL line = last;
IF down THEN
text.curLine := last.prev(tLine)
ELSE
text.curLine := first.next(tLine)
END;
selBeg.X := 0; selBeg.X := 0;
selEnd.X := last.length; selEnd.X := last.length;
n := selEnd.Y - selBeg.Y + 1; IF down THEN
WHILE n > 0 DO last := last.next(tLine);
moveLine(text); List._delete(text, last);
SetPos(text, 0, text.cursor.Y + step); List._insert(text, first.prev, last)
DEC(n)
END
ELSE ELSE
moveLine(text) first := first.prev(tLine);
List._delete(text, first);
List._insert(text, last, first)
END; END;
IF down THEN
IF frw THEN
temp := selBeg; temp := selBeg;
selBeg := selEnd; selBeg := selEnd;
selEnd := temp selEnd := temp;
END; END;
step := step DIV 2; SetPos(text, selBeg.X, selBeg.Y + step);
SetPos(text, selBeg.X, selBeg.Y - step);
setSelect(text); setSelect(text);
text.select.X := selEnd.X; text.select.X := selEnd.X;
text.select.Y := selEnd.Y - step text.select.Y := selEnd.Y + step
ELSE
first := getLine(text, selBeg.Y);
Lines.modify(first);
IF down THEN
last := first.next(tLine)
ELSE
last := first.prev.prev(tLine)
END;
List._delete(text, first);
List._insert(text, last, first);
INC(text.cursor.Y, step);
INC(text.select.Y, step);
SetPos(text, text.cursor.X, text.cursor.Y)
END
END END
END MoveLines; END MoveLines;
@ -2541,18 +2542,6 @@ BEGIN
END findNext; END findNext;
PROCEDURE rewrite (line: tLine; repl: ARRAY OF WCHAR; pos, n: INTEGER);
BEGIN
IF n > 0 THEN
Lines.copy(line)
END;
WHILE n > 0 DO
DEC(n);
Lines.setChar(line, pos + n, repl[n])
END
END rewrite;
PROCEDURE replace* (text: tText; s: ARRAY OF WCHAR; n: INTEGER); PROCEDURE replace* (text: tText; s: ARRAY OF WCHAR; n: INTEGER);
VAR VAR
line: tLine; line: tLine;
@ -2564,11 +2553,15 @@ BEGIN
i := text.cursor.X; i := text.cursor.X;
IF sLen > n THEN IF sLen > n THEN
Lines.insert3(line, i, sLen - n) Lines.insert3(line, i, sLen - n)
ELSIF n > sLen THEN
Lines.delCharN(line, i, n - sLen)
ELSE (* n = sLen *)
Lines.copy(line)
END; END;
SetPos(text, i + sLen, text.cursor.Y); SetPos(text, i + sLen, text.cursor.Y);
rewrite(line, s, i, sLen); WHILE sLen > 0 DO
IF n > sLen THEN DEC(sLen);
Lines.delCharN(line, text.cursor.X, n - sLen) Lines.setChar(line, i + sLen, s[sLen])
END; END;
resetSelect(text); resetSelect(text);
Lines.modify(line); Lines.modify(line);