Skip to content

Cannot delete paragraph before and after a widget / Delete space above widget #1572

Closed
@HarryMuc

Description

Are you reporting a feature request or a bug?

The old issues
"Cannot delete paragraph before and after a widget"
"Delete space above widget"
are still not fixed

Check if the issue is already reported

https://dev.ckeditor.com/ticket/12778
https://dev.ckeditor.com/ticket/13864

Provide detailed reproduction steps (if any)

Just open this page:
https://sdk.ckeditor.com/samples/simplebox.html

Paste this Code:

<h1>&nbsp;</h1>
<div class="simplebox align-center" style="width:750px">
<h2 class="simplebox-title">Title</h2>
<div class="simplebox-content">
<p>Foo <strong>bar</strong>.</p>
<ul>
	<li>Foo!</li>
	<li>Bar!</li>
</ul>
</div>
</div>
<p>&nbsp;</p>
<div class="simplebox align-center" style="width:750px">
<h2 class="simplebox-title">Title</h2>
<div class="simplebox-content">
<p>Foo <strong>bar</strong>.</p>
<ul>
	<li>Foo!</li>
	<li>Bar!</li>
</ul>
</div>
</div>
<p>&nbsp;</p>

And try to delete the paragraphs before, between and after the widgets - not possible!

Expected result

The paragraphs should be deletable

Actual result

Paragraphs are not deleted

Other details

Plase check my workaround in core/selection.js:

	// Handle left, right, delete and backspace keystrokes next to non-editable elements
	// by faking selection on them.
	function getOnKeyDownListener( editor ) {
		var keystrokes = { 37: 1, 39: 1, 8: 1, 46: 1 };

		return function( evt ) {
			var keystroke = evt.data.getKeystroke();

			// Handle only left/right/del/bspace keys.
			if ( !keystrokes[ keystroke ] )
				return;

			var sel = editor.getSelection(),
				ranges = sel.getRanges(),
				range = ranges[ 0 ];

			// Handle only single range and it has to be collapsed.
			if ( ranges.length != 1 || !range.collapsed )
				return;

			var next = range[ keystroke < 38 ? 'getPreviousEditableNode' : 'getNextEditableNode' ]();

			if ( next && next.type == CKEDITOR.NODE_ELEMENT && next.getAttribute( 'contenteditable' ) == 'false' ) {
				/* $custom: added if case to allow removal of empty paragraphs, see incidents
					https://dev.ckeditor.com/ticket/12778
					https://dev.ckeditor.com/ticket/13864 */
				if(sel._ && sel._.cache && sel._.cache.nativeSel && sel._.cache.nativeSel.baseNode && sel._.cache.nativeSel.baseNode.nodeName === 'P'){
					range.endContainer.$.remove();
				} else {
					editor.getSelection().fake( next );
					evt.data.preventDefault();
					evt.cancel();
				}
			}
		};
	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

status:confirmedAn issue confirmed by the development team.supportAn issue reported by a commercially licensed client.type:bugA bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions