Recent

Author Topic: How to setup keystrokes for MultiCartet plugin  (Read 5107 times)

Pascal

  • Hero Member
  • *****
  • Posts: 919
How to setup keystrokes for MultiCartet plugin
« on: January 20, 2016, 10:32:42 am »
Hello,

how do i setup additional keystrokes (like in the IDE) for the MultiCaret plugin.
i tried the following in the constructor of my TCustomSynedit descendant:
Code: Pascal  [Select][+][-]
  1.   fMultiCaret := TSynPluginMultiCaret.Create(self);
  2.   with fMultiCaret do begin
  3.     with KeyStrokes do begin
  4.       with Add do begin
  5.         Command    := ecPluginMultiCaretSetCaret;
  6.         Key        := VK_INSERT;
  7.         Shift      := [ssShift, ssCtrl];
  8.         ShiftMask  := [ssShift,ssCtrl,ssAlt];
  9.       end;
  10.       with Add do begin
  11.         Command    := ecPluginMultiCaretUnsetCaret;
  12.         Key        := VK_DELETE;
  13.         Shift      := [ssShift, ssCtrl];
  14.         ShiftMask  := [ssShift,ssCtrl,ssAlt];
  15.       end;
  16.     end;
  17.   end;
  18.  
But this doesn't work.

Regards
Pascal
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6819
  • Debugger - SynEdit - and more
    • wiki
Re: How to setup keystrokes for MultiCartet plugin
« Reply #1 on: January 20, 2016, 02:10:56 pm »
As in compiles, but doesnt do anything?

Not sure, looks ok on first sight.

Set breakpoints and see what gets called:

TSynCustomPluginMultiCaret.TranslateKey
"Handled" should be false on enter, and be set to true
Should set "Command" to your command

TSynCustomPluginMultiCaret.ProcessMySynCommand

TSynPluginMultiCaretKeyStrokes.ResetDefaults
must not be called AFTER your setup

madref

  • Hero Member
  • *****
  • Posts: 830
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: How to setup keystrokes for MultiCartet plugin
« Reply #2 on: January 20, 2016, 04:04:28 pm »
Look at this and make it your own.
Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm_Referee.DBGrid_RefereesKeyDown(Sender: TObject; var Key: Word);
  3. begin
  4.   if Key = VK_RETURN then // in LCLType
  5.   begin
  6.     BT_Edit.Click;
  7.     Key := 0;
  8.   end;
  9.   if Key = VK_INSERT then
  10.   begin
  11.     BT_New.Click;
  12.     Key := 0;
  13.   end;
  14. end;     // DBGrid_RefereesKeyDown
  15.  
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.6 / FPC 3.0.4
Lazarus Trunc / FPC Trunc
Mac OS X Mojave

Pascal

  • Hero Member
  • *****
  • Posts: 919
Re: How to setup keystrokes for MultiCartet plugin
« Reply #3 on: January 20, 2016, 09:14:24 pm »
Martin_fr,

TSynCustomPluginMultiCaret.TranslateKey is called but doesn't find any Command.

Function TSynEditKeyStrokes.FindKeycode does not seem to handle ShiftMask right.
The original function subtracts the ShiftMask from the actual ShiftState which is [].

Code: Pascal  [Select][+][-]
  1. function TSynEditKeyStrokes.FindKeycode(Code: word; SS: TShiftState): integer;
  2. var
  3.   x: integer;
  4. begin
  5.   Result := -1;
  6.   for x := 0 to Count-1 do begin
  7.     if (Items[x].Key = Code) and (Items[x].Shift = SS-Items[x].ShiftMask)
  8.     and (Items[x].Key2 = 0) then                     ^
  9.     begin                                            ^
  10.       Result := x;                                   ^
  11.       break;                                         ^
  12.     end;                                             *
  13.   end;
  14. end;
  15.  

If i change the minus to multiply then keystrokes with set ShiftMask will be found and handled!

So this seems to be a BUG. Correct me if i am wrong.

EDIT: This seems to be handled wrong in other places in the unit, too.
« Last Edit: January 20, 2016, 09:27:08 pm by Pascal »
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

Pascal

  • Hero Member
  • *****
  • Posts: 919
Re: How to setup keystrokes for MultiCartet plugin
« Reply #4 on: January 20, 2016, 09:24:45 pm »
BTW

Why does TSynPluginMultiCaretKeyStrokes.ResetDefaults have to call
the inherited ResetDefaults which adds all (105) TSynEditKeyStrokes defaults?
A call to Clear should be enough here, right?

Code: Pascal  [Select][+][-]
  1. procedure TSynPluginMultiCaretKeyStrokes.ResetDefaults;
  2.   procedure AddKey(const ACmd: TSynEditorCommand; const AKey: word;
  3.      const AShift: TShiftState; const AShiftMask: TShiftState = []);
  4.   begin
  5.     with Add do
  6.     begin
  7.       Key       := AKey;
  8.       Shift     := AShift;
  9.       ShiftMask := AShiftMask;
  10.       Command   := ACmd;
  11.     end;
  12.   end;
  13. begin
  14.   inherited ResetDefaults;        <----------------------
  15.   AddKey(ecPluginMultiCaretToggleCaret, VK_SPACE, [ssShift, ssCtrl], [ssShift,ssCtrl,ssAlt]);
  16.   AddKey(ecPluginMultiCaretClearAll, VK_ESCAPE, [ssShift, ssCtrl], [ssShift,ssCtrl,ssAlt]);
  17. end;
  18.  
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6819
  • Debugger - SynEdit - and more
    • wiki
Re: How to setup keystrokes for MultiCartet plugin
« Reply #5 on: January 20, 2016, 09:27:01 pm »
I would expect changing this will then break lots of other code. Starting with the IDE, or anyone else using this.
Not sure this is a good idea now.

Maybe a new alternative method AddFoo() can be added, that handles the mask more correct. Then the old can be deprecated.
In either case I wont have time to look into it now.

Seems that the mask is applied as "ignore those that are in the mask".

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6819
  • Debugger - SynEdit - and more
    • wiki
Re: How to setup keystrokes for MultiCartet plugin
« Reply #6 on: January 20, 2016, 09:27:56 pm »
BTW

Why does TSynPluginMultiCaretKeyStrokes.ResetDefaults have to call
the inherited ResetDefaults which adds all (105) TSynEditKeyStrokes defaults?
A call to Clear should be enough here, right?

report it on mantis please, and I look into it when I have more time

Pascal

  • Hero Member
  • *****
  • Posts: 919
Re: How to setup keystrokes for MultiCartet plugin
« Reply #7 on: January 20, 2016, 11:05:24 pm »
Seems that the mask is applied as "ignore those that are in the mask".

But what is the original intention of ShiftMask?
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6819
  • Debugger - SynEdit - and more
    • wiki
Re: How to setup keystrokes for MultiCartet plugin
« Reply #8 on: January 20, 2016, 11:19:53 pm »
Dont remember, maybe the svn will give a hint.

But even if it was different, it would still break all code that currently uses it.

deprecating the current, and introducing a new mask (and methods/accessors) can avoid breakage or provide at least time to fix dependent code.

So that would be a way to get it fixed.

---
Or ShiftMAsk can be renamed to be IgnoredModifiers.

That is assuming all code uses it that way.
If some code already uses it wrong, it gets really complex.

---
I can only make vague comments right now. I dont have the time to look through all the affected code right now.
« Last Edit: January 20, 2016, 11:22:17 pm by Martin_fr »

Pascal

  • Hero Member
  • *****
  • Posts: 919
Re: How to setup keystrokes for MultiCartet plugin
« Reply #9 on: January 20, 2016, 11:33:04 pm »
i've found a hint:

Code: Pascal  [Select][+][-]
  1. ->  // Modifier keys, that should be ignored
  2.     property ShiftMask: TShiftState read FShiftMask write FShiftMask;
  3.     property ShiftMask2: TShiftState read FShiftMask2 write FShiftMask2;
  4.  

