paste handler no longer causes fast viewport shift when pasting

This commit is contained in:
christian 2012-02-08 23:37:52 +00:00
parent 13921a0468
commit f84fc1cbf1
Notes: Gabriel Wicke 2012-02-27 16:40:01 +00:00
2 changed files with 3 additions and 7 deletions

View file

@ -157,6 +157,6 @@ include( '../../modules/sandbox/base.php' );
<!-- sandbox -->
<script src="main.js"></script>
<div id="paste" contenteditable="true" style="height: 1px; width: 1px; position: absolute; left: -20000px;"></div>
<div id="paste" contenteditable="true" style="height: 1px; width: 1px; display: none; opacity: 0; position: absolute;"></div>
</body>
</html>

View file

@ -55,19 +55,15 @@ ve.es.Surface = function( $container, model ) {
var insertionPoint = _this.getSelection().start;
console.log(_this.clipboard);
var scrollTop = $(window).scrollTop();
$('#paste').html('');
$('#paste').focus();
$('#paste').html('').show().css('top', $(window).scrollTop()).css('left', $(window).scrollLeft()).focus();
setTimeout(function() {
var key = $('#paste').text().replace(/( |\r\n|\n|\r|\t)/gm,"");
var key = $('#paste').hide().text().replace(/( |\r\n|\n|\r|\t)/gm,"");
if (_this.clipboard[key]) {
var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.clipboard[key]);
_this.documentView.model.commit(tx);
_this.showCursorAt(insertionPoint + _this.clipboard[key].length);
$(window).scrollTop(scrollTop);
} else {
alert('i can only handle copy/paste from hybrid surface. sorry. :(');
}