diff --git a/lib/ace/Document.js b/lib/ace/Document.js index 74d021c2..bb7b27b7 100644 --- a/lib/ace/Document.js +++ b/lib/ace/Document.js @@ -166,6 +166,40 @@ var Document = function(text, mode) { 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() { switch (this.$newLineMode) { diff --git a/lib/ace/Editor.js b/lib/ace/Editor.js index 8aa330d5..79a2e73b 100644 --- a/lib/ace/Editor.js +++ b/lib/ace/Editor.js @@ -37,8 +37,8 @@ var Editor = function(renderer, doc) { var mouseTarget = renderer.getMouseEventTarget(); event.addListener(mouseTarget, "mousedown", lang.bind(this.onMouseDown, this)); - event.addMultiMouseDownListener(mouseTarget, 2, 500, lang.bind(this.onMouseDoubleClick, this)); - event.addMultiMouseDownListener(mouseTarget, 3, 600, lang.bind(this.onMouseTripleClick, this)); + event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, lang.bind(this.onMouseDoubleClick, this)); + event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, lang.bind(this.onMouseTripleClick, this)); event.addMouseWheelListener(mouseTarget, lang.bind(this.onMouseWheel, this)); this.$selectionMarker = null; @@ -270,11 +270,15 @@ var Editor = function(renderer, doc) { var pageX = event.getDocumentX(e); var pageY = event.getDocumentY(e); - if (event.getButton(e) != 0) - return; - var pos = this.renderer.screenToTextCoordinates(pageX, pageY); 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) this.selection.selectToPosition(pos) diff --git a/lib/ace/Selection.js b/lib/ace/Selection.js index 6609ff81..015057dc 100644 --- a/lib/ace/Selection.js +++ b/lib/ace/Selection.js @@ -198,9 +198,6 @@ var Selection = function(doc) { this.$moveSelection(this.moveCursorFileStart); }; - this.tokenRe = /^[\w\d]+/g; - this.nonTokenRe = /^[^\w\d]+/g; - this.selectWordRight = function() { this.$moveSelection(this.moveCursorWordRight); }; @@ -211,39 +208,14 @@ var Selection = function(doc) { this.selectWord = function() { var cursor = this.selectionLead; - - var line = this.doc.getLine(cursor.row); var column = cursor.column; - - 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++; - } - - this.setSelectionAnchor(cursor.row, start); + var range = this.doc.getWordRange(cursor.row, column); + this.setSelectionRange(range); + + /*this.setSelectionAnchor(cursor.row, start); this.$moveSelection(function() { this.moveCursorTo(cursor.row, end); - }); + });*/ }; this.selectLine = function() { @@ -317,20 +289,20 @@ var Selection = function(doc) { var rightOfCursor = line.substring(column); var match; - this.nonTokenRe.lastIndex = 0; - this.tokenRe.lastIndex = 0; + this.doc.nonTokenRe.lastIndex = 0; + this.doc.tokenRe.lastIndex = 0; if (column == line.length) { this.moveCursorRight(); return; } - else if (match = this.nonTokenRe.exec(rightOfCursor)) { - column += this.nonTokenRe.lastIndex; - this.nonTokenRe.lastIndex = 0; + else if (match = this.doc.nonTokenRe.exec(rightOfCursor)) { + column += this.doc.nonTokenRe.lastIndex; + this.doc.nonTokenRe.lastIndex = 0; } - else if (match = this.tokenRe.exec(rightOfCursor)) { - column += this.tokenRe.lastIndex; - this.tokenRe.lastIndex = 0; + else if (match = this.doc.tokenRe.exec(rightOfCursor)) { + column += this.doc.tokenRe.lastIndex; + this.doc.tokenRe.lastIndex = 0; } this.moveCursorTo(row, column); @@ -343,20 +315,20 @@ var Selection = function(doc) { var leftOfCursor = lang.stringReverse(line.substring(0, column)); var match; - this.nonTokenRe.lastIndex = 0; - this.tokenRe.lastIndex = 0; + this.doc.nonTokenRe.lastIndex = 0; + this.doc.tokenRe.lastIndex = 0; if (column == 0) { this.moveCursorLeft(); return; } - else if (match = this.nonTokenRe.exec(leftOfCursor)) { - column -= this.nonTokenRe.lastIndex; - this.nonTokenRe.lastIndex = 0; + else if (match = this.doc.nonTokenRe.exec(leftOfCursor)) { + column -= this.doc.nonTokenRe.lastIndex; + this.doc.nonTokenRe.lastIndex = 0; } - else if (match = this.tokenRe.exec(leftOfCursor)) { - column -= this.tokenRe.lastIndex; - this.tokenRe.lastIndex = 0; + else if (match = this.doc.tokenRe.exec(leftOfCursor)) { + column -= this.doc.tokenRe.lastIndex; + this.doc.tokenRe.lastIndex = 0; } this.moveCursorTo(row, column); diff --git a/lib/ace/lib/event.js b/lib/ace/lib/event.js index 4cd117ba..803ee803 100644 --- a/lib/ace/lib/event.js +++ b/lib/ace/lib/event.js @@ -158,7 +158,7 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) { event.addListener(el, "mousewheel", listener); }; - event.addMultiMouseDownListener = function(el, count, timeout, callback) { + event.addMultiMouseDownListener = function(el, button, count, timeout, callback) { var clicks = 0; var startX, startY; @@ -173,7 +173,8 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) { }, 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; if (clicks == count) { diff --git a/lib/ace/theme/tm.css b/lib/ace/theme/tm.css index be72a9a8..4e999fa1 100644 --- a/lib/ace/theme/tm.css +++ b/lib/ace/theme/tm.css @@ -105,6 +105,10 @@ background: rgb(252, 255, 0); } +.ace-tm .ace_marker-layer .ace_stack { + background: rgb(164, 229, 101); +} + .ace-tm .ace_marker-layer .ace_bracket { margin: -1px 0 0 -1px; border: 1px solid rgb(192, 192, 192);