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
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
|
|
@ -658,6 +659,12 @@ var EditSession = function(text, mode) {
|
|||
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) {
|
||||
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() {
|
||||
if (this.$readOnly)
|
||||
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
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
define(function(require, exports, module) {
|
||||
|
||||
var event = require("pilot/event");
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
var MouseHandler = function(editor) {
|
||||
this.editor = editor;
|
||||
|
|
@ -74,6 +76,8 @@ var MouseHandler = function(editor) {
|
|||
|
||||
var pos = editor.renderer.screenToTextCoordinates(pageX, pageY);
|
||||
pos.row = Math.max(0, Math.min(pos.row, editor.session.getLength()-1));
|
||||
|
||||
var inSelection = false;
|
||||
|
||||
var button = event.getButton(e)
|
||||
if (button != 0) {
|
||||
|
|
@ -86,16 +90,19 @@ var MouseHandler = function(editor) {
|
|||
event.capture(editor.container, function(){}, editor.textInput.onContextMenuClose);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else
|
||||
inSelection = editor.getSelectionRange().contains(pos.row, pos.column);
|
||||
|
||||
if (e.shiftKey)
|
||||
editor.selection.selectToPosition(pos)
|
||||
else {
|
||||
editor.moveCursorToPosition(pos);
|
||||
if (!editor.$clickSelection)
|
||||
editor.selection.clearSelection(pos.row, pos.column);
|
||||
if (!inSelection) {
|
||||
if (e.shiftKey)
|
||||
editor.selection.selectToPosition(pos)
|
||||
else {
|
||||
editor.moveCursorToPosition(pos);
|
||||
if (!editor.$clickSelection)
|
||||
editor.selection.clearSelection(pos.row, pos.column);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
editor.renderer.scrollCursorIntoView();
|
||||
|
||||
var self = this;
|
||||
|
|
@ -110,6 +117,20 @@ var MouseHandler = function(editor) {
|
|||
clearInterval(timerId);
|
||||
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() {
|
||||
if (mousePageX === undefined || mousePageY === undefined)
|
||||
|
|
@ -137,9 +158,25 @@ var MouseHandler = function(editor) {
|
|||
|
||||
editor.renderer.scrollCursorIntoView();
|
||||
};
|
||||
|
||||
var onDragSelectionInterval = function() {
|
||||
if (mousePageX === undefined || mousePageY === undefined)
|
||||
return;
|
||||
|
||||
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
||||
var timerId = setInterval(onSelectionInterval, 20);
|
||||
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);
|
||||
var timerId = setInterval(onSelectionInterval, 20);
|
||||
}
|
||||
|
||||
return event.preventDefault(e);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue