From 6b47fb69d077069521998470b6b8d692181a0555 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 17 Feb 2013 18:01:25 +0000 Subject: [PATCH 1/3] seems to be working pretty well --- src/static/js/ace2_inner.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 8209c9bf8..70b5443bd 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3731,6 +3731,33 @@ function Ace2Inner(){ updateBrowserSelectionFromRep(); }, 200); } + + /* 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 isLeftArrow = evt.which === 37; + var isUpArrow = evt.which === 38; + var isRightArrow = evt.which === 39; + var isDownArrow = evt.which === 40; + + 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((isUpArrow || isLeftArrow || isRightArrow || isDownArrow) && caretOffsetTop){ // was it an up arrow or left arrow? + 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. + // 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") @@ -3836,7 +3863,6 @@ function Ace2Inner(){ selection.endPoint = getPointForLineAndChar(se); selection.focusAtStart = !! rep.selFocusAtStart; - setSelection(selection); } From 48ffbde7316a2aa21d76e300d0a272651b98b389 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 18 Feb 2013 01:10:54 +0000 Subject: [PATCH 2/3] allow colon to indent line --- src/static/js/ace2_inner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 70b5443bd..5c0af0f15 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1897,7 +1897,7 @@ function Ace2Inner(){ var prevLine = rep.lines.prev(thisLine); var prevLineText = prevLine.text; var theIndent = /^ *(?:)/.exec(prevLineText)[0]; - if (/[\[\(\{]\s*$/.exec(prevLineText)) theIndent += THE_TAB; + if (/[\[\(\:\{]\s*$/.exec(prevLineText)) theIndent += THE_TAB; var cs = Changeset.builder(rep.lines.totalWidth()).keep( rep.lines.offsetOfIndex(lineNum), lineNum).insert( theIndent, [ From 77d03d34731f1ec12d77f82fe4c260c4bb9f559a Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 18 Feb 2013 01:40:34 +0000 Subject: [PATCH 3/3] Try to add some sanity to indentation --- src/static/js/ace2_inner.js | 9 +++++---- src/static/js/pad_editbar.js | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 5c0af0f15..151a18068 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -3287,7 +3287,7 @@ function Ace2Inner(){ listType = /([a-z]+)([12345678])/.exec(listType); var type = listType[1]; var level = Number(listType[2]); - + //detect empty list item; exclude indentation if(text === '*' && type !== "indent") { @@ -3317,8 +3317,10 @@ function Ace2Inner(){ function doIndentOutdent(isOut) { - if (!(rep.selStart && rep.selEnd) || - ((rep.selStart[0] == rep.selEnd[0]) && (rep.selStart[1] == rep.selEnd[1]) && rep.selEnd[1] > 1)) + if (!((rep.selStart && rep.selEnd) || + ((rep.selStart[0] == rep.selEnd[0]) && (rep.selStart[1] == rep.selEnd[1]) && rep.selEnd[1] > 1)) && + (isOut != true) + ) { return false; } @@ -3326,7 +3328,6 @@ function Ace2Inner(){ var firstLine, lastLine; firstLine = rep.selStart[0]; lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0)); - var mods = []; for (var n = firstLine; n <= lastLine; n++) { diff --git a/src/static/js/pad_editbar.js b/src/static/js/pad_editbar.js index 91a07bf96..cc9f8758c 100644 --- a/src/static/js/pad_editbar.js +++ b/src/static/js/pad_editbar.js @@ -156,10 +156,7 @@ var padeditbar = (function() else if (cmd == 'insertorderedlist') ace.ace_doInsertOrderedList(); else if (cmd == 'indent') { - if (!ace.ace_doIndentOutdent(false)) - { - ace.ace_doInsertUnorderedList(); - } + ace.ace_doIndentOutdent(false); } else if (cmd == 'outdent') {