History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: LPP-4015
Type: Improvement Improvement
Status: RetestBranch RetestBranch
Resolution: Fixed
Priority: P0 P0
Assignee: Mamye Kratt
Reporter: Dan Stowell
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
OpenLaszlo

Text selection position and size should be available during onblur event

Created: 21/May/07 03:02 PM   Updated: 09/Aug/07 07:52 PM
Component/s: LFC - Text
Affects Version/s: 3.4, 3.3.3
Fix Version/s: Legals, 4.0.5WaffleCone

Time Tracking:
Not Specified

Severity: Major
Fixed in Change#: 5,717
Runtime: N/A
Flags: Emerald
Fix in hand: False


 Description  « Hide
LzText provides getSelectionSize() and getSelectionPosition() methods for determining which text is selected. If an instance of LzText does not have keyboard focus, calls to these methods will return -1.

When a user clicks a format button (e.g., bold, italic, or underline) while using the rich text editor, the input text field briefly loses keyboard focus. Even before the editor receives an onblur event, calls to getSelectionSize() and getSelectionPosition() return -1 --- the selection information is lost. This information is vital for correctly applying formatting and for restoring the selection when the rich text editor regains focus. We have a workaround that involves hacking the LzModeManager to store the most recent text selection information on every mouseup or mousedown event. Ideally, though, we would be able to rely on the LFC to provide text selection size and position until an input text field has actually lost focus (i.e., after the onblur event has fired), so that we can add the following event handler to the rich text editor:

<handler name="onblur">
    var start = this._field.getSelection.Position();
    var size = this._field.getSelectionSize();
    this._ssel = start;
    this._esel = start + size;
</handler>

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jim Grandy - 21/May/07 03:31 PM
Even more ideally, the format button wouldn't steal focus at all...

Elliot Winard - 16/Jul/07 02:27 PM
need to remove #pragma workaround in our code to run in Legals -
        LzModeManager.rawMouseEvent = function ( eName ) {
            //_root.Debug.warn("rawmouseevent %w", eName);
            //assume this happens before handleMouseEvent though order is
            //not guaranteed
            
            // Store the selection in the currently focused text field
            // (if any). Useful for restoring a text field's selection
            // after a click event.
            var focus = Selection.getFocus();
            if (focus) {
                // focus is a path string - we have to eval() it to get
                // an actual movieclip
                var textclip = eval(focus); // apologies - dstowell
#pragma "warnUndefinedReferences=false"
                // [NB dstowell] __LZrte is a field I created to
                // store a reference to a rich text editor view
                // in the textclip itself. This field is _not_ part
                // of the LFC.
                if (textclip.__LZrte) {
                    var beginIndex = Selection.getBeginIndex();
                    var endIndex = Selection.getEndIndex();
                    if (-1 != beginIndex && -1 != endIndex) {
                        textclip.__LZrte._ssel = beginIndex;
                        textclip.__LZrte._esel = endIndex;
                    }
                }
            }

            this.clickStream.push( this.clstDict[ eName ] );
            //call the cleanup delegate

            this.callNext();
        }

P T Withington - 17/Jul/07 01:12 PM
He's just asking to remove the #pragma. Maybe Phil could dig in to why the #pragma is there and how to silence the warning without the #pragma?

Phil, you should not need a diamond set-up to investigate this, so why don't you take a stab at this right away. I'm assigning it to you for now. Let me know if you need help.


P T Withington - 17/Jul/07 01:42 PM
Ok, I didn't read this carefully enough. I think the issue is an impedence mismatch between the runtime focus and our abstract concept of focus. By the time we send an LZX onblur, the runtime focus has already been lost. Dan's work-around seems reasonable to me and we ought to see about integrating it into the LFC. Basically, if there is an active selection in the runtime when focus changes, we should cache that so we can return that value, at least until we bubble the loss of focus up to the lzx node.

Philip Romanik - 17/Jul/07 02:25 PM
This app demonstrates the problem.

