| [news.eclipse.platform.swt] Re: Bug in Text.setSelection? |
In my case, the text window is read-only, so this isn't a problem.
Doug
Bob Foster wrote:
And what happens when the user sets the caret one character before the end of the visible text and types two characters?
Bob
Doug Pearson wrote:
Hi Steve,
I tried your suggestion and indeed you are correct sir -- the control scrolls anyway, so changing the API would have no effect (at least on Windows).
Fortunately, in tinkering I found a workaround. Turning off redraw while moving the selection prevents the scroll from happening. It does result in a flicker (as the control is repainted when turning redraw back on) but at least the functionality is there.
Thanks for your input,
Doug
Steve Northover wrote:
All of the setSelection() methods in SWT, in addition to setting the
selection, scroll or do whatever work is necessary to bring the selection to
the attention of the user. So, to get what you want would requre new API.
However, I believe that (due to a bug in Windows), the EM_SCROLLCARET is not
necessary and that the text control will scroll anyways. Try commenting the
line out and see if it doesn't scroll.
"Doug Pearson" <doug-list@xxxxxxxxxxxxxx> wrote in message news:d9d85q$120$1@xxxxxxxxxxxxxxxxxxx
The code for the Text widget's set selection on Windows looks like this:
public void setSelection (int start) { checkWidget (); if (OS.IsDBLocale) start = wcsToMbcsPos (start); OS.SendMessage (handle, OS.EM_SETSEL, start, start); OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); }
I'm looking to implement a common pattern with a text widget, where if the user has set the caret to a position other than the end of the widget the window doesn't scroll as new text is added.
The underlying control supports this but because of the call to
"EM_SCROLLCARET" in this method I don't think it's possible to implement
this in SWT. (You need to move the selection to add text to the end of
the control and then move it back).
This scroll caret call seems clearly unnecessary as there's a separate showSelection() method:
public void showSelection () { checkWidget (); OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); }
so if you want the scroll behavior you can call this method.
So my question is simple: is there any reason not to treat this as a bug
or shall I go ahead and write it up?
Thanks,
Doug