diff --git a/tk-silica/xm-gadgets.lisp b/tk-silica/xm-gadgets.lisp
index 977db018175d6040a21073a330424707bc599cf6..f1435017009766df207771f83870fb831d9943d8 100644
--- a/tk-silica/xm-gadgets.lisp
+++ b/tk-silica/xm-gadgets.lisp
@@ -1020,6 +1020,13 @@
 	   (and (not (zerop x))
 		(values (excl:native-to-string x)))))))
 
+(defmethod silica::set-selection ((tf motif-text-editor) startpos endpos)
+  (let ((m (sheet-direct-mirror tf)))
+    (when m
+      (let* ((display (port-display (port tf)))
+             (time (tk::xt-last-timestamp-processed display)))
+        (tk::xm_text_set_selection m startpos endpos time)))))
+
 (defmethod compose-space ((te motif-text-editor) &key width height)
   (declare (ignore width height))
   (make-space-requirement :width (process-width-specification te`(,(gadget-columns te) :character))
diff --git a/tk/xm-funs.lisp b/tk/xm-funs.lisp
index 085987362ed0afaf8de2de1a2f3e05dd3be20109..c6ed5539ef7b6797bbfae0d456c4a2104d6c69d9 100644
--- a/tk/xm-funs.lisp
+++ b/tk/xm-funs.lisp
@@ -244,6 +244,15 @@
   :call-direct t
   :arg-checking nil)
 
+(def-foreign-call (xm_text_set_selection "XmTextSetSelection")
+    ((x :foreign-address)
+     (first :long)
+     (last :long)
+     (time :foreign-address))
+  :returning :void
+  :call-direct t
+  :arg-checking nil)
+
 (def-foreign-call (xm_scale_set_value "XmScaleSetValue")
     ((x :foreign-address) (y :int fixnum))
   :returning :void