caret leaves rv-table by pressing cursor up or down

General TRichView support forum. Please post your questions here
Post Reply
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

caret leaves rv-table by pressing cursor up or down

Post by j&b »

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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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.

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;
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

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;
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

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;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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
PS: typed in browser, so misprints are possible
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

THANKS ...
Post Reply