Observe for highlight?

狂风中的少年 提交于 2019-12-02 03:33:08
Noitidart

I found a solution but it doesn't use nsIController as @Neil had recommended in a SO topic HERE to look at viewSource.js.

Im still interested in a nsIController solution if possible, im trying to understand that sucker it confuses me.

So this is how you observer for a selection:

 var mylis = {
   timeout: 0,
   notifySelectionChanged: function(doc, sel, reason)
   {
       if (!this.timeout) {
           this.timeout = setTimeout(function() {
               console.log('notifySelectionChanged','doc=',doc,'sel=',sel,'reason=',reason);
               mylis.timeout = 0;
           }, 1000);
       }
   }
 }

gBrowser.contentWindow.getSelection().QueryInterface(Ci.nsISelectionPrivate).addSelectionListener(mylis);

//gBrowser.contentWindow.getSelection().QueryInterface(Ci.nsISelectionPrivate).removeSelectionListener(mylis);

the timeout is important because otherwise it will slow down the browser thread. you can see as you highlight its all gimicky. viewSource.js used 100ms so I would reocmmend that.

MXR - viewSource.js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!