<canvas debug="true">
  <simplelayout axis="y" spacing="20"/>

  <text>Select something in the input text and click the button</text>

  <button>Button
    <method event="onblur">
      Debug.write("button: blur");
    </method>
    <method event="onfocus">
      Debug.write("button: focus");
    </method>
    <method event="onclick">
      Debug.write("button: click");
    </method>
  </button>

  <richinputtext name="editor" width="300" height="200" bgcolor="0xeeeeee">Hello World
    <method event="onblur">
      var start = this.getSelectionPosition();
      var size = this.getSelectionSize();
      Debug.write("richinputtext: blur", start, size);
    </method>
    <method event="onfocus">
      Debug.write("richinputtext: focus");
    </method>
  </richinputtext>

</canvas>


Philip Romanik - 19/Jul/07 11:24 AM
This is a better example app. It shows that richinputtext and inputtext views both work the same way.


<canvas debug="true">
  <simplelayout axis="y" spacing="20"/>

  <text>Select something in the input text and click the button</text>

  <button>Button
    <method event="onblur">
      Debug.write("button: blur");
    </method>
    <method event="onfocus">
      Debug.write("button: focus");
    </method>
    <method event="onclick">
      Debug.write("button: click");
    </method>
  </button>

  <richinputtext name="editor" width="300" height="100" bgcolor="0xeeeeee">Hello World (richinputtext)
    <method event="onblur">
      var start = this.getSelectionPosition();
      var size = this.getSelectionSize();
      Debug.write("richinputtext: blur", start, size);
    </method>
    <method event="onfocus">
      Debug.write("richinputtext: focus");
    </method>
  </richinputtext>

  <inputtext name="ieditor" width="300" height="100" bgcolor="0xeeeeee">Hello World (inputtext)
    <method event="onblur">
      var start = this.getSelectionPosition();
      var size = this.getSelectionSize();
      Debug.write("inputtext: blur", start, size);
    </method>
    <method event="onfocus">
      Debug.write("inputtext: focus");
    </method>
  </inputtext>

</canvas>

Philip Romanik - 19/Jul/07 02:20 PM
Change 20070719-Philip-4 by Philip@Philip-DC on 2007-07-19 14:05:35 EST
   in /cygdrive/f/laszlo/svn/src/svn/openlaszlo/branches/legals
   for http://svn.openlaszlo.org/openlaszlo/branches/legals

Summary: SWF: Text size and position available during onblur

New Features:

Bugs Fixed: LPP-4015

Technical Reviewer: max
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:

LzFocus.lzx
 For the view losing focus, calls preBlur() before the focus change begins,
 and calls postBlur() after the focus has changed.
LaszloView.lzx
 Defined preBlur() and postBlur() methods which are called from LzFocus() at
 the start and end of changing focus from one view to another. The default
 behavior is to set a variable, blurring to true when a view is losing focus.
LzModeManager.as
 rawMouseEvent() caches the current selection (for all text views).
LzTextSprite.as
 Defines _cacheSelection() method for the TextField object to capture the
 position and size of the selection. Modified getSelectionPosition() and
 getSelectionSize() to return the cached values if the view is losing focus.
LzInputTextSprite.as
 Setup cacheSelection method to capture the position and size of selection.


Tests:
See the test case I posted in LPP-4015. When you click the button, the selection
 information from the input box (assuming it had focus) is displayed in the debu
gger.

Files:
M WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
M WEB-INF/lps/lfc/kernel/swf/LzInputTextSprite.as
M WEB-INF/lps/lfc/services/platform/swf/LzModeManager.as
M WEB-INF/lps/lfc/services/LzFocus.lzs
M WEB-INF/lps/lfc/views/LaszloView.lzs

Changeset: http://svn.openlaszlo.org/openlaszlo/patches/20070719-Philip-4.tar

Mamye Kratt - 09/Aug/07 06:48 PM
(wafflecone branch local build r5986)
Fixed in wafflecone.

Mamye Kratt - 09/Aug/07 06:48 PM
Need to test branch.

Mamye Kratt - 09/Aug/07 07:52 PM
Need to re-resolve after problem with jira

Mamye Kratt - 09/Aug/07 07:52 PM
re-close for wafflecone

Mamye Kratt - 09/Aug/07 07:52 PM
Need to test in legals