If I stand in the top row (in any cell) of a rv-table and press cursor up, the care leaves table and stands in the memo line just above the table.
I don't want this behavior. I wish that the cursor does not leave the table.
Just the same with the last (written) row. If I click the cursor down, caret leaves table.
This behavior is most provoking.
To leave rv-table, user has to press a shortcut (or something else).
Jürgen
caret leaves rv-table by pressing cursor up or down
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
The code below block UP key in the first line of the first row cells, and DOWN key in the last line of the last row cells.
You may wish also block Ctrl+Home and Ctrl+End.
You may wish also block Ctrl+Home and Ctrl+End.
Code: Select all
uses RVTInplace;
function IsInFirstLine(rve: TCustomRichViewEdit): Boolean;
var DItemNo, DOffs, i: Integer;
begin
rve.RVData.Item2DrawItem(rve.CurItemNo, rve.OffsetInCurItem, DItemNo, DOffs);
Result := False;
for i := 0 to rve.RVData.DrawItems.Count-1 do begin
if ((i>0) and rve.RVData.DrawItems[i].FromNewLine) then
break;
if i=DItemNo then begin
Result := True;
exit;
end;
end;
end;
function IsInLastLine(rve: TCustomRichViewEdit): Boolean;
var DItemNo, DOffs, i: Integer;
begin
rve.RVData.Item2DrawItem(rve.CurItemNo, rve.OffsetInCurItem, DItemNo, DOffs);
Result := False;
for i := rve.RVData.DrawItems.Count-1 downto 0 do begin
if i=DItemNo then begin
Result := True;
exit;
end;
if rve.RVData.DrawItems[i].FromNewLine then
break;
end;
end;
procedure TForm3.RichViewEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var Cell: TRVTableCellData;
Table: TRVTableItemInfo;
r: Integer;
begin
if (Key<>VK_UP) and (Key<>VK_DOWN) then
exit;
if RichViewEdit1.InplaceEditor=nil then
exit; // not in cell
Cell := TRVTableInplaceEdit(RichViewEdit1.InplaceEditor).FCell;
Table := Cell.GetTable;
r := TRVTableInplaceEdit(RichViewEdit1.InplaceEditor).FRow;
if ((Key=VK_UP) and (r=0) and IsInFirstLine(RichViewEdit1.TopLevelEditor)) or
((Key=VK_DOWN) and (r=Table.RowCount-1) and IsInLastLine(RichViewEdit1.TopLevelEditor)) then
Key := 0;
end;
I had forgotten vk_left + vk_Right. I hope you agree:
if key= ...
...
end else if (key=vk_down) or (Key=VK_up) or (Key=VK_Left) or (Key=VK_Right) then begin
if memo.InplaceEditor=nil then exit; // not in cell
Cell := TRVTableInplaceEdit(memo.InplaceEditor).FCell;
Table := Cell.GetTable;
r := TRVTableInplaceEdit(memo.InplaceEditor).FRow;
c := TRVTableInplaceEdit(memo.InplaceEditor).FCol;
if ((Key=VK_UP) and (r=0) and IsInFirstLine(memo.TopLevelEditor)) or
((Key=VK_DOWN) and (r=Table.RowCount-1) and IsInLastLine(memo.TopLevelEditor)) or
((Key=VK_Left) and (c=0) and IsInFirstLine(memo.TopLevelEditor)) or
((Key=VK_Right) and (c=Table.ColCount-1) and IsInLastLine(memo.TopLevelEditor)) then Key := 0;
if key= ...
...
end else if (key=vk_down) or (Key=VK_up) or (Key=VK_Left) or (Key=VK_Right) then begin
if memo.InplaceEditor=nil then exit; // not in cell
Cell := TRVTableInplaceEdit(memo.InplaceEditor).FCell;
Table := Cell.GetTable;
r := TRVTableInplaceEdit(memo.InplaceEditor).FRow;
c := TRVTableInplaceEdit(memo.InplaceEditor).FCol;
if ((Key=VK_UP) and (r=0) and IsInFirstLine(memo.TopLevelEditor)) or
((Key=VK_DOWN) and (r=Table.RowCount-1) and IsInLastLine(memo.TopLevelEditor)) or
((Key=VK_Left) and (c=0) and IsInFirstLine(memo.TopLevelEditor)) or
((Key=VK_Right) and (c=Table.ColCount-1) and IsInLastLine(memo.TopLevelEditor)) then Key := 0;
Oh,
if I have a word in the first cell and caret stands at the end of this word I can't go by vk_left to the begining of the word.
My wish: I don't want to leave rve-table by pressing vk_left (and vk_right).
Do you have a solution ?
This runs, but is not the optimal solution:
...
((Key=VK_Right) and (c=Table.ColCount-1) and IsInLastLine(memo.TopLevelEditor)) then begin
IF Key=VK_Left then KEY:=VK_Home
else IF Key=VK_Right then KEY:=VK_End
ELSE key:= 0;
exit;
end;
if I have a word in the first cell and caret stands at the end of this word I can't go by vk_left to the begining of the word.
My wish: I don't want to leave rve-table by pressing vk_left (and vk_right).
Do you have a solution ?
This runs, but is not the optimal solution:
...
((Key=VK_Right) and (c=Table.ColCount-1) and IsInLastLine(memo.TopLevelEditor)) then begin
IF Key=VK_Left then KEY:=VK_Home
else IF Key=VK_Right then KEY:=VK_End
ELSE key:= 0;
exit;
end;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
function IsAtTheBeginning(rve: TCustomRichViewEdit): Boolean;
begin
Result := (rve.CurItemNo=0) or
((rve.CurItemNo=1) and (rve.GetItemStyle(0)=rvsListMarker));
Result := Result and (rve.OffsetInCurItem<=rve.GetOffsBeforeItem(rve.CurItemNo));
end;
function IsAtTheEnd(rve: TCustomRichViewEdit): Boolean;
begin
Result := (rve.CurItemNo=rve.ItemCount-1) and
(rve.OffsetInCurItem>=rve.GetOffsAfterItem(rve.CurItemNo));
end;
...
if ((Key=VK_UP) and (r=0) and IsInFirstLine(memo.TopLevelEditor)) or
((Key=VK_DOWN) and (r=Table.RowCount-1) and IsInLastLine(memo.TopLevelEditor)) or
((Key=VK_LEFT) and (c=0) and IsAtTheBeginning(memo.TopLevelEditor)) or
((Key=VK_Right) and (c=Table.ColCount-1) and IsAtTheEnd(memo.TopLevelEditor)) then
Key := 0