diff --git a/build/bundle.js b/build/bundle.js index 314d7c3b..bce79529 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -14484,7 +14484,6 @@ var VisBranch = VisBase.extend({ branch.obj.get('visBranch') )); }); - console.log('getting text size', textNode, 'width', textNode.clientWidth); return firefoxFix({ w: maxWidth, @@ -15067,13 +15066,15 @@ var MultiView = Backbone.View.extend({ this.navEvents = _.clone(Backbone.Events); this.navEvents.on('negative', this.getNegFunc(), this); this.navEvents.on('positive', this.getPosFunc(), this); + this.navEvents.on('quit', this.finish, this); this.keyboardListener = new KeyboardListener({ events: this.navEvents, aliasMap: { left: 'negative', right: 'positive', - enter: 'positive' + enter: 'positive', + esc: 'quit' } }); @@ -16056,7 +16057,7 @@ var CommandPromptView = Backbone.View.extend({ }); this.index = -1; - this.commandSpan = this.$('#prompt span.command')[0]; + this.commandParagraph = this.$('#prompt p.command')[0]; this.commandCursor = this.$('#prompt span.cursor')[0]; this.focus(); @@ -16093,16 +16094,11 @@ var CommandPromptView = Backbone.View.extend({ }, onKeyDown: function(e) { - console.log('on keydown'); - console.log(e); - var el = e.srcElement; this.updatePrompt(el); }, onKeyUp: function(e) { - console.log('on key up'); - console.log(e); this.onKeyDown(e); // we need to capture some of these events. @@ -16145,7 +16141,7 @@ var CommandPromptView = Backbone.View.extend({ // well... var text = $('#commandTextField').val(); var val = this.badHtmlEncode(text); - this.commandSpan.innerHTML = val; + this.commandParagraph.innerHTML = val; // now mutate the cursor... this.cursorUpdate(text.length, el.selectionStart, el.selectionEnd); @@ -16155,24 +16151,31 @@ var CommandPromptView = Backbone.View.extend({ cursorUpdate: function(commandLength, selectionStart, selectionEnd) { if (selectionStart === undefined || selectionEnd === undefined) { - selectionStart = 0; - selectionEnd = 1; + selectionStart = commandLength - 1; + selectionEnd = commandLength; } // 10px for monospaced font at "1" zoom var zoom = require('../util/zoomLevel').detectZoom(); var widthPerChar = 10 * zoom; + var heightPerRow = 22 * zoom; - var numCharsSelected = Math.max(1, selectionEnd - selectionStart); - var width = String(numCharsSelected * widthPerChar) + 'px'; + var widthOfParagraph = $(this.commandParagraph).width(); + var numCharsPerLine = widthOfParagraph / widthPerChar; + + var numCharsSelected = Math.min(Math.max(1, selectionEnd - selectionStart), numCharsPerLine); + var widthOfSelection = String(numCharsSelected * widthPerChar) + 'px'; // now for positioning - var numLeft = (selectionStart !== undefined) ? Math.max(commandLength - selectionStart, 0) : 0; - var left = String(-numLeft * widthPerChar) + 'px'; + var leftOffset = String(widthPerChar * (selectionStart % numCharsPerLine)) + 'px'; + var topOffset = String(Math.floor(selectionStart / numCharsPerLine) * heightPerRow) + 'px'; + console.log('height per row', heightPerRow, 'selection start', selectionStart, 'num chars perline', numCharsPerLine); + // one reflow? :D $(this.commandCursor).css({ - width: width, - left: left + width: widthOfSelection, + left: leftOffset, + top: topOffset }); }, @@ -20715,7 +20718,7 @@ var CommandPromptView = Backbone.View.extend({ }); this.index = -1; - this.commandSpan = this.$('#prompt span.command')[0]; + this.commandParagraph = this.$('#prompt p.command')[0]; this.commandCursor = this.$('#prompt span.cursor')[0]; this.focus(); @@ -20752,16 +20755,11 @@ var CommandPromptView = Backbone.View.extend({ }, onKeyDown: function(e) { - console.log('on keydown'); - console.log(e); - var el = e.srcElement; this.updatePrompt(el); }, onKeyUp: function(e) { - console.log('on key up'); - console.log(e); this.onKeyDown(e); // we need to capture some of these events. @@ -20804,7 +20802,7 @@ var CommandPromptView = Backbone.View.extend({ // well... var text = $('#commandTextField').val(); var val = this.badHtmlEncode(text); - this.commandSpan.innerHTML = val; + this.commandParagraph.innerHTML = val; // now mutate the cursor... this.cursorUpdate(text.length, el.selectionStart, el.selectionEnd); @@ -20814,24 +20812,31 @@ var CommandPromptView = Backbone.View.extend({ cursorUpdate: function(commandLength, selectionStart, selectionEnd) { if (selectionStart === undefined || selectionEnd === undefined) { - selectionStart = 0; - selectionEnd = 1; + selectionStart = commandLength - 1; + selectionEnd = commandLength; } // 10px for monospaced font at "1" zoom var zoom = require('../util/zoomLevel').detectZoom(); var widthPerChar = 10 * zoom; + var heightPerRow = 22 * zoom; - var numCharsSelected = Math.max(1, selectionEnd - selectionStart); - var width = String(numCharsSelected * widthPerChar) + 'px'; + var widthOfParagraph = $(this.commandParagraph).width(); + var numCharsPerLine = widthOfParagraph / widthPerChar; + + var numCharsSelected = Math.min(Math.max(1, selectionEnd - selectionStart), numCharsPerLine); + var widthOfSelection = String(numCharsSelected * widthPerChar) + 'px'; // now for positioning - var numLeft = (selectionStart !== undefined) ? Math.max(commandLength - selectionStart, 0) : 0; - var left = String(-numLeft * widthPerChar) + 'px'; + var leftOffset = String(widthPerChar * (selectionStart % numCharsPerLine)) + 'px'; + var topOffset = String(Math.floor(selectionStart / numCharsPerLine) * heightPerRow) + 'px'; + console.log('height per row', heightPerRow, 'selection start', selectionStart, 'num chars perline', numCharsPerLine); + // one reflow? :D $(this.commandCursor).css({ - width: width, - left: left + width: widthOfSelection, + left: leftOffset, + top: topOffset }); }, @@ -22171,13 +22176,15 @@ var MultiView = Backbone.View.extend({ this.navEvents = _.clone(Backbone.Events); this.navEvents.on('negative', this.getNegFunc(), this); this.navEvents.on('positive', this.getPosFunc(), this); + this.navEvents.on('quit', this.finish, this); this.keyboardListener = new KeyboardListener({ events: this.navEvents, aliasMap: { left: 'negative', right: 'positive', - enter: 'positive' + enter: 'positive', + esc: 'quit' } }); @@ -23895,7 +23902,6 @@ var VisBranch = VisBase.extend({ branch.obj.get('visBranch') )); }); - console.log('getting text size', textNode, 'width', textNode.clientWidth); return firefoxFix({ w: maxWidth, diff --git a/index.html b/index.html index e2a48f33..01837461 100644 --- a/index.html +++ b/index.html @@ -40,10 +40,10 @@