diff options
author | Andreas Gohr <gohr@cosmocode.de> | 2009-08-06 11:38:33 +0200 |
---|---|---|
committer | Andreas Gohr <gohr@cosmocode.de> | 2009-08-06 11:38:33 +0200 |
commit | 21aec47c3344df2ccbc69de8a50097d4a6273599 (patch) | |
tree | 7378b064621cb034cdda178bf8e3e384952714c7 /lib/scripts/textselection.js | |
parent | edfd1f892681cc411c036f9aa877d8c454c72c6b (diff) | |
download | dokuwiki-21aec47c3344df2ccbc69de8a50097d4a6273599.tar.gz dokuwiki-21aec47c3344df2ccbc69de8a50097d4a6273599.zip |
some cleanup in the IE selection handling
Ignore-this: 5a6b527fbf3f2ffc79e3ceef11552763
darcs-hash:20090806093833-6e07b-f5fbd738bff54ec6a3488e4fb9ab98c6e49799d4.gz
Diffstat (limited to 'lib/scripts/textselection.js')
-rw-r--r-- | lib/scripts/textselection.js | 23 |
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) { |