Opened 7 years ago

Closed 6 years ago

#9684 closed Bug (duplicate)

Type error when nothing is selected in checkSelectionChange() (Cannot call method "getType" of null)

Reported by: Jeremie Miserez Owned by:
Priority: Normal Milestone:
Component: General Version: 4.0
Keywords: IBM Cc: jan_wloka@…

Description

Version: 4.x Nightly (Rev. 3952) The call to a.getType() will fail, as the function getSelection(1) can return null.

function b() {
                var a = this.getSelection(1);
                if (a.getType() != CKEDITOR.SELECTION_NONE) {
                    this.fire("selectionCheck", a);
                    var b = this.elementPath();
                    if (!b.compare(this._.selectionPreviousPath)) {
                        this._.selectionPreviousPath = b;
                        this.fire("selectionChange", {selection: a,path: b})
                    }
                }
            }

The corresponding source code would be in: core/selection.js at line 15

function checkSelectionChange() {
		// Editor may have no selection at all.
		var sel = this.getSelection( 1 );
		if ( sel.getType() == CKEDITOR.SELECTION_NONE )
			return;

		this.fire( 'selectionCheck', sel );

		var currentPath = this.elementPath();
		if ( !currentPath.compare( this._.selectionPreviousPath ) ) {
			this._.selectionPreviousPath = currentPath;
			this.fire( 'selectionChange', { selection: sel, path: currentPath } );
		}
	}

Attachments (2)

inlineall2.html (10.0 KB) - added by Jakub Ś 6 years ago.
inlinebycode2.html (6.0 KB) - added by Jakub Ś 6 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by Jeremie Miserez

Note: This also happens after destroying inline editor instances, as the function is called using setTimeout().

comment:2 Changed 7 years ago by Jan Wloka

Cc: jan_wloka@… added

Subscribed.

comment:3 Changed 7 years ago by Jakub Ś

Please provide steps to reproduce this issue in editor.

comment:4 Changed 6 years ago by Jan Wloka

Keywords: IBM added

Changed 6 years ago by Jakub Ś

Attachment: inlineall2.html added

Changed 6 years ago by Jakub Ś

Attachment: inlinebycode2.html added

comment:5 Changed 6 years ago by Jakub Ś

Status: newpending

@jmiserez I have tried to reproduce your problem with two attached samples in latest CKEditor 4.0.1. None of them resulted in error.

  1. Could you attach reduced HTML page with code that shows this problem in editor 4.0.1?
  2. Does this problem occur in editor 4.0.1?
  3. If yes, what are exact steps to get The call to a.getType() will fail ?

comment:6 Changed 6 years ago by Paul Vrugt

I can confirm that this issue occurs when destroying the editor and the function is called using settimeout

comment:7 Changed 6 years ago by Jakub Ś

occurs when destroying the editor and the function is called using

@paulvrugt I may not see the whole picture but when you are destroying editor and then calling its functions then IMO no wonder that there is an error. You can't call functions of non-existing object.

If I have misunderstood you, could you please provide sample page and working showing this problem in code?

comment:8 Changed 6 years ago by Paul Vrugt

You indeed do not see the whole picture here :)

My situation: I am rendering the CKEditor within an aspnet update panel. When i type, the checkselectionchange seems to be fired delayed using settimeouts. (this is not something i wrote, but seems to be default behavior of ckeditor)

The problem is, that when the timer is started, and the updatepanel submits (causing the editor to be destroyed) before the timer is finished, the checkselectionchange function fires for the destroyed editor, causing this issue. Normally this is not a problem since the submit causes the entire page to refresh. But when the editor is in an update panel, the page is persistant, and the error occurs.

I haven't scripted anything against the CKEditor, it is just a default setup.

I think the checkselectionchange function should just check if the "sel" variable is actually filled with a value before calling the getType function, or the destroy function should clear any remaining timeouts when it is called.

I can try to create a sample page demonstrating the problem if the issue is still not clear

comment:9 Changed 6 years ago by Jakub Ś

I can try to create a sample page demonstrating the problem if the issue is still not clear

What you say is very clear, it would be nice however if you could send us sample code showing this problem.

comment:10 Changed 6 years ago by Piotrek Koszuliński

Resolution: duplicate
Status: pendingclosed

This issue is a duplicate of #10219 which already has milestone, so I'm closing this issue and moving TCs there.

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy