This commit is contained in:
Sergi Mansilla 2011-11-25 11:30:31 +01:00
commit 0ca443966e
7 changed files with 79 additions and 25 deletions

View file

@ -6608,6 +6608,17 @@ var EditSession = function(text, mode) {
return new Range(row, start, row, end); 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.setNewLineMode = function(newLineMode) {
this.doc.setNewLineMode(newLineMode); this.doc.setNewLineMode(newLineMode);
}; };
@ -7866,11 +7877,11 @@ var Range = require("./range").Range;
/** /**
* Keeps cursor position and the text selection of an edit session. * Keeps cursor position and the text selection of an edit session.
* *
* The row/columns used in the selection are in document coordinates * The row/columns used in the selection are in document coordinates
* representing ths coordinates as thez appear in the document * representing ths coordinates as thez appear in the document
* before applying soft wrap and folding. * before applying soft wrap and folding.
*/ */
var Selection = function(session) { var Selection = function(session) {
this.session = session; this.session = session;
this.doc = session.getDocument(); this.doc = session.getDocument();
@ -7944,7 +7955,7 @@ var Selection = function(session) {
}; };
var anchor = this.getSelectionAnchor(); var anchor = this.getSelectionAnchor();
var lead = this.getSelectionLead(); var lead = this.getSelectionLead();
var isBackwards = this.isBackwards(); var isBackwards = this.isBackwards();
@ -8074,6 +8085,13 @@ var Selection = function(session) {
this.setSelectionRange(range); 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() { this.selectLine = function() {
var rowStart = this.selectionLead.row; var rowStart = this.selectionLead.row;
var rowEnd; var rowEnd;
@ -8261,10 +8279,10 @@ var Selection = function(session) {
this.selectionLead.row, this.selectionLead.row,
this.selectionLead.column this.selectionLead.column
); );
var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column;
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
// move the cursor and update the desired column // move the cursor and update the desired column
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
}; };
@ -8280,11 +8298,11 @@ var Selection = function(session) {
row = fold.start.row; row = fold.start.row;
column = fold.start.column; column = fold.start.column;
} }
this.$preventUpdateDesiredColumnOnChange = true; this.$preventUpdateDesiredColumnOnChange = true;
this.selectionLead.setPosition(row, column); this.selectionLead.setPosition(row, column);
this.$preventUpdateDesiredColumnOnChange = false; this.$preventUpdateDesiredColumnOnChange = false;
if (!preventUpdateDesiredColumn) if (!preventUpdateDesiredColumn)
this.$updateDesiredColumn(this.selectionLead.column); this.$updateDesiredColumn(this.selectionLead.column);
}; };

File diff suppressed because one or more lines are too long

View file

@ -11,7 +11,7 @@
Ace Ace
version 0.2.0 version 0.2.0
commit 219d337db34951e44d1484979918a3030901dd0c commit 7e84cef35b033d0d159560f3959737318db514ac
--> -->

View file