But then TSynPluginMultiCaretKeyStrokes.ResetDefaults has to be changed to:
Code: Pascal  [Select][+][-]
  1. procedure TSynPluginMultiCaretKeyStrokes.ResetDefaults;
  2.   procedure AddKey(const ACmd: TSynEditorCommand; const AKey: word;
  3.      const AShift: TShiftState; const AShiftMask: TShiftState = []);
  4.   begin
  5.     with Add do
  6.     begin
  7.       Key       := AKey;
  8.       Shift     := AShift;
  9.       ShiftMask := AShiftMask;
  10.       Command   := ACmd;
  11.     end;
  12.   end;
  13. begin
  14.   inherited ResetDefaults;
  15.   AddKey(ecPluginMultiCaretToggleCaret, VK_SPACE, [ssShift, ssCtrl], [ssAlt]);  // removed ssShift,ssCtr from ShiftMask
  16.   AddKey(ecPluginMultiCaretClearAll, VK_ESCAPE, [ssShift, ssCtrl], [ssAlt]); // removed ssShift,ssCtr from ShiftMask
  17. end;
  18.  
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6819
  • Debugger - SynEdit - and more
    • wiki
Re: How to setup keystrokes for MultiCartet plugin
« Reply #10 on: January 20, 2016, 11:37:02 pm »
so it is currently used half/half?

report it on mantis. Currently I can't spend time on it. When I have time, I look into it.

Pascal

  • Hero Member
  • *****
  • Posts: 919
Re: How to setup keystrokes for MultiCartet plugin
« Reply #11 on: January 20, 2016, 11:42:45 pm »
Ups ... TSynEditMouseAction handles ShiftMask the other way!!!

Code: Pascal  [Select][+][-]
  1. function TSynEditMouseAction.IsMatchingShiftState(AShift: TShiftState): Boolean;
  2. begin
  3.   Result := AShift * FShiftMask = FShift;
  4. end;
  5.  

This should be made consistent in the future.

I will also report this on mantis.
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6819
  • Debugger - SynEdit - and more
    • wiki
Re: How to setup keystrokes for MultiCartet plugin
« Reply #12 on: January 21, 2016, 01:08:09 am »
thanks, hopefully I ll have some time in a couple of weeks.

ϻαϻɾΣɀО

  • Jr. Member
  • **
  • Posts: 54
  • MaMrEzO
Re: How to setup keystrokes for MultiCartet plugin
« Reply #13 on: June 19, 2016, 12:08:33 am »
Hello,

how do i setup additional keystrokes (like in the IDE) for the MultiCaret plugin.
i tried the following in the constructor of my TCustomSynedit descendant:
Code: Pascal  [Select][+][-]
  1.   fMultiCaret := TSynPluginMultiCaret.Create(self);
  2.   with fMultiCaret do begin
  3.     with KeyStrokes do begin
  4.       with Add do begin
  5.         Command    := ecPluginMultiCaretSetCaret;
  6.         Key        := VK_INSERT;
  7.         Shift      := [ssShift, ssCtrl];
  8.         ShiftMask  := [ssShift,ssCtrl,ssAlt];
  9.       end;
  10.       with Add do begin
  11.         Command    := ecPluginMultiCaretUnsetCaret;
  12.         Key        := VK_DELETE;
  13.         Shift      := [ssShift, ssCtrl];
  14.         ShiftMask  := [ssShift,ssCtrl,ssAlt];
  15.       end;
  16.     end;
  17.   end;
  18.  
But this doesn't work.

Regards
Pascal

Hi
Thanks for your question, Because of show me the way!  ::)
But what you missed is one line :
Code: Pascal  [Select][+][-]
  1.   fMultiCaret := TSynPluginMultiCaret.Create(self);
  2.   with fMultiCaret do begin
  3.     Editor := SynEdit1;//Here what's you missed It's worked for me great.
  4.     with KeyStrokes do begin
  5.       with Add do begin
  6.         Command    := ecPluginMultiCaretSetCaret;
  7.         Key        := VK_INSERT;
  8.         Shift      := [ssShift, ssCtrl];
  9.         ShiftMask  := [ssShift,ssCtrl,ssAlt];
  10.       end;
  11.       with Add do begin
  12.         Command    := ecPluginMultiCaretUnsetCaret;
  13.         Key        := VK_DELETE;
  14.         Shift      := [ssShift, ssCtrl];
  15.         ShiftMask  := [ssShift,ssCtrl,ssAlt];
  16.       end;
  17.     end;
  18.   end;
  19.  
« Last Edit: June 19, 2016, 12:11:41 am by ϻαϻɾΣɀО »
Debio-Sql is a new brand of GUI Database tool for the Firebird RDBMS.
http://debio-sql.ariaian.com/

 

TinyPortal © 2005-2018