Started work on fixing issue 42.
Code's not working as desired, yet. Work in progress. :)
This commit is contained in:
parent
0099165a85
commit
f79e4a3111
3 changed files with 63 additions and 12 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
/* vim:ts=4:sts=4:sw=4:
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
|
@ -658,6 +659,12 @@ var EditSession = function(text, mode) {
|
||||||
return addedRows;
|
return addedRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.moveText = function(range, toPosition) {
|
||||||
|
var removed = this.getTextRange(range);
|
||||||
|
this.doc.remove(range);
|
||||||
|
this.doc.insert(toPosition, removed);
|
||||||
|
};
|
||||||
|
|
||||||
this.$clipRowToDocument = function(row) {
|
this.$clipRowToDocument = function(row) {
|
||||||
return Math.max(0, Math.min(row, this.doc.getLength()-1));
|
return Math.max(0, Math.min(row, this.doc.getLength()-1));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -762,6 +762,13 @@ var Editor =function(renderer, session) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.moveText = function(range, toPosition) {
|
||||||
|
if (this.$readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.session.moveText(range, toPosition);
|
||||||
|
};
|
||||||
|
|
||||||
this.copyLinesUp = function() {
|
this.copyLinesUp = function() {
|
||||||
if (this.$readOnly)
|
if (this.$readOnly)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
/* vim:ts=4:sts=4:sw=4:
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
|
@ -38,6 +39,7 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var event = require("pilot/event");
|
var event = require("pilot/event");
|
||||||
|
var Range = require("ace/range").Range;
|
||||||
|
|
||||||
var MouseHandler = function(editor) {
|
var MouseHandler = function(editor) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
|
|
@ -75,6 +77,8 @@ var MouseHandler = function(editor) {
|
||||||
var pos = editor.renderer.screenToTextCoordinates(pageX, pageY);
|
var pos = editor.renderer.screenToTextCoordinates(pageX, pageY);
|
||||||
pos.row = Math.max(0, Math.min(pos.row, editor.session.getLength()-1));
|
pos.row = Math.max(0, Math.min(pos.row, editor.session.getLength()-1));
|
||||||
|
|
||||||
|
var inSelection = false;
|
||||||
|
|
||||||
var button = event.getButton(e)
|
var button = event.getButton(e)
|
||||||
if (button != 0) {
|
if (button != 0) {
|
||||||
var isEmpty = editor.selection.isEmpty()
|
var isEmpty = editor.selection.isEmpty()
|
||||||
|
|
@ -86,8 +90,10 @@ var MouseHandler = function(editor) {
|
||||||
event.capture(editor.container, function(){}, editor.textInput.onContextMenuClose);
|
event.capture(editor.container, function(){}, editor.textInput.onContextMenuClose);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
} else
|
||||||
|
inSelection = editor.getSelectionRange().contains(pos.row, pos.column);
|
||||||
|
|
||||||
|
if (!inSelection) {
|
||||||
if (e.shiftKey)
|
if (e.shiftKey)
|
||||||
editor.selection.selectToPosition(pos)
|
editor.selection.selectToPosition(pos)
|
||||||
else {
|
else {
|
||||||
|
|
@ -95,6 +101,7 @@ var MouseHandler = function(editor) {
|
||||||
if (!editor.$clickSelection)
|
if (!editor.$clickSelection)
|
||||||
editor.selection.clearSelection(pos.row, pos.column);
|
editor.selection.clearSelection(pos.row, pos.column);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
editor.renderer.scrollCursorIntoView();
|
editor.renderer.scrollCursorIntoView();
|
||||||
|
|
||||||
|
|
@ -111,6 +118,20 @@ var MouseHandler = function(editor) {
|
||||||
self.$clickSelection = null;
|
self.$clickSelection = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var onMouseDragSelectionEnd = function() {
|
||||||
|
clearInterval(timerId);
|
||||||
|
|
||||||
|
var cursor = editor.getCursorPosition();
|
||||||
|
var selection = editor.getSelectionRange();
|
||||||
|
editor.moveText(selection, cursor);
|
||||||
|
|
||||||
|
var rows = selection.end.row - selection.start.row;
|
||||||
|
var columns = selection.end.column - selection.end.column;
|
||||||
|
|
||||||
|
var newSelection = new Range(cursor.row, cursor.column, cursor.row + rows, cursor.column + columns);
|
||||||
|
editor.selection.setSelectionRange(newSelection);
|
||||||
|
};
|
||||||
|
|
||||||
var onSelectionInterval = function() {
|
var onSelectionInterval = function() {
|
||||||
if (mousePageX === undefined || mousePageY === undefined)
|
if (mousePageX === undefined || mousePageY === undefined)
|
||||||
return;
|
return;
|
||||||
|
|
@ -138,8 +159,24 @@ var MouseHandler = function(editor) {
|
||||||
editor.renderer.scrollCursorIntoView();
|
editor.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var onDragSelectionInterval = function() {
|
||||||
|
if (mousePageX === undefined || mousePageY === undefined)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY);
|
||||||
|
cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1));
|
||||||
|
|
||||||
|
editor.moveCursorToPosition(cursor);
|
||||||
|
editor.renderer.scrollCursorIntoView();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (inSelection) {
|
||||||
|
event.capture(editor.container, onMouseSelection, onMouseDragSelectionEnd);
|
||||||
|
var timerId = setInterval(onDragSelectionInterval, 20);
|
||||||
|
} else {
|
||||||
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
||||||
var timerId = setInterval(onSelectionInterval, 20);
|
var timerId = setInterval(onSelectionInterval, 20);
|
||||||
|
}
|
||||||
|
|
||||||
return event.preventDefault(e);
|
return event.preventDefault(e);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue