jquery.textSelection: Add setContents function
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Sat, 26 Jul 2014 13:47:03 +0000 (15:47 +0200)
committerDerk-Jan Hartman <hartman.wiki@gmail.com>
Sat, 26 Jul 2014 14:09:37 +0000 (16:09 +0200)
This function is specified in the commands handler below, but did not
have an implementation for the plain textarea case.

Better we make this work. A user wanted this api call so his JS
cleanup script could work consistently on both plain textarea and the
CodeEditor

Change-Id: Ib3afc505037a5b12269e55b4b130a38a3fac7823

resources/src/jquery/jquery.textSelection.js
tests/qunit/suites/resources/jquery/jquery.textSelection.test.js

index 0573f66..e5444eb 100644 (file)
                        getContents: function () {
                                return this.val();
                        },
+                       /**
+                        * Set the contents of the textarea, replacing anything that was there before
+                        */
+                       setContents: function ( content ) {
+                               this.val( content );
+                       },
                        /**
                         * Get the currently selected text in this textarea. Will focus the textarea
                         * in some browsers (IE/Opera)
index 2191c3b..56b0fa9 100644 (file)
 
                        $( '#qunit-fixture' ).append( $textarea );
 
-                       // This method is actually missing atm...
-                       //$textarea.textSelection( 'setContents', opt.before.text);
-
-                       // Won't work with the WikiEditor iframe?
-                       $textarea.val( opt.before.text );
+                       $textarea.textSelection( 'setContents', opt.before.text );
 
                        start = opt.before.start;
                        end = opt.before.end;