From 140ff6f1bf06c53658addc47d72c038633c8ed5e Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 15 Feb 2013 12:24:16 +0000 Subject: [PATCH 1/4] dont lose focus on key up, doesn't work yet --- src/static/js/ace2_inner.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 8209c9bf8..d719bc081 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3539,7 +3539,6 @@ function Ace2Inner(){ { // if (DEBUG && window.DONT_INCORP) return; if (!isEditable) return; - var type = evt.type; var charCode = evt.charCode; var keyCode = evt.keyCode; @@ -3731,6 +3730,30 @@ function Ace2Inner(){ updateBrowserSelectionFromRep(); }, 200); } + + // Chrome sucks at moving the users UI to the right place when the user uses the arrow keys + // we catch these issues and fix it. + // You can replicate this bug by copy/pasting text into a pad and moving it about then using the + // arrow keys to navitgate + if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && type == 'keydown' && $.browser.chrome){ + /* Is it an event we care about? */ + var isUpArrow = evt.which === 38; + var isLeftArrow = evt.which === 38; + var newVisibleLineRange = getVisibleLineRange(); // get the current visible range + top.console.log("IM NOT UPDATING! I need a way to get the actual rep when a key is held down", rep.selStart[0]); + if(isUpArrow || isLeftArrow){ // was it an up arrow or left arrow? + var lineNum = rep.selStart[0]; // Get the current Line Number IE 84 + var caretIsVisible = (lineNum > newVisibleLineRange[0]); // Is the cursor in the visible Range IE ie 84 > 14? + if(!caretIsVisible){ // is the cursor no longer visible to the user? + // Oh boy the caret is out of the visible area, I need to scroll the browser window to lineNum. + top.console.log("I need to scroll thw UI to here"); + var lineHeight = textLineHeight(); // what Is the height of each line? + // Get the new Y by getting the line number and multiplying by the height of each line. + var newY = lineHeight * (lineNum -1); // -1 to go to the line above + setScrollY(newY); // set the scroll height of the browser + } + } + } } if (type == "keydown") From 04f609752fa4b5c7a3bfa26ea8a2f082e0f1e184 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 17 Feb 2013 18:05:25 +0000 Subject: [PATCH 2/4] actually works --- src/static/js/ace2_inner.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index d719bc081..5fc09b835 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3731,29 +3731,27 @@ function Ace2Inner(){ }, 200); } - // Chrome sucks at moving the users UI to the right place when the user uses the arrow keys - // we catch these issues and fix it. - // You can replicate this bug by copy/pasting text into a pad and moving it about then using the - // arrow keys to navitgate - if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && type == 'keydown' && $.browser.chrome){ - /* Is it an event we care about? */ - var isUpArrow = evt.which === 38; - var isLeftArrow = evt.which === 38; - var newVisibleLineRange = getVisibleLineRange(); // get the current visible range - top.console.log("IM NOT UPDATING! I need a way to get the actual rep when a key is held down", rep.selStart[0]); - if(isUpArrow || isLeftArrow){ // was it an up arrow or left arrow? - var lineNum = rep.selStart[0]; // Get the current Line Number IE 84 - var caretIsVisible = (lineNum > newVisibleLineRange[0]); // Is the cursor in the visible Range IE ie 84 > 14? + /* Attempt to apply some sanity to cursor handling in Chrome after a copy / paste event + We have to do this the way we do because rep. doesn't hold the value for keyheld events IE if the user + presses and holds the arrow key */ + if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && $.browser.chrome){ + var newVisibleLineRange = getVisibleLineRange(); // get the current visible range -- This works great. + var lineHeight = textLineHeight(); // what Is the height of each line? + var myselection = document.getSelection(); // get the current caret selection, can't use rep. here because that only gives us the start position not the current + var caretOffsetTop = myselection.focusNode.parentNode.offsetTop; // get the carets selection offset in px IE 214 + + if(caretOffsetTop){ // sometimes caretOffsetTop bugs out and returns 0, not sure why, possible Chrome bug? Either way if it does we don't wanna mess with it + var lineNum = Math.round(caretOffsetTop / lineHeight) ; // Get the current Line Number IE 84 + var caretIsVisible = (lineNum > newVisibleLineRange[0] && lineNum < newVisibleLineRange[1]); // Is the cursor in the visible Range IE ie 84 > 14 and 84 < 90? if(!caretIsVisible){ // is the cursor no longer visible to the user? // Oh boy the caret is out of the visible area, I need to scroll the browser window to lineNum. - top.console.log("I need to scroll thw UI to here"); - var lineHeight = textLineHeight(); // what Is the height of each line? // Get the new Y by getting the line number and multiplying by the height of each line. - var newY = lineHeight * (lineNum -1); // -1 to go to the line above + var newY = lineHeight * (lineNum -1); // -1 to go to the line above setScrollY(newY); // set the scroll height of the browser } } } + } if (type == "keydown") From 5441179e78072b40bb52da8e447c176558a59d5b Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 18 Feb 2013 19:38:25 +0000 Subject: [PATCH 3/4] dont jump pages --- src/static/js/ace2_inner.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 5fc09b835..0d5260668 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3746,7 +3746,11 @@ function Ace2Inner(){ if(!caretIsVisible){ // is the cursor no longer visible to the user? // Oh boy the caret is out of the visible area, I need to scroll the browser window to lineNum. // Get the new Y by getting the line number and multiplying by the height of each line. - var newY = lineHeight * (lineNum -1); // -1 to go to the line above + if(evt.which == 37 || evt.which == 38){ // If left or up + var newY = lineHeight * (lineNum -1); // -1 to go to the line above + }else if(evt.which == 39 || evt.which == 40){ // if down or right + var newY = caretOffsetTop + lineHeight; // the offset and one additional line + } setScrollY(newY); // set the scroll height of the browser } } From ab81b5cfe979a9e1a2440df6a8931ab8a0ac11ca Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 18 Feb 2013 19:46:31 +0000 Subject: [PATCH 4/4] dont jump pages --- src/static/js/ace2_inner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 0d5260668..4ae98080e 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3742,6 +3742,7 @@ function Ace2Inner(){ if(caretOffsetTop){ // sometimes caretOffsetTop bugs out and returns 0, not sure why, possible Chrome bug? Either way if it does we don't wanna mess with it var lineNum = Math.round(caretOffsetTop / lineHeight) ; // Get the current Line Number IE 84 + newVisibleLineRange[1] = newVisibleLineRange[1]-1; var caretIsVisible = (lineNum > newVisibleLineRange[0] && lineNum < newVisibleLineRange[1]); // Is the cursor in the visible Range IE ie 84 > 14 and 84 < 90? if(!caretIsVisible){ // is the cursor no longer visible to the user? // Oh boy the caret is out of the visible area, I need to scroll the browser window to lineNum. @@ -3749,7 +3750,7 @@ function Ace2Inner(){ if(evt.which == 37 || evt.which == 38){ // If left or up var newY = lineHeight * (lineNum -1); // -1 to go to the line above }else if(evt.which == 39 || evt.which == 40){ // if down or right - var newY = caretOffsetTop + lineHeight; // the offset and one additional line + var newY = getScrollY() + (lineHeight*3); // the offset and one additional line } setScrollY(newY); // set the scroll height of the browser }