@ -5748,6 +5748,17 @@ var EditSession = function(text, mode) {
return new Range(row, start, row, end); 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.setNewLineMode = function(newLineMode) {
this.doc.setNewLineMode(newLineMode); this.doc.setNewLineMode(newLineMode);
}; };
@ -7006,11 +7017,11 @@ var Range = require("./range").Range;
/** /**
* Keeps cursor position and the text selection of an edit session. * Keeps cursor position and the text selection of an edit session.
* *
* The row/columns used in the selection are in document coordinates * The row/columns used in the selection are in document coordinates
* representing ths coordinates as thez appear in the document * representing ths coordinates as thez appear in the document
* before applying soft wrap and folding. * before applying soft wrap and folding.
*/ */
var Selection = function(session) { var Selection = function(session) {
this.session = session; this.session = session;
this.doc = session.getDocument(); this.doc = session.getDocument();
@ -7084,7 +7095,7 @@ var Selection = function(session) {
}; };
var anchor = this.getSelectionAnchor(); var anchor = this.getSelectionAnchor();
var lead = this.getSelectionLead(); var lead = this.getSelectionLead();
var isBackwards = this.isBackwards(); var isBackwards = this.isBackwards();
@ -7214,6 +7225,13 @@ var Selection = function(session) {
this.setSelectionRange(range); 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() { this.selectLine = function() {
var rowStart = this.selectionLead.row; var rowStart = this.selectionLead.row;
var rowEnd; var rowEnd;
@ -7401,10 +7419,10 @@ var Selection = function(session) {
this.selectionLead.row, this.selectionLead.row,
this.selectionLead.column this.selectionLead.column
); );
var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column;
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
// move the cursor and update the desired column // move the cursor and update the desired column
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
}; };
@ -7420,11 +7438,11 @@ var Selection = function(session) {
row = fold.start.row; row = fold.start.row;
column = fold.start.column; column = fold.start.column;
} }
this.$preventUpdateDesiredColumnOnChange = true; this.$preventUpdateDesiredColumnOnChange = true;
this.selectionLead.setPosition(row, column); this.selectionLead.setPosition(row, column);
this.$preventUpdateDesiredColumnOnChange = false; this.$preventUpdateDesiredColumnOnChange = false;
if (!preventUpdateDesiredColumn) if (!preventUpdateDesiredColumn)
this.$updateDesiredColumn(this.selectionLead.column); this.$updateDesiredColumn(this.selectionLead.column);
}; };

File diff suppressed because one or more lines are too long

View file

@ -5702,6 +5702,17 @@ var EditSession = function(text, mode) {
return new Range(row, start, row, end); 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.setNewLineMode = function(newLineMode) {
this.doc.setNewLineMode(newLineMode); this.doc.setNewLineMode(newLineMode);
}; };
@ -6960,11 +6971,11 @@ var Range = require("./range").Range;
/** /**
* Keeps cursor position and the text selection of an edit session. * Keeps cursor position and the text selection of an edit session.
* *
* The row/columns used in the selection are in document coordinates * The row/columns used in the selection are in document coordinates
* representing ths coordinates as thez appear in the document * representing ths coordinates as thez appear in the document
* before applying soft wrap and folding. * before applying soft wrap and folding.
*/ */
var Selection = function(session) { var Selection = function(session) {
this.session = session; this.session = session;
this.doc = session.getDocument(); this.doc = session.getDocument();
@ -7038,7 +7049,7 @@ var Selection = function(session) {
}; };
var anchor = this.getSelectionAnchor(); var anchor = this.getSelectionAnchor();
var lead = this.getSelectionLead(); var lead = this.getSelectionLead();
var isBackwards = this.isBackwards(); var isBackwards = this.isBackwards();
@ -7168,6 +7179,13 @@ var Selection = function(session) {
this.setSelectionRange(range); 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() { this.selectLine = function() {
var rowStart = this.selectionLead.row; var rowStart = this.selectionLead.row;
var rowEnd; var rowEnd;
@ -7355,10 +7373,10 @@ var Selection = function(session) {
this.selectionLead.row, this.selectionLead.row,
this.selectionLead.column this.selectionLead.column
); );
var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column; var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column;
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol); var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
// move the cursor and update the desired column // move the cursor and update the desired column
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
}; };
@ -7374,11 +7392,11 @@ var Selection = function(session) {
row = fold.start.row; row = fold.start.row;
column = fold.start.column; column = fold.start.column;
} }
this.$preventUpdateDesiredColumnOnChange = true; this.$preventUpdateDesiredColumnOnChange = true;
this.selectionLead.setPosition(row, column); this.selectionLead.setPosition(row, column);
this.$preventUpdateDesiredColumnOnChange = false; this.$preventUpdateDesiredColumnOnChange = false;
if (!preventUpdateDesiredColumn) if (!preventUpdateDesiredColumn)
this.$updateDesiredColumn(this.selectionLead.column); this.$updateDesiredColumn(this.selectionLead.column);
}; };

File diff suppressed because one or more lines are too long