summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2010-06-27 18:34:57 +0200
committerMichael Hamann <michael@content-space.de>2010-06-27 18:40:38 +0200
commit136982455ae0eddc18744176db33fbd7b421e11c (patch)
tree47204bcdc587685117e1de019f6659220ef4c460
parent226bf2dc02909d49bb6afbd7b5018572aeba6050 (diff)
downloadrpg-136982455ae0eddc18744176db33fbd7b421e11c.tar.gz
rpg-136982455ae0eddc18744176db33fbd7b421e11c.tar.bz2
Fixed automatic insertion of listbullets in Opera FS#1877
The keydown event can't be prevented in Opera (see http://www.quirksmode.org/dom/events/keys.html) so this switches back to keypress in Opera (keypress doesn't give the correct key codes in Firefox). Furthermore Opera replaces '\n' by '\r\n' when inserting text, thus the offset for cursor/selection placement was wrong.
-rw-r--r--lib/scripts/edit.js10
-rw-r--r--lib/scripts/textselection.js7
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index b9767fdc0..b507e804b 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -169,7 +169,7 @@ function keyHandler(e){
var scroll = field.scrollHeight;
var match2 = search.match(/^\n +[\*-]\s*$/);
// Cancel list if the last item is empty (i. e. two times enter)
- if (match2 && field.value.substr(selection.start).match(/^($|\n)/)) {
+ if (match2 && field.value.substr(selection.start).match(/^($|\r?\n)/)) {
field.value = field.value.substr(0, linestart) + "\n" +
field.value.substr(selection.start);
selection.start = linestart + 1;
@@ -222,7 +222,13 @@ function keyHandler(e){
addInitEvent(function(){
var field = $('wiki__text');
if(!field) return;
- addEvent(field,'keydown',keyHandler);
+ // in Firefox, keypress doesn't send the correct keycodes,
+ // in Opera, the default of keydown can't be prevented
+ if (is_opera) {
+ addEvent(field,'keypress',keyHandler);
+ } else {
+ addEvent(field,'keydown',keyHandler);
+ }
});
/**
diff --git a/lib/scripts/textselection.js b/lib/scripts/textselection.js
index 0378b544d..742338785 100644
--- a/lib/scripts/textselection.js
+++ b/lib/scripts/textselection.js
@@ -161,7 +161,12 @@ function pasteText(selection,text,opts){
selection.obj.value.substring(selection.end, selection.obj.value.length);
// set new selection
- selection.end = selection.start + text.length;
+ if (is_opera) {
+ // Opera replaces \n by \r\n when inserting text.
+ selection.end = selection.start + text.replace(/\r?\n/g, '\r\n').length;
+ } else {
+ selection.end = selection.start + text.length;
+ }
// modify the new selection if wanted
if(opts.startofs) selection.start += opts.startofs;