Commits

Michael Shepanski committed 11f6f6d Draft Merge
  • Participants
  • Parent commits 03fec4c, dd66c71

Comments (0)

Files changed (2)

File .gitignore

Empty file added.

File wysiwym/wysiwym.js

         if (typeof(this.textelem.selectionStart) == 'number') {
             var startpos = this.textelem.selectionStart;
             var endpos = this.textelem.selectionEnd;
+            if (this.textelem.value.indexOf('\r\n') !== -1) {
+              //this fixes Opera, it has \r\n's instead of \n's
+              startpos -= (this.textelem.value.substring(0, startpos).match(/\r\n/g)||[]).length;
+              endpos -= (this.textelem.value.substring(0, endpos).match(/\r\n/g)||[]).length;
+            }
         } else {
             this.textelem.focus();
             var text = this.textelem.value.replace(/\r\n/g, '\n');
         var selectionEnd = properties[2];
         this.textarea.val(newtext);
         if (this.textelem.setSelectionRange) {
-            this.textelem.setSelectionRange(selectionStart, selectionEnd);
+            if (this.textelem.value.indexOf('\r\n') !== -1) {
+              //this fixes Opera, it has \r\n's instead of \n's
+              var virtual = newtext.replace(/\r\n/g,'\n');
+              var deltaStart = (virtual.substring(0, selectionStart).match(/\n/g)||[]).length;
+              var deltaEnd = (virtual.substring(0, selectionEnd).match(/\n/g)||[]).length;
+              this.textelem.setSelectionRange(selectionStart + deltaStart, selectionEnd + deltaEnd);
+            }else{
+              this.textelem.setSelectionRange(selectionStart, selectionEnd);
+            }
         } else if (this.textelem.createTextRange) {
             var range = this.textelem.createTextRange();
             range.collapse(true);