diff --git a/build/demo/kitchen-sink/kitchen-sink-uncompressed.js b/build/demo/kitchen-sink/kitchen-sink-uncompressed.js index 63fe499d..d8fcb853 100644 --- a/build/demo/kitchen-sink/kitchen-sink-uncompressed.js +++ b/build/demo/kitchen-sink/kitchen-sink-uncompressed.js @@ -6591,6 +6591,17 @@ var EditSession = function(text, mode) { return new Range(row, start, row, end); }; + // Gets the range of a word including its right whitespace + this.getAWordRange = function(row, column) { + var wordRange = this.getWordRange(row, column); + var line = this.getLine(wordRange.end.row); + + while (line.charAt(wordRange.end.column).match(/[ \t]/)) { + wordRange.end.column += 1; + } + return wordRange; + }; + this.setNewLineMode = function(newLineMode) { this.doc.setNewLineMode(newLineMode); }; @@ -7849,11 +7860,11 @@ var Range = require("./range").Range; /** * Keeps cursor position and the text selection of an edit session. - * + * * The row/columns used in the selection are in document coordinates * representing ths coordinates as thez appear in the document * before applying soft wrap and folding. - */ + */ var Selection = function(session) { this.session = session; this.doc = session.getDocument(); @@ -7927,7 +7938,7 @@ var Selection = function(session) { }; var anchor = this.getSelectionAnchor(); - var lead = this.getSelectionLead(); + var lead = this.getSelectionLead(); var isBackwards = this.isBackwards(); @@ -8057,6 +8068,13 @@ var Selection = function(session) { this.setSelectionRange(range); }; + // Selects a word including its right whitespace + this.selectAWord = function() { + var cursor = this.getCursor(); + var range = this.session.getAWordRange(cursor.row, cursor.column); + this.setSelectionRange(range); + }; + this.selectLine = function() { var rowStart = this.selectionLead.row; var rowEnd; @@ -8244,10 +8262,10 @@ var Selection = function(session) { this.selectionLead.row, this.selectionLead.column ); - + var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); - + // move the cursor and update the desired column this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); }; @@ -8263,11 +8281,11 @@ var Selection = function(session) { row = fold.start.row; column = fold.start.column; } - + this.$preventUpdateDesiredColumnOnChange = true; this.selectionLead.setPosition(row, column); this.$preventUpdateDesiredColumnOnChange = false; - + if (!preventUpdateDesiredColumn) this.$updateDesiredColumn(this.selectionLead.column); }; diff --git a/build/src/ace-uncompressed.js b/build/src/ace-uncompressed.js index 4ccccff5..04dfc472 100644 --- a/build/src/ace-uncompressed.js +++ b/build/src/ace-uncompressed.js @@ -5731,6 +5731,17 @@ var EditSession = function(text, mode) { return new Range(row, start, row, end); }; + // Gets the range of a word including its right whitespace + this.getAWordRange = function(row, column) { + var wordRange = this.getWordRange(row, column); + var line = this.getLine(wordRange.end.row); + + while (line.charAt(wordRange.end.column).match(/[ \t]/)) { + wordRange.end.column += 1; + } + return wordRange; + }; + this.setNewLineMode = function(newLineMode) { this.doc.setNewLineMode(newLineMode); }; @@ -6989,11 +7000,11 @@ var Range = require("./range").Range; /** * Keeps cursor position and the text selection of an edit session. - * + * * The row/columns used in the selection are in document coordinates * representing ths coordinates as thez appear in the document * before applying soft wrap and folding. - */ + */ var Selection = function(session) { this.session = session; this.doc = session.getDocument(); @@ -7067,7 +7078,7 @@ var Selection = function(session) { }; var anchor = this.getSelectionAnchor(); - var lead = this.getSelectionLead(); + var lead = this.getSelectionLead(); var isBackwards = this.isBackwards(); @@ -7197,6 +7208,13 @@ var Selection = function(session) { this.setSelectionRange(range); }; + // Selects a word including its right whitespace + this.selectAWord = function() { + var cursor = this.getCursor(); + var range = this.session.getAWordRange(cursor.row, cursor.column); + this.setSelectionRange(range); + }; + this.selectLine = function() { var rowStart = this.selectionLead.row; var rowEnd; @@ -7384,10 +7402,10 @@ var Selection = function(session) { this.selectionLead.row, this.selectionLead.column ); - + var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); - + // move the cursor and update the desired column this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); }; @@ -7403,11 +7421,11 @@ var Selection = function(session) { row = fold.start.row; column = fold.start.column; } - + this.$preventUpdateDesiredColumnOnChange = true; this.selectionLead.setPosition(row, column); this.$preventUpdateDesiredColumnOnChange = false; - + if (!preventUpdateDesiredColumn) this.$updateDesiredColumn(this.selectionLead.column); }; diff --git a/build/textarea/src/ace-uncompressed.js b/build/textarea/src/ace-uncompressed.js index 8bf9ff84..f72efb0b 100644 --- a/build/textarea/src/ace-uncompressed.js +++ b/build/textarea/src/ace-uncompressed.js @@ -5685,6 +5685,17 @@ var EditSession = function(text, mode) { return new Range(row, start, row, end); }; + // Gets the range of a word including its right whitespace + this.getAWordRange = function(row, column) { + var wordRange = this.getWordRange(row, column); + var line = this.getLine(wordRange.end.row); + + while (line.charAt(wordRange.end.column).match(/[ \t]/)) { + wordRange.end.column += 1; + } + return wordRange; + }; + this.setNewLineMode = function(newLineMode) { this.doc.setNewLineMode(newLineMode); }; @@ -6943,11 +6954,11 @@ var Range = require("./range").Range; /** * Keeps cursor position and the text selection of an edit session. - * + * * The row/columns used in the selection are in document coordinates * representing ths coordinates as thez appear in the document * before applying soft wrap and folding. - */ + */ var Selection = function(session) { this.session = session; this.doc = session.getDocument(); @@ -7021,7 +7032,7 @@ var Selection = function(session) { }; var anchor = this.getSelectionAnchor(); - var lead = this.getSelectionLead(); + var lead = this.getSelectionLead(); var isBackwards = this.isBackwards(); @@ -7151,6 +7162,13 @@ var Selection = function(session) { this.setSelectionRange(range); }; + // Selects a word including its right whitespace + this.selectAWord = function() { + var cursor = this.getCursor(); + var range = this.session.getAWordRange(cursor.row, cursor.column); + this.setSelectionRange(range); + }; + this.selectLine = function() { var rowStart = this.selectionLead.row; var rowEnd; @@ -7338,10 +7356,10 @@ var Selection = function(session) { this.selectionLead.row, this.selectionLead.column ); - + var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); - + // move the cursor and update the desired column this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); }; @@ -7357,11 +7375,11 @@ var Selection = function(session) { row = fold.start.row; column = fold.start.column; } - + this.$preventUpdateDesiredColumnOnChange = true; this.selectionLead.setPosition(row, column); this.$preventUpdateDesiredColumnOnChange = false; - + if (!preventUpdateDesiredColumn) this.$updateDesiredColumn(this.selectionLead.column); }; diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 9754f1b4..544a635c 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -441,6 +441,17 @@ var EditSession = function(text, mode) { return new Range(row, start, row, end); }; + // Gets the range of a word including its right whitespace + this.getAWordRange = function(row, column) { + var wordRange = this.getWordRange(row, column); + var line = this.getLine(wordRange.end.row); + + while (line.charAt(wordRange.end.column).match(/[ \t]/)) { + wordRange.end.column += 1; + } + return wordRange; + }; + this.setNewLineMode = function(newLineMode) { this.doc.setNewLineMode(newLineMode); }; diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 88a7bd64..4f0474d9 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -45,11 +45,11 @@ var Range = require("./range").Range; /** * Keeps cursor position and the text selection of an edit session. - * + * * The row/columns used in the selection are in document coordinates * representing ths coordinates as thez appear in the document * before applying soft wrap and folding. - */ + */ var Selection = function(session) { this.session = session; this.doc = session.getDocument(); @@ -123,7 +123,7 @@ var Selection = function(session) { }; var anchor = this.getSelectionAnchor(); - var lead = this.getSelectionLead(); + var lead = this.getSelectionLead(); var isBackwards = this.isBackwards(); @@ -253,6 +253,13 @@ var Selection = function(session) { this.setSelectionRange(range); }; + // Selects a word including its right whitespace + this.selectAWord = function() { + var cursor = this.getCursor(); + var range = this.session.getAWordRange(cursor.row, cursor.column); + this.setSelectionRange(range); + }; + this.selectLine = function() { var rowStart = this.selectionLead.row; var rowEnd; @@ -440,10 +447,10 @@ var Selection = function(session) { this.selectionLead.row, this.selectionLead.column ); - + var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); - + // move the cursor and update the desired column this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); }; @@ -459,11 +466,11 @@ var Selection = function(session) { row = fold.start.row; column = fold.start.column; } - + this.$preventUpdateDesiredColumnOnChange = true; this.selectionLead.setPosition(row, column); this.$preventUpdateDesiredColumnOnChange = false; - + if (!preventUpdateDesiredColumn) this.$updateDesiredColumn(this.selectionLead.column); }; diff --git a/lib/ace/selection_test.js b/lib/ace/selection_test.js index fc962a18..3be52b5f 100644 --- a/lib/ace/selection_test.js +++ b/lib/ace/selection_test.js @@ -149,7 +149,7 @@ module.exports = { " Juhu Kinners (abc, 12)", " cde" ].join("\n")); - + var selection = session.getSelection(); selection.moveCursorDown(); @@ -187,7 +187,7 @@ module.exports = { selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 2); }, - + "test: moveCursor word left" : function() { var session = new EditSession(" Fuß Füße"); @@ -195,7 +195,7 @@ module.exports = { selection.moveCursorTo(0, 9) selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 5); - + selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 4); }, @@ -248,6 +248,18 @@ module.exports = { assert.position(range.end, 0, 12); }, + "test: select word with cursor in word including right whitespace should select the word" : function() { + var session = new EditSession("Juhu Kinners 123"); + var selection = session.getSelection(); + + selection.moveCursorTo(0, 8); + selection.selectAWord(); + + var range = selection.getRange(); + assert.position(range.start, 0, 5); + assert.position(range.end, 0, 18); + }, + "test: select word with cursor betwen white space and word should select the word" : function() { var session = new EditSession("Juhu Kinners"); var selection = session.getSelection(); @@ -308,67 +320,67 @@ module.exports = { selection.moveCursorTo(0, 5); assert.notOk(called); }, - + "test: moveWordLeft should move past || and [": function() { var session = new EditSession("||foo["); var selection = session.getSelection(); - + // Move behind || selection.moveCursorWordRight(); assert.position(selection.getCursor(), 0, 2); - + // Move beind foo selection.moveCursorWordRight(); assert.position(selection.getCursor(), 0, 5); - + // Move behind [ selection.moveCursorWordRight(); assert.position(selection.getCursor(), 0, 6); }, - + "test: moveWordRight should move past || and [": function() { var session = new EditSession("||foo["); var selection = session.getSelection(); - + selection.moveCursorTo(0, 6); - + // Move behind [ selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 5); - + // Move beind foo selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 2); - + // Move behind || selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 0); }, - + "test: move cursor to line start should move cursor to end of the indentation first": function() { var session = new EditSession("12\n Juhu\n12"); var selection = session.getSelection(); - + selection.moveCursorTo(1, 6); selection.moveCursorLineStart(); assert.position(selection.getCursor(), 1, 4); }, - + "test: move cursor to line start when the cursor is at the end of the indentation should move cursor to column 0": function() { var session = new EditSession("12\n Juhu\n12"); var selection = session.getSelection(); - + selection.moveCursorTo(1, 4); selection.moveCursorLineStart(); assert.position(selection.getCursor(), 1, 0); }, - + "test: move cursor to line start when the cursor is at column 0 should move cursor to the end of the indentation": function() { var session = new EditSession("12\n Juhu\n12"); var selection = session.getSelection(); - + selection.moveCursorTo(1, 0); selection.moveCursorLineStart(); @@ -379,64 +391,64 @@ module.exports = { "test: move cursor to line start when the cursor is before the initial indentation should move cursor to the end of the indentation": function() { var session = new EditSession("12\n Juhu\n12"); var selection = session.getSelection(); - + selection.moveCursorTo(1, 2); selection.moveCursorLineStart(); assert.position(selection.getCursor(), 1, 4); }, - + "test go line up when in the middle of the first line should go to document start": function() { var session = new EditSession("juhu kinners"); var selection = session.getSelection(); - + selection.moveCursorTo(0, 4); selection.moveCursorUp(); assert.position(selection.getCursor(), 0, 0); }, - + "test: (wrap) go line up when in the middle of the first line should go to document start": function() { var session = new EditSession("juhu kinners"); session.setWrapLimitRange(5, 5); session.adjustWrapLimit(80); - + var selection = session.getSelection(); - + selection.moveCursorTo(0, 4); selection.moveCursorUp(); assert.position(selection.getCursor(), 0, 0); }, - - + + "test go line down when in the middle of the last line should go to document end": function() { var session = new EditSession("juhu kinners"); var selection = session.getSelection(); - + selection.moveCursorTo(0, 4); selection.moveCursorDown(); assert.position(selection.getCursor(), 0, 12); }, - + "test (wrap) go line down when in the middle of the last line should go to document end": function() { var session = new EditSession("juhu kinners"); session.setWrapLimitRange(8, 8); session.adjustWrapLimit(80); var selection = session.getSelection(); - + selection.moveCursorTo(0, 10); selection.moveCursorDown(); assert.position(selection.getCursor(), 0, 12); }, - + "test go line up twice and then once down when in the second should go back to the previous column": function() { var session = new EditSession("juhu\nkinners"); var selection = session.getSelection(); - + selection.moveCursorTo(1, 4); selection.moveCursorUp(); selection.moveCursorUp(); @@ -444,25 +456,25 @@ module.exports = { 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(); @@ -474,4 +486,4 @@ module.exports = { if (typeof module !== "undefined" && module === require.main) { require("asyncjs").test.testcase(module.exports).exec() -} \ No newline at end of file +}