Recent

Author Topic: How to prevent caret moving when selecting text with the mouse  (Read 2349 times)

rgeorge7

  • Newbie
  • Posts: 4
How to prevent caret moving when selecting text with the mouse
« on: February 05, 2016, 04:07:45 am »
I am wanting to be able to select text with the mouse without the caret moving from the current position.  I tried leaving the MoveCaret property as false in a MouseAction but it doesn't seem to do anything.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9864
  • Debugger - SynEdit - and more
    • wiki
Re: How to prevent caret moving when selecting text with the mouse
« Reply #1 on: February 05, 2016, 04:38:14 am »
In SynEdit the caret always has to be at one end of the selection. And that is always the end of the selection that gets changed.
(One end of the selection gets fixed (to where the caret originally was), the other end follows the caret (the mouse moves the caret))

You may be able to set them separate by code. But then (if that works) you have to write your own mouse button/move handler.

Actually the caret can move away from the selection, if you enable persistent selection. But the caret is still used to create the selection.

But if you remove any mouseaction from the button, and do your own code, it MIGHT be possible.

rgeorge7

  • Newbie
  • Posts: 4
Re: How to prevent caret moving when selecting text with the mouse
« Reply #2 on: February 05, 2016, 07:15:51 am »
Thanks.  I might try to create a mouse handler.  Can you also explain how the MoveCaret option works?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9864
  • Debugger - SynEdit - and more
    • wiki
Re: How to prevent caret moving when selecting text with the mouse
« Reply #3 on: February 05, 2016, 04:30:48 pm »
The "MoveCaret" depends on the assigned action.

Some actions have "build in" caret move. Then it does nothing. For other actions (e.g. context menu) it triggers an additional move.

See TCustomSynEdit.DoHandleMouseAction search the variable CaretDone and AnInfo.CaretDone.


To do what you want, you may need to set eoPersistentCaret in Options. That also prevents caret movement from clearing the selection.

Otherwise you may need to inherit SynEdit and get access to
FBlockSelection, via property SelectionObj: TSynEditSelection
Then call IgnoreNextCaretMove before you set the caret.



 

TinyPortal © 2005-2018