diff --git a/lib/ace/BackgroundTokenizer.js b/lib/ace/BackgroundTokenizer.js index 57e74f84..c9075639 100644 --- a/lib/ace/BackgroundTokenizer.js +++ b/lib/ace/BackgroundTokenizer.js @@ -120,8 +120,11 @@ var BackgroundTokenizer = function(tokenizer, editor) { this.lines[row] = tokens; } } - else - rows.push(this.lines[row]); + else { + var tokens = this.lines[row]; + state = tokens.state; + rows.push(tokens); + } } return rows; }; diff --git a/lib/ace/Document.js b/lib/ace/Document.js index 54aa2030..ee9f025e 100644 --- a/lib/ace/Document.js +++ b/lib/ace/Document.js @@ -513,9 +513,7 @@ var Document = function(text, mode) { this.$remove(range, fromUndo); - this.fireChangeEvent(range.start.row, - !range.isMultiLine() ? range.start.row - : undefined); + this.fireChangeEvent(range.start.row, range.isMultiLine() ? undefined : range.start.row); return range.start; }; @@ -634,20 +632,22 @@ var Document = function(text, mode) { this.moveLinesUp = function(firstRow, lastRow) { if (firstRow <= 0) return 0; - var removed = this.lines.splice(firstRow, lastRow-firstRow+1); - this.$insertLines(firstRow-1, removed); + var removed = this.lines.slice(firstRow, lastRow + 1); + this.$remove(new Range(firstRow, 0, lastRow + 1, 0)); + this.$insertLines(firstRow - 1, removed); - this.fireChangeEvent(firstRow-1, lastRow); + this.fireChangeEvent(firstRow - 1, lastRow); return -1; }; this.moveLinesDown = function(firstRow, lastRow) { if (lastRow >= this.lines.length-1) return 0; - var removed = this.lines.splice(firstRow, lastRow-firstRow+1); + var removed = this.lines.slice(firstRow, lastRow + 1); + this.$remove(new Range(firstRow, 0, lastRow + 1, 0)); this.$insertLines(firstRow+1, removed); - - this.fireChangeEvent(firstRow, lastRow+1); + + this.fireChangeEvent(firstRow, lastRow + 1); return 1; }; diff --git a/lib/ace/Editor.js b/lib/ace/Editor.js index 27993334..18d66f06 100644 --- a/lib/ace/Editor.js +++ b/lib/ace/Editor.js @@ -913,7 +913,6 @@ var Editor =function(renderer, doc) { }; this.replace = function(replacement, options) { - console.log("replacing with " + replacement); if (options) this.$search.set(options); diff --git a/lib/ace/RenderLoop.js b/lib/ace/RenderLoop.js index 97c02a83..c1fcd490 100644 --- a/lib/ace/RenderLoop.js +++ b/lib/ace/RenderLoop.js @@ -16,6 +16,8 @@ var RenderLoop = function(onRender) { (function() { this.schedule = function(change) { +// this.onRender(change); +// return; this.changes = this.changes | change; if (!this.pending) { this.pending = true; diff --git a/lib/ace/Selection.js b/lib/ace/Selection.js index 015057dc..7915481c 100644 --- a/lib/ace/Selection.js +++ b/lib/ace/Selection.js @@ -260,11 +260,13 @@ var Selection = function(doc) { var row = this.selectionLead.row; var column = this.selectionLead.column; var beforeCursor = this.doc.getLine(row).slice(0, column); - var leadingSpace = beforeCursor.match(/^\s+/); - if (!leadingSpace || leadingSpace[0].length >= column) - this.moveCursorTo(this.selectionLead.row, 0); + var leadingSpace = beforeCursor.match(/^\s*/); + if (leadingSpace[0].length == 0) + this.moveCursorTo(row, this.doc.getLine(row).match(/^\s*/)[0].length); + else if (leadingSpace[0].length >= column) + this.moveCursorTo(row, 0); else - this.moveCursorTo(this.selectionLead.row, leadingSpace[0].length); + this.moveCursorTo(row, leadingSpace[0].length); }; this.moveCursorLineEnd = function() { diff --git a/lib/ace/VirtualRenderer.js b/lib/ace/VirtualRenderer.js index 6d0e16a4..21042538 100644 --- a/lib/ace/VirtualRenderer.js +++ b/lib/ace/VirtualRenderer.js @@ -84,10 +84,11 @@ var VirtualRenderer = function(container, theme) { scrollerWidth: 0 }; - this.$updatePrintMargin(); - this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this)); this.$loop.schedule(this.CHANGE_FULL); + + this.$updatePrintMargin(); + this.setPadding(4); }; (function() { @@ -119,6 +120,9 @@ var VirtualRenderer = function(container, theme) { * Triggers partial update of the text layer */ this.updateLines = function(firstRow, lastRow) { + if (lastRow === undefined) + lastRow = Infinity; + if (!this.$changedLines) { this.$changedLines = { firstRow: firstRow, @@ -132,8 +136,6 @@ var VirtualRenderer = function(container, theme) { if (this.$changedLines.lastRow < lastRow) this.$changedLines.lastRow = lastRow; } - if (this.$changedLines.lastRow === undefined) - this.$changedLines.lastRow = Infinity; this.$loop.schedule(this.CHANGE_LINES); }; @@ -185,6 +187,7 @@ var VirtualRenderer = function(container, theme) { }; this.setTokenizer = function(tokenizer) { + this.$tokenizer = tokenizer; this.$textLayer.setTokenizer(tokenizer); this.$loop.schedule(this.CHANGE_TEXT); }; @@ -283,17 +286,24 @@ var VirtualRenderer = function(container, theme) { return (this.layerConfig || {}).lastRow || 0; }; + this.$padding = null; + this.setPadding = function(padding) { + this.$padding = padding; + this.content.style.padding = "0 " + padding + "px"; + this.$loop.schedule(this.CHANGE_FULL); + }; + this.onScroll = function(e) { this.scrollToY(e.data); }; this.$updateScrollBar = function() { - this.scrollBar.setInnerHeight(this.doc.getLength() * this.lineHeight); + this.scrollBar.setInnerHeight(this.doc.getLength() * this.lineHeight + this.$padding); this.scrollBar.setScrollTop(this.scrollTop); }; this.$renderChanges = function(changes) { - if (!changes) + if (!changes || !this.doc || !this.$tokenizer) return; // text, scrolling and resize changes can cause the view port size to change @@ -368,11 +378,12 @@ var VirtualRenderer = function(container, theme) { var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine); var lineCount = Math.ceil(minHeight / this.lineHeight); - var firstRow = Math.round((this.scrollTop - offset) / this.lineHeight); + var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight)); var lastRow = Math.min(this.lines.length, firstRow + lineCount) - 1; var layerConfig = this.layerConfig = { width : longestLine, + padding : this.$padding, firstRow : firstRow, lastRow : lastRow, lineHeight : this.lineHeight, @@ -392,16 +403,14 @@ var VirtualRenderer = function(container, theme) { this.$gutterLayer.element.style.marginTop = (-offset) + "px"; this.content.style.marginTop = (-offset) + "px"; + this.content.style.width = longestLine + "px"; this.content.style.height = minHeight + "px"; }; this.$updateLines = function() { var firstRow = this.$changedLines.firstRow; var lastRow = this.$changedLines.lastRow; - this.$changedLines = { - firstRow: 0, - lastRow: Infinity - }; + this.$changedLines = null; var layerConfig = this.layerConfig; @@ -428,7 +437,7 @@ var VirtualRenderer = function(container, theme) { if (this.$showInvisibles) charCount += 1; - return Math.max(this.$size.scrollerWidth, Math.round(charCount * this.characterWidth)); + return Math.max(this.$size.scrollerWidth - this.$padding * 2, Math.round(charCount * this.characterWidth)); }; this.addMarker = function(range, clazz, type) { @@ -473,7 +482,7 @@ var VirtualRenderer = function(container, theme) { this.scrollCursorIntoView = function() { var pos = this.$cursorLayer.getPixelPosition(); - var left = pos.left; + var left = pos.left + this.$padding; var top = pos.top; if (this.getScrollTop() > top) { @@ -486,13 +495,13 @@ var VirtualRenderer = function(container, theme) { } if (this.scroller.scrollLeft > left) { - this.scroller.scrollLeft = left; + this.scrollToX(left); } if (this.scroller.scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) { - this.scroller.scrollLeft = Math.round(left + this.characterWidth - - this.$size.scrollerWidth); + this.scrollToX(Math.round(left + this.characterWidth + - this.$size.scrollerWidth)); } }, @@ -513,7 +522,10 @@ var VirtualRenderer = function(container, theme) { }; this.scrollToY = function(scrollTop) { - var maxHeight = this.lines.length * this.lineHeight - this.$size.scrollerHeight; + var maxHeight = this.lines.length * this.lineHeight - this.$size.scrollerHeight + this.$padding; + if (scrollTop >= maxHeight - this.$padding) + scrollTop = maxHeight; + var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop)); if (this.scrollTop !== scrollTop) { @@ -521,16 +533,23 @@ var VirtualRenderer = function(container, theme) { this.$loop.schedule(this.CHANGE_SCROLL); } }; + + this.scrollToX = function(scrollLeft) { + if (scrollLeft <= this.$padding) + scrollLeft = 0; + + this.scroller.scrollLeft = scrollLeft; + }; this.scrollBy = function(deltaX, deltaY) { deltaY && this.scrollToY(this.scrollTop + deltaY); - deltaX && (this.scroller.scrollLeft += deltaX); + deltaX && this.scrollToX(this.scroller.scrollLeft + deltaX); }; this.screenToTextCoordinates = function(pageX, pageY) { var canvasPos = this.scroller.getBoundingClientRect(); - var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left) + var col = Math.round((pageX + this.scroller.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth); var row = Math.floor((pageY + this.scrollTop - canvasPos.top) / this.lineHeight); @@ -544,7 +563,7 @@ var VirtualRenderer = function(container, theme) { this.textToScreenCoordinates = function(row, column) { var canvasPos = this.scroller.getBoundingClientRect(); - var x = Math.round(this.doc.documentToScreenColumn(row, column) * this.characterWidth); + var x = this.padding + Math.round(this.doc.documentToScreenColumn(row, column) * this.characterWidth); var y = row * this.lineHeight; return { @@ -602,4 +621,4 @@ var VirtualRenderer = function(container, theme) { }).call(VirtualRenderer.prototype); return VirtualRenderer; -}); +}); \ No newline at end of file diff --git a/lib/ace/conf/keybindings/default_mac.js b/lib/ace/conf/keybindings/default_mac.js index ad1c9f26..0a652dda 100644 --- a/lib/ace/conf/keybindings/default_mac.js +++ b/lib/ace/conf/keybindings/default_mac.js @@ -26,7 +26,7 @@ return { "selectup": "Shift-Up", "golineup": "Up", "copylinesdown": "Command-Option-Down", - "movelinsedown": "Option-Down", + "movelinesdown": "Option-Down", "selecttoend": "Command-Shift-Down", "gotoend": "Command-End|Command-Down", "selectdown": "Shift-Down", diff --git a/lib/ace/conf/keybindings/default_win.js b/lib/ace/conf/keybindings/default_win.js index 6bcb1960..fd5d393c 100644 --- a/lib/ace/conf/keybindings/default_win.js +++ b/lib/ace/conf/keybindings/default_win.js @@ -26,7 +26,7 @@ return { "selectup": "Shift-Up", "golineup": "Up", "copylinesdown": "Ctrl-Alt-Down", - "movelinsedown": "Alt-Down", + "movelinesdown": "Alt-Down", "selecttoend": "Ctrl-Shift-Down", "gotoend": "Ctrl-End|Ctrl-Down", "selectdown": "Shift-Down", diff --git a/lib/ace/mode/DocCommentHighlightRules.js b/lib/ace/mode/DocCommentHighlightRules.js index 1b500c6e..915c7d29 100644 --- a/lib/ace/mode/DocCommentHighlightRules.js +++ b/lib/ace/mode/DocCommentHighlightRules.js @@ -41,7 +41,7 @@ oop.inherits(DocCommentHighlightRules, TextHighlightRules); this.getStartRule = function(start) { return { token : "comment.doc", // doc comment - regex : "\\/\\*\\*", + regex : "\\/\\*(?=\\*)", next: start }; };