Merge pull request #1661 from danyaPostfactum/dnd-fixes

Some drag'n'drop fixes
This commit is contained in:
Harutyun Amirjanyan 2013-10-27 00:43:13 -07:00
commit 7d8cd7f657
2 changed files with 24 additions and 20 deletions

View file

@ -118,8 +118,8 @@ function DefaultHandlers(mouseHandler) {
editor.selection.clearSelection(); editor.selection.clearSelection();
} }
}.bind(this), 0); }.bind(this), 0);
if (editor.container.setCapture) { if (editor.renderer.content.setCapture) {
editor.container.setCapture(); editor.renderer.content.setCapture();
} }
editor.setStyle("ace_selecting"); editor.setStyle("ace_selecting");
this.setState("select"); this.setState("select");
@ -185,8 +185,8 @@ function DefaultHandlers(mouseHandler) {
this.selectByWordsEnd = this.selectByWordsEnd =
this.selectByLinesEnd = function() { this.selectByLinesEnd = function() {
this.editor.unsetStyle("ace_selecting"); this.editor.unsetStyle("ace_selecting");
if (this.editor.container.releaseCapture) { if (this.editor.renderer.content.releaseCapture) {
this.editor.container.releaseCapture(); this.editor.renderer.content.releaseCapture();
} }
}; };

View file

@ -43,15 +43,11 @@ function DragdropHandler(mouseHandler) {
var editor = mouseHandler.editor; var editor = mouseHandler.editor;
// Safari accepts either image or element (but it must present in the DOM) var blankImage = dom.createElement("img");
var proxy = dom.createElement("img");
// Safari crashes without image data // Safari crashes without image data
proxy.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
if (useragent.isOpera)
if (useragent.isOpera) { blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;";
proxy.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;visibility:hidden";
editor.container.appendChild(proxy);
}
var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"]; var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"];
@ -66,6 +62,7 @@ function DragdropHandler(mouseHandler) {
var timerId, range; var timerId, range;
var dragCursor, counter = 0; var dragCursor, counter = 0;
var dragOperation; var dragOperation;
var isInternal;
var autoScrollStartTime; var autoScrollStartTime;
var cursorMovedTime; var cursorMovedTime;
var cursorPointOnCaretMoved; var cursorPointOnCaretMoved;
@ -80,26 +77,30 @@ function DragdropHandler(mouseHandler) {
}, 0); }, 0);
return e.preventDefault(); return e.preventDefault();
} }
if (useragent.isOpera) {
proxy.style.visibility = "visible";
setTimeout(function(){
proxy.style.visibility = "hidden";
}, 0);
}
range = editor.getSelectionRange(); range = editor.getSelectionRange();
var dataTransfer = e.dataTransfer; var dataTransfer = e.dataTransfer;
dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove"; dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove";
dataTransfer.setDragImage && dataTransfer.setDragImage(proxy, 0, 0); if (useragent.isOpera) {
editor.container.appendChild(blankImage);
// force layout
blankImage._top = blankImage.offsetTop;
}
dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0);
if (useragent.isOpera) {
editor.container.removeChild(blankImage);
}
// clear Opera garbage // clear Opera garbage
dataTransfer.clearData(); dataTransfer.clearData();
dataTransfer.setData("Text", editor.session.getTextRange()); dataTransfer.setData("Text", editor.session.getTextRange());
isInternal = true;
this.setState("drag"); this.setState("drag");
}; };
this.onDragEnd = function(e) { this.onDragEnd = function(e) {
mouseTarget.draggable = false; mouseTarget.draggable = false;
isInternal = false;
this.setState(null); this.setState(null);
if (!editor.getReadOnly()) { if (!editor.getReadOnly()) {
var dropEffect = e.dataTransfer.dropEffect; var dropEffect = e.dataTransfer.dropEffect;
@ -152,7 +153,6 @@ function DragdropHandler(mouseHandler) {
if (!dragSelectionMarker) if (!dragSelectionMarker)
return; return;
var dataTransfer = e.dataTransfer; var dataTransfer = e.dataTransfer;
var isInternal = this.state == "drag";
if (isInternal) { if (isInternal) {
switch (dragOperation) { switch (dragOperation) {
case "move": case "move":
@ -261,6 +261,8 @@ function DragdropHandler(mouseHandler) {
range = editor.selection.toOrientedRange(); range = editor.selection.toOrientedRange();
dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle()); dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle());
editor.clearSelection(); editor.clearSelection();
if (editor.isFocused())
editor.renderer.$cursorLayer.setBlinking(false);
clearInterval(timerId); clearInterval(timerId);
timerId = setInterval(onDragInterval, 20); timerId = setInterval(onDragInterval, 20);
counter = 0; counter = 0;
@ -274,6 +276,8 @@ function DragdropHandler(mouseHandler) {
editor.$blockScrolling += 1; editor.$blockScrolling += 1;
editor.selection.fromOrientedRange(range); editor.selection.fromOrientedRange(range);
editor.$blockScrolling -= 1; editor.$blockScrolling -= 1;
if (editor.isFocused() && !isInternal)
editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly());
range = null; range = null;
counter = 0; counter = 0;
autoScrollStartTime = null; autoScrollStartTime = null;