summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/scripts/textselection.js23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/scripts/textselection.js b/lib/scripts/textselection.js
index 8b7632831..cd9dbe7fa 100644
--- a/lib/scripts/textselection.js
+++ b/lib/scripts/textselection.js
@@ -53,8 +53,6 @@ function getSelection(textArea) {
*
* 1. Selections trim newlines at the end of the code
* 2. Selections count newlines as two characters
- *
- * FIXME see what code is not needed here and can be removed
*/
// The current selection
@@ -65,11 +63,13 @@ function getSelection(textArea) {
before_range.setEndPoint("EndToStart", sel.rangeCopy); // Moves the end where we need it
var before_finished = false, selection_finished = false;
- var before_text, untrimmed_before_text, selection_text, untrimmed_selection_text;
-
+ var before_text, selection_text;
// Load the text values we need to compare
- before_text = untrimmed_before_text = before_range.text;
- selection_text = untrimmed_selection_text = sel.rangeCopy.text;
+ before_text = before_range.text;
+ selection_text = sel.rangeCopy.text;
+
+ sel.start = before_text.length;
+ sel.end = sel.start + selection_text.length;
// Check each range for trimmed newlines by shrinking the range by 1 character and seeing
// if the text property has changed. If it has not changed then we know that IE has trimmed
@@ -81,7 +81,8 @@ function getSelection(textArea) {
} else {
before_range.moveEnd("character", -1)
if (before_range.text == before_text) {
- untrimmed_before_text += "\n";
+ sel.start++;
+ sel.end++;
} else {
before_finished = true;
}
@@ -93,7 +94,7 @@ function getSelection(textArea) {
} else {
sel.rangeCopy.moveEnd("character", -1)
if (sel.rangeCopy.text == selection_text) {
- untrimmed_selection_text += "\n";
+ sel.end++;
} else {
selection_finished = true;
}
@@ -101,12 +102,6 @@ function getSelection(textArea) {
}
} while ((!before_finished || !selection_finished));
- var startPoint = untrimmed_before_text.length;
- var endPoint = startPoint + untrimmed_selection_text.length;
-
- sel.start = startPoint;
- sel.end = endPoint;
-
// count number of newlines in str to work around stupid IE selection bug
var countNL = function(str) {