press a line 2 spaces to the right (or left)
Posted: Sun Feb 28, 2016 3:56 pm
In Delphi editor I find it quite pleasant to press the (highlighted) line 2 spaces to the right (Ctrl+k i ) and 2 spaces to
the left (Ctrl+k u).
I have both implemented for TRichViewEdit about ctrl+spacebar and shift+spacebar.
When I move the (unmarked) line 2 places to the left (cursor stands at the beginning of a memoline - using shift+spacebar)
it bothers me that I can see that a space is inserted before line is going 2 spaces to the left.
I can't prevent that space character is being inserted. I have tried many things (key: = 0 - KeyPreview:= true -
form1.keyUp ...).
Does anyone know a solution that I can't see that a space is inserted before line is going 2 spaces to the left) ?
memo: TRichViewEdit;
memo.Options.rvoShowSpecialCharacters:= true; //damit man die Leerzeichen sieht
procedure TForm1.memoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var memopos: integer;
begin
if (ssCtrl in Shift) and (key= 32) then begin
try
LockWindowUpdate(form1.Handle); //#32 wird 2x eingefügt:
memoPos:=RVGetLinearCaretPos(memo); //1. durch key= 32 und
memo.InsertText(#32); //2. durch memo.InsertText
Application.ProcessMessages; //MUSS sein
memo.selectCurrentword;
RVSetLinearCaretPos(memo,memopos); //Cursor wieder an Ausgangsposition
finally
LockWindowUpdate(0);
end;
end;
end;
procedure TForm1.memoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (ssShift in Shift) and (key= 32) then begin
try //1 Space wurde zuvor durch
memoPos:=RVGetLinearCaretPos(memo)-1; //key= 32 eingefügt - egal was ich
ausprobiert habe
LockWindowUpdate(form1.Handle);
RVSetSelection(memo,memopos, 3);
if memo.GetSelText= #32#32#32 then RVSetSelection(memo,memopos, 3) //eingefügtes + 2 weitere Leerzeichen
else if pos(#32#32,memo.GetSelText)= 1 then RVSetSelection(memo,memopos, 2)
else if pos(#32,memo.GetSelText)= 1 then RVSetSelection(memo,memopos, 1)
else exit;
Application.ProcessMessages; //MUSS sein
memo.deleteSelection;
RVSetLinearCaretPos(memo,memoPos);
finally
LockWindowUpdate(0);
end;
end;
end;
the left (Ctrl+k u).
I have both implemented for TRichViewEdit about ctrl+spacebar and shift+spacebar.
When I move the (unmarked) line 2 places to the left (cursor stands at the beginning of a memoline - using shift+spacebar)
it bothers me that I can see that a space is inserted before line is going 2 spaces to the left.
I can't prevent that space character is being inserted. I have tried many things (key: = 0 - KeyPreview:= true -
form1.keyUp ...).
Does anyone know a solution that I can't see that a space is inserted before line is going 2 spaces to the left) ?
memo: TRichViewEdit;
memo.Options.rvoShowSpecialCharacters:= true; //damit man die Leerzeichen sieht
procedure TForm1.memoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var memopos: integer;
begin
if (ssCtrl in Shift) and (key= 32) then begin
try
LockWindowUpdate(form1.Handle); //#32 wird 2x eingefügt:
memoPos:=RVGetLinearCaretPos(memo); //1. durch key= 32 und
memo.InsertText(#32); //2. durch memo.InsertText
Application.ProcessMessages; //MUSS sein
memo.selectCurrentword;
RVSetLinearCaretPos(memo,memopos); //Cursor wieder an Ausgangsposition
finally
LockWindowUpdate(0);
end;
end;
end;
procedure TForm1.memoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (ssShift in Shift) and (key= 32) then begin
try //1 Space wurde zuvor durch
memoPos:=RVGetLinearCaretPos(memo)-1; //key= 32 eingefügt - egal was ich
ausprobiert habe
LockWindowUpdate(form1.Handle);
RVSetSelection(memo,memopos, 3);
if memo.GetSelText= #32#32#32 then RVSetSelection(memo,memopos, 3) //eingefügtes + 2 weitere Leerzeichen
else if pos(#32#32,memo.GetSelText)= 1 then RVSetSelection(memo,memopos, 2)
else if pos(#32,memo.GetSelText)= 1 then RVSetSelection(memo,memopos, 1)
else exit;
Application.ProcessMessages; //MUSS sein
memo.deleteSelection;
RVSetLinearCaretPos(memo,memoPos);
finally
LockWindowUpdate(0);
end;
end;
end;