Subtle selection / mouse tweaks
This commit is contained in:
parent
05caccfd90
commit
770e1626da
5 changed files with 71 additions and 56 deletions
|
|
@ -166,6 +166,40 @@ var Document = function(text, mode) {
|
||||||
this.$autoNewLine = "\n";
|
this.$autoNewLine = "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.tokenRe = /^[\w\d]+/g;
|
||||||
|
this.nonTokenRe = /^[^\w\d]+/g;
|
||||||
|
|
||||||
|
this.getWordRange = function(row, column) {
|
||||||
|
var line = this.getLine(row);
|
||||||
|
|
||||||
|
var inToken = false;
|
||||||
|
if (column > 0) {
|
||||||
|
inToken = !!line.charAt(column - 1).match(this.tokenRe);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inToken) {
|
||||||
|
inToken = !!line.charAt(column).match(this.tokenRe);
|
||||||
|
}
|
||||||
|
|
||||||
|
var re = inToken ? this.tokenRe : this.nonTokenRe;
|
||||||
|
|
||||||
|
var start = column;
|
||||||
|
if (start > 0) {
|
||||||
|
do {
|
||||||
|
start--;
|
||||||
|
}
|
||||||
|
while (start >= 0 && line.charAt(start).match(re));
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var end = column;
|
||||||
|
while (end < line.length && line.charAt(end).match(re)) {
|
||||||
|
end++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Range(row, start, row, end);
|
||||||
|
};
|
||||||
|
|
||||||
this.$getNewLineCharacter = function() {
|
this.$getNewLineCharacter = function() {
|
||||||
switch (this.$newLineMode) {
|
switch (this.$newLineMode) {
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ var Editor = function(renderer, doc) {
|
||||||
|
|
||||||
var mouseTarget = renderer.getMouseEventTarget();
|
var mouseTarget = renderer.getMouseEventTarget();
|
||||||
event.addListener(mouseTarget, "mousedown", lang.bind(this.onMouseDown, this));
|
event.addListener(mouseTarget, "mousedown", lang.bind(this.onMouseDown, this));
|
||||||
event.addMultiMouseDownListener(mouseTarget, 2, 500, lang.bind(this.onMouseDoubleClick, this));
|
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, lang.bind(this.onMouseDoubleClick, this));
|
||||||
event.addMultiMouseDownListener(mouseTarget, 3, 600, lang.bind(this.onMouseTripleClick, this));
|
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, lang.bind(this.onMouseTripleClick, this));
|
||||||
event.addMouseWheelListener(mouseTarget, lang.bind(this.onMouseWheel, this));
|
event.addMouseWheelListener(mouseTarget, lang.bind(this.onMouseWheel, this));
|
||||||
|
|
||||||
this.$selectionMarker = null;
|
this.$selectionMarker = null;
|
||||||
|
|
@ -274,11 +274,15 @@ var Editor = function(renderer, doc) {
|
||||||
var pageX = event.getDocumentX(e);
|
var pageX = event.getDocumentX(e);
|
||||||
var pageY = event.getDocumentY(e);
|
var pageY = event.getDocumentY(e);
|
||||||
|
|
||||||
if (event.getButton(e) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var pos = this.renderer.screenToTextCoordinates(pageX, pageY);
|
var pos = this.renderer.screenToTextCoordinates(pageX, pageY);
|
||||||
pos.row = Math.max(0, Math.min(pos.row, this.doc.getLength()-1));
|
pos.row = Math.max(0, Math.min(pos.row, this.doc.getLength()-1));
|
||||||
|
|
||||||
|
if (event.getButton(e) != 0) {
|
||||||
|
if (this.selection.isEmpty()) {
|
||||||
|
this.moveCursorToPosition(pos);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.shiftKey)
|
if (e.shiftKey)
|
||||||
this.selection.selectToPosition(pos)
|
this.selection.selectToPosition(pos)
|
||||||
|
|
|
||||||
|
|
@ -198,9 +198,6 @@ var Selection = function(doc) {
|
||||||
this.$moveSelection(this.moveCursorFileStart);
|
this.$moveSelection(this.moveCursorFileStart);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.tokenRe = /^[\w\d]+/g;
|
|
||||||
this.nonTokenRe = /^[^\w\d]+/g;
|
|
||||||
|
|
||||||
this.selectWordRight = function() {
|
this.selectWordRight = function() {
|
||||||
this.$moveSelection(this.moveCursorWordRight);
|
this.$moveSelection(this.moveCursorWordRight);
|
||||||
};
|
};
|
||||||
|
|
@ -211,39 +208,14 @@ var Selection = function(doc) {
|
||||||
|
|
||||||
this.selectWord = function() {
|
this.selectWord = function() {
|
||||||
var cursor = this.selectionLead;
|
var cursor = this.selectionLead;
|
||||||
|
|
||||||
var line = this.doc.getLine(cursor.row);
|
|
||||||
var column = cursor.column;
|
var column = cursor.column;
|
||||||
|
var range = this.doc.getWordRange(cursor.row, column);
|
||||||
var inToken = false;
|
this.setSelectionRange(range);
|
||||||
if (column > 0) {
|
|
||||||
inToken = !!line.charAt(column - 1).match(this.tokenRe);
|
/*this.setSelectionAnchor(cursor.row, start);
|
||||||
}
|
|
||||||
|
|
||||||
if (!inToken) {
|
|
||||||
inToken = !!line.charAt(column).match(this.tokenRe);
|
|
||||||
}
|
|
||||||
|
|
||||||
var re = inToken ? this.tokenRe : this.nonTokenRe;
|
|
||||||
|
|
||||||
var start = column;
|
|
||||||
if (start > 0) {
|
|
||||||
do {
|
|
||||||
start--;
|
|
||||||
}
|
|
||||||
while (start >= 0 && line.charAt(start).match(re));
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
|
|
||||||
var end = column;
|
|
||||||
while (end < line.length && line.charAt(end).match(re)) {
|
|
||||||
end++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setSelectionAnchor(cursor.row, start);
|
|
||||||
this.$moveSelection(function() {
|
this.$moveSelection(function() {
|
||||||
this.moveCursorTo(cursor.row, end);
|
this.moveCursorTo(cursor.row, end);
|
||||||
});
|
});*/
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectLine = function() {
|
this.selectLine = function() {
|
||||||
|
|
@ -317,20 +289,20 @@ var Selection = function(doc) {
|
||||||
var rightOfCursor = line.substring(column);
|
var rightOfCursor = line.substring(column);
|
||||||
|
|
||||||
var match;
|
var match;
|
||||||
this.nonTokenRe.lastIndex = 0;
|
this.doc.nonTokenRe.lastIndex = 0;
|
||||||
this.tokenRe.lastIndex = 0;
|
this.doc.tokenRe.lastIndex = 0;
|
||||||
|
|
||||||
if (column == line.length) {
|
if (column == line.length) {
|
||||||
this.moveCursorRight();
|
this.moveCursorRight();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (match = this.nonTokenRe.exec(rightOfCursor)) {
|
else if (match = this.doc.nonTokenRe.exec(rightOfCursor)) {
|
||||||
column += this.nonTokenRe.lastIndex;
|
column += this.doc.nonTokenRe.lastIndex;
|
||||||
this.nonTokenRe.lastIndex = 0;
|
this.doc.nonTokenRe.lastIndex = 0;
|
||||||
}
|
}
|
||||||
else if (match = this.tokenRe.exec(rightOfCursor)) {
|
else if (match = this.doc.tokenRe.exec(rightOfCursor)) {
|
||||||
column += this.tokenRe.lastIndex;
|
column += this.doc.tokenRe.lastIndex;
|
||||||
this.tokenRe.lastIndex = 0;
|
this.doc.tokenRe.lastIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.moveCursorTo(row, column);
|
this.moveCursorTo(row, column);
|
||||||
|
|
@ -343,20 +315,20 @@ var Selection = function(doc) {
|
||||||
var leftOfCursor = lang.stringReverse(line.substring(0, column));
|
var leftOfCursor = lang.stringReverse(line.substring(0, column));
|
||||||
|
|
||||||
var match;
|
var match;
|
||||||
this.nonTokenRe.lastIndex = 0;
|
this.doc.nonTokenRe.lastIndex = 0;
|
||||||
this.tokenRe.lastIndex = 0;
|
this.doc.tokenRe.lastIndex = 0;
|
||||||
|
|
||||||
if (column == 0) {
|
if (column == 0) {
|
||||||
this.moveCursorLeft();
|
this.moveCursorLeft();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (match = this.nonTokenRe.exec(leftOfCursor)) {
|
else if (match = this.doc.nonTokenRe.exec(leftOfCursor)) {
|
||||||
column -= this.nonTokenRe.lastIndex;
|
column -= this.doc.nonTokenRe.lastIndex;
|
||||||
this.nonTokenRe.lastIndex = 0;
|
this.doc.nonTokenRe.lastIndex = 0;
|
||||||
}
|
}
|
||||||
else if (match = this.tokenRe.exec(leftOfCursor)) {
|
else if (match = this.doc.tokenRe.exec(leftOfCursor)) {
|
||||||
column -= this.tokenRe.lastIndex;
|
column -= this.doc.tokenRe.lastIndex;
|
||||||
this.tokenRe.lastIndex = 0;
|
this.doc.tokenRe.lastIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.moveCursorTo(row, column);
|
this.moveCursorTo(row, column);
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
|
||||||
event.addListener(el, "mousewheel", listener);
|
event.addListener(el, "mousewheel", listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
event.addMultiMouseDownListener = function(el, count, timeout, callback) {
|
event.addMultiMouseDownListener = function(el, button, count, timeout, callback) {
|
||||||
var clicks = 0;
|
var clicks = 0;
|
||||||
var startX, startY;
|
var startX, startY;
|
||||||
|
|
||||||
|
|
@ -173,7 +173,8 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
|
||||||
}, timeout || 600);
|
}, timeout || 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
|
if (event.getButton(e) != button
|
||||||
|
|| Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
|
||||||
clicks = 0;
|
clicks = 0;
|
||||||
|
|
||||||
if (clicks == count) {
|
if (clicks == count) {
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,10 @@
|
||||||
background: rgb(252, 255, 0);
|
background: rgb(252, 255, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ace-tm .ace_marker-layer .ace_stack {
|
||||||
|
background: rgb(164, 229, 101);
|
||||||
|
}
|
||||||
|
|
||||||
.ace-tm .ace_marker-layer .ace_bracket {
|
.ace-tm .ace_marker-layer .ace_bracket {
|
||||||
margin: -1px 0 0 -1px;
|
margin: -1px 0 0 -1px;
|
||||||
border: 1px solid rgb(192, 192, 192);
|
border: 1px solid rgb(192, 192, 192);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue