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

Cutting the widget scrolls editor to the end (with t/468) #1170

Merged
merged 5 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions plugins/widget/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3082,17 +3082,21 @@

function copySingleWidget( widget, isCut ) {
var editor = widget.editor,
doc = editor.document;
doc = editor.document,
isEdge16 = CKEDITOR.env.edge && CKEDITOR.env.version >= 16;

// We're still handling previous copy/cut.
// When keystroke is used to copy/cut this will also prevent
// conflict with copySingleWidget called again for native copy/cut event.
if ( doc.getById( 'cke_copybin' ) )
return;

// [IE] Use span for copybin and its container to avoid bug with expanding editable height by
// absolutely positioned element.
var copybinName = ( editor.blockless || CKEDITOR.env.ie ) ? 'span' : 'div',
// [IE] Use span for copybin and its container to avoid bug with expanding
// editable height by absolutely positioned element.
// For Edge 16+ always use div as span causes scrolling to the end of the document
// on widget cut (also for blockless editor) (#1160).
// Edge 16+ workaround could be safetly removed after #1169 is fixed.
var copybinName = ( ( editor.blockless || CKEDITOR.env.ie ) && !isEdge16 ) ? 'span' : 'div',
copybin = doc.createElement( copybinName ),
copybinContainer = doc.createElement( copybinName ),
// IE8 always jumps to the end of document.
Expand Down
99 changes: 99 additions & 0 deletions tests/plugins/widget/manual/scrolloncut.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<head>
<link rel="stylesheet" href="/apps/ckeditor/contents.css">
</head>

<div>
<h2>Classic</h2>
<hr>
<div id="classic"></div>
</div>

<div>
<h2>Divarea</h2>
<hr>
<div id="divarea"></div>
</div>

<div>
<h2>Inline</h2>
<hr>
<div id="inline" contenteditable="true"></div>
</div>

<div>
<h2>Inline header</h2>
<hr>
<h1 id="inlineheader" contenteditable="true" style="width:500px;">
Apollo 11
<br>
<br>
Apollo 11 was the spaceflight that landed the first humans, Americans Neil Armstrong and Buzz Aldrin, on the Moon on July 20, 1969, at 20:18 UTC. <img height="20" alt="CKEditor logo" src="%BASE_PATH%_assets/logo.png" /> Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.
<br>
<br>
Armstrong spent about three and a half two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&nbsp;kg) of lunar material for return to Earth. A third member of the mission, Michael Collins, piloted the command spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.
<br>
<br>
Broadcasting and quotes
<br>
<br>
Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:
<br>
<br>
"One small step for [a] man, one giant leap for mankind."
<br>
<br>
Apollo 11 effectively ended the Space Race and fulfilled a national goal proposed in 1961 by the late U.S. President John F. Kennedy in a speech before the United States Congress:
<br>
<br>
"[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth."
</h1>
</div>

<div style="display:none;" id="startup-content">
<h1>Apollo 11</h1>

<p>Apollo 11 was the spaceflight that landed the first humans, Americans Neil Armstrong and Buzz Aldrin, on the Moon on July 20, 1969, at 20:18 UTC. <img height="20" alt="CKEditor logo" src="%BASE_PATH%_assets/logo.png" /> Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p>

<figure class="image right"><img alt="CKEditor logo" src="%BASE_PATH%_assets/logo.png" />
<figcaption>CKEditor</figcaption>
</figure>

<p>Armstrong spent about three and a half two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&nbsp;kg) of lunar material for return to Earth. A third member of the mission, Michael Collins, piloted the command spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.</p>

<h2>Broadcasting and quotes</h2>

<p>Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:</p>

<blockquote>
<p>One small step for [a] man, one giant leap for mankind.</p>
</blockquote>

<p>Apollo 11 effectively ended the Space Race and fulfilled a national goal proposed in 1961 by the late U.S. President John F. Kennedy in a speech before the United States Congress:</p>

<blockquote>
<p>[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.</p>
</blockquote>
</div>


<script>
if ( !( CKEDITOR.env.edge && CKEDITOR.env.version >= 16 ) ) {
bender.ignore();
}

var startupContent = document.querySelector( '#startup-content' ).innerHTML;

CKEDITOR.on( 'instanceReady', function( evt ) {
if ( evt.editor.name != 'inlineheader' ) {
evt.editor.setData( startupContent );
}
} );

CKEDITOR.replace( 'classic' );
CKEDITOR.replace( 'divarea', {
extraPlugins: 'divarea'
} );

CKEDITOR.inline( 'inline' );
CKEDITOR.inline( 'inlineheader' );
</script>
14 changes: 14 additions & 0 deletions tests/plugins/widget/manual/scrolloncut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@bender-ui: collapsed
@bender-tags: 4.8.0, 1160, bug
@bender-ckeditor-plugins: wysiwygarea,toolbar,undo,elementspath,clipboard,floatingspace,sourcearea,htmlwriter,image2,format,blockquote

## For each editor instance:

* Select widget inside editor.
* Cut widget (`Ctrl/Cmd + X` or `Cut` button).

### Expected:

Widget is cut. Editor content does not scroll upon cut or scrolls in a way that after widget is removed, caret is still visible near top of the content.