Skip to content

Commit

Permalink
Refactoring: post review corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Jun 8, 2018
1 parent 782a952 commit 913bef2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
6 changes: 3 additions & 3 deletions plugins/autocomplete/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
*
* // Finally, instantiate the autocomplete class.
* new CKEDITOR.plugins.autocomplete( editor, {
* textTestCallback: textTestCallback,
* dataCallback: dataCallback
* } );
* textTestCallback: textTestCallback,
* dataCallback: dataCallback
* } );
* ```
*
* # Changing the behavior of the autocomplete class by subclassing it
Expand Down
46 changes: 34 additions & 12 deletions tests/plugins/textwatcher/manual/throttle.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,57 @@
height: 200px;
overflow-y: auto;
}

#performance-msg {
position: absolute;
top: 20px;
border: 2px solid orange;
color: orange;
background: #111;
padding: 0.3em;
right: 150px;
display: none;
}
</style>
<div id="performance-msg">
Your browser does not have
<var>performance.now()</var>
function. So you have to feel out the timings :(
</div>
<strong>Logger: </strong>
<ul id="logger"></ul>
<div id="editor1" ></div>

<script>
var logger = document.getElementById( 'logger' ),
hasPerformance = window.performance && window.performance.now,
editor = CKEDITOR.replace( 'editor1', {
on: {
instanceReady: function() {
var counter = 0,
counterInterval = 100,

var lastTime = null,
textWatcher = new CKEDITOR.plugins.textWatcher( editor, function( selectionRange ) {
var matchEl = document.createElement( 'li' );
var now = hasPerformance ? performance.now() : null,
matchEl = document.createElement( 'li' );

matchEl.innerText = 'Time: ' + counter + 'ms, Text: ' + selectionRange.startContainer.getText();
logger.appendChild( matchEl );
if ( lastTime === null ) {
lastTime = now;
}

if ( counter == 0 ) {
setInterval( function() {
counter += counterInterval;
}, counterInterval );
}
matchEl.innerText = hasPerformance ? 'Delta: ' + ( now - lastTime ) + 'ms, ' : '';
matchEl.innerText += 'Text: ' + selectionRange.startContainer.getText();
logger.appendChild( matchEl );

}, 2000 );
lastTime = now;

// Throttling set slightly higher than expected due to https://github.com/ckeditor/ckeditor-dev/pull/2001#discussion_r194047585.
}, 2002 );

textWatcher.attach();
}
}
} );

if ( !hasPerformance ) {
CKEDITOR.document.getById( 'performance-msg' ).setStyle( 'display', 'block' );
}
</script>
5 changes: 2 additions & 3 deletions tests/plugins/textwatcher/manual/throttle.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

1. Focus the editor.
1. Start typing `a` constantly.
1. Check log above the editor.
1. Check log above the editor.

## Expected

Typed text should be logged:

1. Immediately after first typed character.
1. Not more often than once every 2000ms.

## Unexpected

Typed text is logged immediately or in invalid interval times.

***Other details*** Measured time by logger can have slight error +/- 100ms.

0 comments on commit 913bef2

Please sign in to comment.