From 3451ab1b8fb288c73780da6cecc4ce65514b10fd Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Wed, 2 Nov 2011 09:59:28 +0000 Subject: [PATCH 1/3] Issue 489 Initial --- lib/ace/selection.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 65e0fec5..5d315a25 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -440,7 +440,14 @@ var Selection = function(session) { this.selectionLead.row, this.selectionLead.column ); - var screenCol = (chars == 0 && this.$desiredColumn) || screenPos.column; + + var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; + + if (this.$lines[screenPos.row].length === screenPos.column && + this.$lines[screenPos.row + rows].match(/^\s*$/)) { + screenCol = this.$lines[screenPos.row + rows].length; + } + var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0); }; From 125d9bfbfd54fc66f03ebb673e4c9b125b04570b Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Wed, 2 Nov 2011 10:03:04 +0000 Subject: [PATCH 2/3] Issue 489 --- build/demo/kitchen-sink-uncompressed.js | 17 ++++++++++++++++- lib/ace/selection.js | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build/demo/kitchen-sink-uncompressed.js b/build/demo/kitchen-sink-uncompressed.js index 85d8321a..eccf480e 100644 --- a/build/demo/kitchen-sink-uncompressed.js +++ b/build/demo/kitchen-sink-uncompressed.js @@ -11855,8 +11855,23 @@ var Selection = function(session) { this.selectionLead.row, this.selectionLead.column ); - var screenCol = (chars == 0 && this.$desiredColumn) || screenPos.column; + + var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; + + // so here is the deal. First checkout what the content of ur current and ur target line is + var currentLine = (this.session.getLines(screenPos.row, screenPos.row) || [""])[0], + targetLine = (this.session.getLines(screenPos.row + rows, screenPos.row + rows) || [""])[0]; + + // if you are at the EOL of your current line, and your targetline is all whitespace + if (currentLine.length === screenPos.column && targetLine.match(/^\s*$/)) { + // set the new column to the EOL of the target line + screenCol = this.session.getTabString(targetLine).length; + } + var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); + + console.log(rows, chars, screenPos, currentLine, targetLine, screenCol, docPos); + this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0); }; diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 5d315a25..1d76f8b1 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -123,7 +123,7 @@ var Selection = function(session) { }; var anchor = this.getSelectionAnchor(); - var lead = this.getSelectionLead(); + var lead = this.getSelectionLead(); var isBackwards = this.isBackwards(); From b9955714f17ea5282400eac0ec39c637cb7c6968 Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Wed, 2 Nov 2011 11:23:09 +0000 Subject: [PATCH 3/3] new rule on behavior when doing keyboard navigation + tests --- build/demo/kitchen-sink-uncompressed.js | 14 +++++----- lib/ace/selection.js | 20 ++++++++++---- lib/ace/selection_test.js | 36 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/build/demo/kitchen-sink-uncompressed.js b/build/demo/kitchen-sink-uncompressed.js index eccf480e..0f4b055b 100644 --- a/build/demo/kitchen-sink-uncompressed.js +++ b/build/demo/kitchen-sink-uncompressed.js @@ -11863,16 +11863,18 @@ var Selection = function(session) { targetLine = (this.session.getLines(screenPos.row + rows, screenPos.row + rows) || [""])[0]; // if you are at the EOL of your current line, and your targetline is all whitespace - if (currentLine.length === screenPos.column && targetLine.match(/^\s*$/)) { + if (currentLine && targetLine && + currentLine.length === screenPos.column && targetLine.match(/^\s*$/)) { // set the new column to the EOL of the target line screenCol = this.session.getTabString(targetLine).length; - } + // update the chars so we are sure that the desired column will be updated + chars = 1; + }; var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); - - console.log(rows, chars, screenPos, currentLine, targetLine, screenCol, docPos); - - this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0); + + // move the cursor and update the desired column + this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); }; this.moveCursorToPosition = function(position) { diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 1d76f8b1..b9157830 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -443,13 +443,23 @@ var Selection = function(session) { var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; - if (this.$lines[screenPos.row].length === screenPos.column && - this.$lines[screenPos.row + rows].match(/^\s*$/)) { - screenCol = this.$lines[screenPos.row + rows].length; - } + // so here is the deal. First checkout what the content of ur current and ur target line is + var currentLine = (this.session.getLines(screenPos.row, screenPos.row) || [""])[0], + targetLine = (this.session.getLines(screenPos.row + rows, screenPos.row + rows) || [""])[0]; + // if you are at the EOL of your current line, and your targetline is all whitespace + if (currentLine && targetLine && + currentLine.length === screenPos.column && targetLine.match(/^\s*$/)) { + // set the new column to the EOL of the target line + screenCol = this.session.getTabString(targetLine).length; + // update the chars so we are sure that the desired column will be updated + chars = 1; + }; + var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); - this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0); + + // move the cursor and update the desired column + this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); }; this.moveCursorToPosition = function(position) { diff --git a/lib/ace/selection_test.js b/lib/ace/selection_test.js index 335b49db..95914b77 100644 --- a/lib/ace/selection_test.js +++ b/lib/ace/selection_test.js @@ -442,6 +442,42 @@ module.exports = { selection.moveCursorUp(); selection.moveCursorDown(); + assert.position(selection.getCursor(), 1, 4); + }, + + "test (keyboard navigation) when curLine is EOL and targetLine is all whitespace new column should be targetLine's EOL": function() { + var session = new EditSession("function (a) {\n\ + \n\ +}"); + var selection = session.getSelection(); + + selection.moveCursorTo(2, 1); + selection.moveCursorUp(); + + assert.position(selection.getCursor(), 1, 4); + }, + + "test (keyboard navigation) when curLine is not EOL and targetLine is all whitespace new column should be current column": function() { + var session = new EditSession("function (a) {\n\ + \n\ +}"); + var selection = session.getSelection(); + + selection.moveCursorTo(2, 0); + selection.moveCursorUp(); + + assert.position(selection.getCursor(), 1, 0); + }, + + "test (keyboard navigation) when curLine is EOL and targetLine is shorter dan current column, new column should be targetLine's EOL": function() { + var session = new EditSession("function (a) {\n\ + \n\ +}"); + var selection = session.getSelection(); + + selection.moveCursorTo(0, 14); + selection.moveCursorDown(); + assert.position(selection.getCursor(), 1, 4); } };