Control now unresponsive on Android
Opened this issue · 8 comments
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)
Can you give us a demo project to reproduce this?
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)
Apologies that I cannot attach the project I do have the test Application linked below however that seems to execute the Editor fine.
@jessejiang0214 what are your thoughts?
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
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:
- Clone the project from https://github.com/XAM-Consulting/TEditor
- Edit TEditor.Forms.Samle.Droid Properties
- Click Android Manifest.
- Set Target Android version to 8.0
- 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();
});
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;
}
Can you give me a project which can reproduce this issue?
https://drive.google.com/open?id=1FBxLd_Ch3WBeybHx7mEMcygkGMG1l5hI<- proj
Phone i used is samsung galaxy s6 edge android 7.0