Recent

Author Topic: [SOLVED] Scroll to position/caret in RichMemo?  (Read 8629 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
[SOLVED] Scroll to position/caret in RichMemo?
« on: March 20, 2016, 09:23:14 pm »
I'm beating my head over this one.

I've implemented a search, and need to scroll the richmemo to the selection, I've tried everything I can think of and then some, but can't get it working.

I'm on OSX, Lazarus 1.6

I've tried just setting the selection, selstart/sellength, vertscrollbar, etc. and no go.

I'm getting the position with PosEx(), but I've also tried Search() with which I get no hits at all.

Any ideas?
« Last Edit: March 23, 2016, 03:57:05 pm by Trenatos »

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #1 on: March 21, 2016, 12:04:23 am »
I've tested on a windows machine, where using .Search and setting the SelStart seems to do what I need, but no such luck on Mac, where the .Search always keeps returning -1, and SelStart doesn't seem to scroll.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Scroll to position/caret in RichMemo?
« Reply #2 on: March 22, 2016, 12:14:47 am »
Carbon or Cocoa?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #3 on: March 22, 2016, 01:30:44 pm »
Carbon

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Scroll to position/caret in RichMemo?
« Reply #4 on: March 22, 2016, 02:37:08 pm »
If you've an opportunity could please test if TMemo behaves in the similar (inconsistent) way?

Where setting SelStart in Windows would scroll to selection, while it should not scroll in Carbon?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #5 on: March 22, 2016, 02:53:04 pm »
Sure I can test that

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #6 on: March 22, 2016, 06:45:09 pm »
I just tested, and it's the same behavior.

Tested on Windows 7, and El Capitan, Lazarus 1.6.

Mac uses Carbon.

TMemo and RichMemo act the same, EG. SelStart works on Windows but does not scroll on Mac.

Here's the code I used:

Code: Pascal  [Select]
  1. var
  2.   count, match: Integer;
  3. begin
  4.         for count := 1 to 300 do
  5.   begin
  6.     Memo1.Lines.Add('Line ' + IntToStr(count));
  7.   end;
  8.   match := PosEx('Line 200', Memo1.Text);
  9.   Memo1.SelStart := match;
  10. end;

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #7 on: March 22, 2016, 06:50:58 pm »
I have no preference myself as for Carbon vs Cocoa, I just use what was defaulted after installing Lazarus.

--edit
I just tried setting and building for Cocoa, and got an error on RichMemo:

cocoarichmemo.pas(533,32) Error: Identifier not found "taLeft"
« Last Edit: March 22, 2016, 06:53:09 pm by Trenatos »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Scroll to position/caret in RichMemo?
« Reply #8 on: March 22, 2016, 06:58:46 pm »
TMemo and RichMemo act the same, EG. SelStart works on Windows but does not scroll on Mac.
It looks like the fix should come to Carbon, rather than RichMemo itself.
SelStart should trigger scrolling.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #9 on: March 22, 2016, 08:05:36 pm »
I've no idea what to do with that information.

I'm not involved in the Mac dev community, nor have any idea who to talk to or what/where to submit an error report if this is a Carbon issue.

I assume then that there are no workarounds either?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: Scroll to position/caret in RichMemo?
« Reply #10 on: March 23, 2016, 03:10:15 am »
I assume then that there are no workarounds either?
why? there's one!

Here're steps:
1) you'll need to get the latest RichMemo revision r4584.
2) open compiler options of the package. (in Lazarus IDE select Packages -> Open Recent Package ... -> pick richmemo. In the openned dialog click on "Options" button)
3) in "Custom Options" of the package compiler options add the following line "-dRMCARBONSELSTART" (as shown on the screenshot).
4) recompile the package and recompile the project.

These steps should take care of the issue when changing SelStart doesn't trigger  scrolling.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: Scroll to position/caret in RichMemo?
« Reply #11 on: March 23, 2016, 03:53:40 pm »
I grabbed the latest build off of svn, followed your steps, and it works beautifully, big thanks!

What does that flag do?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: [SOLVED] Scroll to position/caret in RichMemo?
« Reply #12 on: March 23, 2016, 05:10:22 pm »
That flag enables the code in RichMemo to adjust the scroll towards the selstart set.
The fix however should be (and will be) applied in LCL. But it would force you to use Lazarus trunk. (Which you might not want in some cases).

So for now, you need to use the flag.

I'll also research why Search() doesn't work for you. As well as will fix cocoa compilation

« Last Edit: March 23, 2016, 05:12:52 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: [SOLVED] Scroll to position/caret in RichMemo?
« Reply #13 on: March 23, 2016, 06:00:41 pm »
Aha ok, I understand, thanks a whole bunch for the fix.

I'll post some test/example code for the Search when I get a chance (Probably tonight or tomorrow).

Trenatos

  • Hero Member
  • *****
  • Posts: 508
  • Software developer - Open source contributor
    • MarcusFernstrom.com
Re: [SOLVED] Scroll to position/caret in RichMemo?
« Reply #14 on: March 24, 2016, 01:45:34 am »
Not much needed to test the Search()

Same code as the earlier post, just replacing PosEx with this line, and does not work.

match := RichMemo1.Search('Line 200', 0, Length(RichMemo1.Text), []);

match is -1

Again, thanks, Skalogryz for looking into this stuff for me, I appreciate it