Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control now unresponsive on Android #20

Open
Jhanbury opened this issue Oct 12, 2017 · 8 comments
Open

Control now unresponsive on Android #20

Jhanbury opened this issue Oct 12, 2017 · 8 comments

Comments

@Jhanbury
Copy link

I have been testing out your control and it worked fine in the beginning, however now on android it is unresponsive.

When I exit the app and check my output i see the same error spammed a couple of hundred times:

"Uncaught IndexSizeError: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.", source: http://www.xam-consulting.com/ (940)

@jessejiang0214
Copy link
Contributor

Can you give us a demo project to reproduce this?

@Jhanbury
Copy link
Author

So this is very strange @jessejiang0214

I created a sample app and no problems.

So I then decided to test TEditor in an existing project which was roughly the same size as the project i was having the issue in and the issue reproduced.

11-10 09:44:12.407 I/chromium(28248): [INFO:CONSOLE(940)] "Uncaught IndexSizeError: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.", source: http://www.xam-consulting.com/ (940)
11-10 09:44:12.408 I/WebView (28248): Uncaught IndexSizeError: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.

I ran the project in Xamarin Profiler and here is what happened when I ran TEditor in the app

(Red Box highlights TEditor interaction)

image

Apologies that I cannot attach the project I do have the test Application linked below however that seems to execute the Editor fine.

Sample

@Jhanbury
Copy link
Author

@jessejiang0214 what are your thoughts?

@jessejiang0214
Copy link
Contributor

If the demo App caonnot reproduce, I guess most reason is Android memory issue, maybe Android raise a GC and this error comes. Maybe you can try increase Android heap size, or GC before use TEditor

@gidgol
Copy link

gidgol commented Feb 5, 2018

This is just to fix Uncaught IndexSizeError: Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index
in ZSSRichTextEditor.js -> getCaretYPosition() method replace
var range = = sel.getRangeAt(0);
with

var `range;`
 if (sel.rangeCount > 0) {
        range = sel.getRangeAt(0);
    }

**But the problem is bigger.
This bug can be reproduced easy just fallow this steps:

  1. Clone the project from https://github.com/XAM-Consulting/TEditor
  2. Edit TEditor.Forms.Samle.Droid Properties
  3. Click Android Manifest.
  4. Set Target Android version to 8.0
  5. Compile. When you open the editor and tap to start writing it will not be responsible.**

ZSSRichTextEditor.js i am not sure why but when you click on the editor this event triggers constantly like in inifnity loop. I will write here if i find a wat to fix this issue.

$(document).on('selectionchange',function(e){
                   zss_editor.calculateEditorHeightWithCaretPosition();
                   zss_editor.setScrollPosition();
                   });

@gidgol
Copy link

gidgol commented Feb 5, 2018

My guess that the problem come from here(i've added the sel.rangeCount check)

zss_editor.getCaretYPosition = function() {
    var sel = window.getSelection();
    // Next line is comented to prevent deselecting selection. It looks like work but if there are any issues will appear then uconmment it as well as code above.
    //sel.collapseToStart();
    var range;
    if (sel.rangeCount > 0) {
        range = sel.getRangeAt(0);
    }
    var span = document.createElement('span');// something happening here preventing selection of elements
    range.collapse(false);
    range.insertNode(span);
    span.parentNode.removeChild(span); 

    var topPosition = span.offsetTop;
    return topPosition;
}

This should fix this bug:

zss_editor.getCaretYPosition = function() {
    var sel = window.getSelection();
    var topPosition;
    var range;
    
    if (sel.rangeCount > 0) {
        range = sel.getRangeAt(0);
        topPosition = range.getBoundingClientRect().top;
    }

    return topPosition;
}

@jessejiang0214
Copy link
Contributor

Can you give me a project which can reproduce this issue?

@gidgol
Copy link

gidgol commented Apr 20, 2018

https://drive.google.com/open?id=1FBxLd_Ch3WBeybHx7mEMcygkGMG1l5hI<- proj
Phone i used is samsung galaxy s6 edge android 7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants