parent
ba333fba1f
commit
bcb38e3d02
|
|
@ -70,7 +70,6 @@ TYPE TMemoLineList=class(tnumindexarray) //
|
|||
begin
|
||||
if(Flock)then
|
||||
begin
|
||||
//echo "+++\r\n";
|
||||
FEdit.UpDateScroll();
|
||||
end
|
||||
end
|
||||
|
|
@ -652,6 +651,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
FIsCaretShow; //光标可见
|
||||
fcaretcreated; //光标已经构造成功
|
||||
fForceCaret;
|
||||
fcaretcout; //列选择时候的caret count
|
||||
FCharsInWindow; //
|
||||
fTextHeight; //行高
|
||||
fLinesInWindow; //能显示的行数
|
||||
|
|
@ -839,7 +839,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
r[1]:= RC[1]+fTextHeight * iy;
|
||||
iy++;
|
||||
r[3]:= r[1]+fTextHeight;
|
||||
if i+1=fCaretY then
|
||||
if i+1=fCaretY then //当前行
|
||||
begin
|
||||
if Color<>fcurrentLineColor then
|
||||
begin
|
||||
|
|
@ -856,6 +856,19 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
if FSelectionMode=smLine then
|
||||
begin
|
||||
end else
|
||||
if FSelectionMode=smColumn then
|
||||
begin
|
||||
a1 := min(bb[1],ee[1]);
|
||||
a2 := max(bb[1],ee[1]);
|
||||
if a1=e2 then
|
||||
begin
|
||||
src := array(0,0,0,0);
|
||||
end else
|
||||
begin
|
||||
src[0]+= fCharWidth *(a1-1);
|
||||
src[2]:= src[0]+fCharWidth *(a2-a1);
|
||||
end
|
||||
end else
|
||||
begin
|
||||
if bb[0]=ee[0]then //同一行
|
||||
begin
|
||||
|
|
@ -1242,8 +1255,8 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
end
|
||||
if not s then return;
|
||||
bb := array(fCaretY,fCaretX);
|
||||
r := buffer_InsertChars(bb,s);
|
||||
fUndoList.AddChange(crInsert,bb,r,s,0);
|
||||
r := buffer_InsertChars(bb,ee,s,FSelectionMode);
|
||||
fUndoList.AddChange(crInsert,bb,r,s,FSelectionMode);
|
||||
SetCaretXY(r);
|
||||
UpdateCaret();
|
||||
memtextchanged(bb);
|
||||
|
|
@ -1583,6 +1596,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
begin
|
||||
if not(ifarray(p2)and ifarray(p1)and p2[0]>= 1 and p2[1]>= 1)then return;
|
||||
SetCaretXY(p2);
|
||||
|
||||
IncPaintLock();
|
||||
if Sel then
|
||||
begin
|
||||
|
|
@ -1601,9 +1615,20 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
ed := GetBlockEnd()[0];
|
||||
InvalidateLines(bg,ed);
|
||||
end
|
||||
if FSelectionMode=smColumn then
|
||||
begin
|
||||
if fBlockBegin then fBlockBegin[1] := caretxy[1];
|
||||
fBlockEnd := CaretXY;
|
||||
end else
|
||||
begin
|
||||
fBlockBegin := CaretXY;
|
||||
fBlockEnd := CaretXY;
|
||||
end
|
||||
end
|
||||
if FSelectionMode=smColumn and P2[0]<>P1[0] then
|
||||
begin
|
||||
ReCreateCaret();
|
||||
end else
|
||||
UpDateCaret();
|
||||
DecPaintLock();
|
||||
end
|
||||
|
|
@ -1652,7 +1677,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
begin
|
||||
if fCaretX >= fLeftChar and(fCaretX<fCharsInWindow+fLeftChar)and FTopLine <= fCaretY and fCaretY<FTopLine+fLinesInWindow then
|
||||
begin
|
||||
_wapi.SetCaretPos(FGutter.Width+FCharWidth *(FCaretX-FLeftChar),(fTextHeight *(fCaretY-FTopLine)+3));
|
||||
_wapi.SetCaretPos(FGutter.Width+FCharWidth *(FCaretX-FLeftChar),(fTextHeight *(fCaretY-FTopLine-((FSelectionMode=smColumn)?(fcaretcout-1):0))+3));
|
||||
//_wapi.ShowCaret(self.Handle);
|
||||
if not FIsCaretShow then
|
||||
begin
|
||||
|
|
@ -1887,7 +1912,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
begin
|
||||
fBlockEnd := array(len,1+fLines[len-1].StrLength());
|
||||
InvalidateRect(nil,false);
|
||||
end else
|
||||
end
|
||||
end
|
||||
function CopyToClipboard(); //复制选择
|
||||
begin
|
||||
|
|
@ -1920,7 +1945,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
end
|
||||
function SetSelectionMode(v);
|
||||
begin
|
||||
if(v <> FSelectionMode)and(v in array(smNormal,smLine))then FSelectionMode := v;
|
||||
if(v <> FSelectionMode)and(v in array(smNormal,smLine,smColumn))then FSelectionMode := v;
|
||||
end
|
||||
function MoveCaretHorz(stp,sel);
|
||||
begin
|
||||
|
|
@ -1997,9 +2022,15 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
crDelete:
|
||||
begin
|
||||
//插入
|
||||
if item.FSelMode = smColumn then
|
||||
begin
|
||||
|
||||
end
|
||||
else
|
||||
begin
|
||||
SetCaretXY(item.FStartPos);
|
||||
InsertChars(item.FStr);
|
||||
//echo tostn(item);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2219,42 +2250,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
if not GetSelAvail()then return r;
|
||||
bb := GetBlockBegin();
|
||||
ee := GetBlockEnd();
|
||||
if FSelectionMode=smLine then
|
||||
begin
|
||||
len := ee[0];
|
||||
for i := bb[0]to ee[0] do
|
||||
begin
|
||||
r += fLines[i-1].FStr;
|
||||
if i<len then r += "\r\n";
|
||||
end
|
||||
end else
|
||||
begin
|
||||
if bb[0]=ee[0]then
|
||||
begin
|
||||
s := fLines[bb[0]-1].FStr;
|
||||
if ee[1]>bb[1]and ee[1]>1 then
|
||||
try
|
||||
r := s[bb[1]:ee[1]-1]; //可能出错,添加try
|
||||
except
|
||||
r := "";
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
//第一行
|
||||
s := fLines[bb[0]-1].FStr;
|
||||
if bb[1]<= length(s)then r += s[bb[1]:];
|
||||
r += "\r\n";
|
||||
//中间
|
||||
for i := bb[0]to ee[0]-2 do
|
||||
begin
|
||||
r += fLines[i].FStr;
|
||||
r += "\r\n";
|
||||
end
|
||||
//最后一行
|
||||
s := fLines[ee[0]-1].FStr;
|
||||
if s and ee[1]>1 then r += s[1:ee[1]-1];
|
||||
end
|
||||
end
|
||||
r := buffer_getchars(bb,ee,FSelectionMode);
|
||||
return r;
|
||||
end
|
||||
function SetCaretX(cx);
|
||||
|
|
@ -2289,7 +2285,9 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
end
|
||||
function GetSelAvail();
|
||||
begin
|
||||
return fBlockBegin <> fBlockEnd and fBlockBegin and fBlockEnd;
|
||||
r := fBlockBegin <> fBlockEnd and fBlockBegin and fBlockEnd;
|
||||
if FSelectionMode=smColumn then return fBlockBegin[1]<>fBlockEnd[1];
|
||||
return r;
|
||||
end
|
||||
function SelectNextChar(); //选取后一个字符
|
||||
begin
|
||||
|
|
@ -2327,6 +2325,7 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
end else
|
||||
if fCaretY>1 then
|
||||
begin
|
||||
//if FSelectionMode=smColumn then return ;
|
||||
s := fLines.GetStringByIndex(fCaretY-2);
|
||||
fBlockEnd := array(CaretY-1,length(s)+1);
|
||||
end
|
||||
|
|
@ -2339,27 +2338,15 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
IncPaintLock();
|
||||
ee := GetBlockEnd();
|
||||
bb := DeleteSel();
|
||||
up := false;
|
||||
if bb[0]=ee[0]then
|
||||
begin
|
||||
//InvalidateLines(bb[0],bb[0]);
|
||||
end else
|
||||
begin
|
||||
up := true;
|
||||
end
|
||||
if v then
|
||||
begin
|
||||
bb2 := buffer_InsertChars(bb,v);
|
||||
fUndoList.AddChange(crInsert,bb,bb2,v,0);
|
||||
bb2 := buffer_InsertChars(bb,ee,v,FSelectionMode);
|
||||
fUndoList.AddChange(crInsert,bb,bb2,v,FSelectionMode);
|
||||
fUndoList.MergeReplaceItem();
|
||||
fBlockEnd := bb2;
|
||||
if bb2[0]<> bb[0]then up := true;
|
||||
end else
|
||||
bb2 := bb;
|
||||
ExecuteCommand(ecGotoXY,bb2);
|
||||
//SetCaretXY(bb2);
|
||||
//if up then UpDateScroll();
|
||||
//UpDateCaret();
|
||||
DecPaintLock();
|
||||
memtextchanged(bb);
|
||||
end
|
||||
|
|
@ -2370,13 +2357,13 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
if not GetSelAvail()then return 0;
|
||||
bb := GetBlockBegin();
|
||||
ee := GetBlockEnd();
|
||||
if FSelectionMode=smLine then
|
||||
if FSelectionMode= smLine then
|
||||
begin
|
||||
bb[1]:= 1;
|
||||
ee[1]:= fLines[ee[0]-1].StrLength()+1;
|
||||
end
|
||||
fUndoList.AddChange(crDelete,bb,ee,GetSelText(),0);
|
||||
buffer_DeleteChars(bb,ee);
|
||||
fUndoList.AddChange(crDelete,bb,ee,GetSelText(),FSelectionMode);
|
||||
buffer_DeleteChars(bb,ee,FSelectionMode);
|
||||
fBlockBegin := fBlockEnd := bb;
|
||||
return bb;
|
||||
end
|
||||
|
|
@ -2422,6 +2409,14 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
if FReadOnly then return;
|
||||
if fcaretcreated then return;
|
||||
h := Font.Height;
|
||||
if FSelectionMode=smColumn then
|
||||
begin
|
||||
if fBlockBegin and fBlockEnd then
|
||||
begin
|
||||
fcaretcout := max(abs(fBlockBegin[0]-fBlockEnd[0])+1,1);
|
||||
if fcaretcout>1 then h := fTextHeight*fcaretcout;
|
||||
end
|
||||
end
|
||||
hd := Handle;
|
||||
_wapi.CreateCaret(hd,nil,1,h);
|
||||
_wapi.ShowCaret(hd);
|
||||
|
|
@ -2439,9 +2434,121 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
end
|
||||
FHasFocus;
|
||||
//buffer 处理
|
||||
function buffer_DeleteChars(bb,ee); //删除选择
|
||||
function buffer_getchars(bb,ee,sm);//获得
|
||||
begin
|
||||
r := "";
|
||||
case FSelectionMode of
|
||||
smLine:
|
||||
begin
|
||||
for i := bb[0] to ee[0] do
|
||||
begin
|
||||
r += fLines[i-1].FStr;
|
||||
r += "\r\n";
|
||||
end
|
||||
end
|
||||
smColumn:
|
||||
begin
|
||||
len := ee[0];
|
||||
a1 := min(bb[1],ee[1]);
|
||||
a2 := max(bb[1],ee[1]);
|
||||
if a1=a2 then return r;
|
||||
for i := bb[0] to ee[0] do
|
||||
begin
|
||||
ri := fLines[i-1].FStr;
|
||||
lri := length(ri);
|
||||
a22 := min(a2-1,lri);
|
||||
if lri then
|
||||
begin
|
||||
if bytetype(ri,a1)=2 then
|
||||
begin
|
||||
a11 := a1+1;
|
||||
end else
|
||||
begin
|
||||
a11 := a1;
|
||||
end
|
||||
if bytetype(ri,a22)=1 then
|
||||
begin
|
||||
a22-=1;
|
||||
end
|
||||
if a11<=a22 then r+=ri[a11:a22];
|
||||
end
|
||||
if i<len then r += "\r\n";
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
if bb[0]=ee[0]then
|
||||
begin
|
||||
s := fLines[bb[0]-1].FStr;
|
||||
if ee[1]>bb[1]and ee[1]>1 then
|
||||
try
|
||||
r := s[bb[1]:ee[1]-1]; //可能出错,添加try
|
||||
except
|
||||
r := "";
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
//第一行
|
||||
s := fLines[bb[0]-1].FStr;
|
||||
if bb[1]<= length(s)then r += s[bb[1]:];
|
||||
r += "\r\n";
|
||||
//中间
|
||||
for i := bb[0]to ee[0]-2 do
|
||||
begin
|
||||
r += fLines[i].FStr;
|
||||
r += "\r\n";
|
||||
end
|
||||
//最后一行
|
||||
s := fLines[ee[0]-1].FStr;
|
||||
if s and ee[1]>1 then r += s[1:ee[1]-1];
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
return r;
|
||||
end
|
||||
function buffer_DeleteChars(bb,ee,sm); //删除选择
|
||||
begin
|
||||
if bb=ee then return;
|
||||
case sm of
|
||||
smLine:
|
||||
begin
|
||||
fLines.splices(bb[0]-1,max(1,ee[0]-bb[0]+1),array());
|
||||
end
|
||||
smColumn:
|
||||
begin
|
||||
a1 := min(bb[1],ee[1]);
|
||||
a2 := max(bb[1],ee[1]);
|
||||
if a1=a2 then return r;
|
||||
for i := bb[0] to ee[0] do
|
||||
begin
|
||||
ri := fLines.GetStringByIndex(i-1);
|
||||
lri := length(ri);
|
||||
a22 := min(a2-1,lri);
|
||||
if lri then
|
||||
begin
|
||||
if bytetype(ri,a1)=2 then
|
||||
begin
|
||||
a11 := a1+1;
|
||||
end else
|
||||
begin
|
||||
a11 := a1;
|
||||
end
|
||||
if bytetype(ri,a22)=1 then
|
||||
begin
|
||||
a22-=1;
|
||||
end
|
||||
if a11<=a22 then
|
||||
begin
|
||||
ri[a11:a22]:="";
|
||||
fLines.SetValueByIndex(i-1,ri);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
smNormal:
|
||||
begin
|
||||
if bb[0]=ee[0]then //删除一行中的
|
||||
begin
|
||||
str := fLines.GetStringByIndex(bb[0]-1);
|
||||
|
|
@ -2460,7 +2567,9 @@ type TCustomMemo = class(TCustomScrollControl,TCustomMemoCmd) //
|
|||
fLines.splices(bb[0],ee[0]-bb[0],array());
|
||||
end
|
||||
end
|
||||
function buffer_InsertChars(cxy,str); //插入
|
||||
end
|
||||
end
|
||||
function buffer_InsertChars(cxy,ee,str,sm); //插入
|
||||
begin
|
||||
if not(ifstring(str)and str)then return;
|
||||
ss := str2array(str,"\n");
|
||||
|
|
|
|||
Loading…
Reference in New Issue