Mercurial > firefox-enso
comparison enso_pyxpcom.py @ 3:21f5e1dc0a4c default tip
text selection for firefox will return the full contents of the current text field if no text is selected. also, the seldict contains references to the currently-focused element and window, if any.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 09 May 2008 12:59:10 -0700 |
parents | 4f22928c7a2c |
children |
comparison
equal
deleted
inserted
replaced
2:4f22928c7a2c | 3:21f5e1dc0a4c |
---|---|
20 cc = components.classes | 20 cc = components.classes |
21 | 21 |
22 Application = getFuelApplication() | 22 Application = getFuelApplication() |
23 document = Application.activeWindow.activeTab.document | 23 document = Application.activeWindow.activeTab.document |
24 | 24 |
25 mediator = cc["@mozilla.org/appshell/window-mediator;1"].getService(ci.nsIWindowMediator) | 25 mediator = cc["@mozilla.org/appshell/window-mediator;1"].getService( |
26 ci.nsIWindowMediator | |
27 ) | |
26 window = mediator.getMostRecentWindow("navigator:browser") | 28 window = mediator.getMostRecentWindow("navigator:browser") |
27 return window.document.commandDispatcher | 29 return window.document.commandDispatcher |
28 | 30 |
29 def firefoxSelectionHook(): | 31 def firefoxSelectionHook(): |
30 import AppKit | 32 import AppKit |
44 if dispatcher.focusedElement: | 46 if dispatcher.focusedElement: |
45 start = dispatcher.focusedElement.selectionStart | 47 start = dispatcher.focusedElement.selectionStart |
46 end = dispatcher.focusedElement.selectionEnd | 48 end = dispatcher.focusedElement.selectionEnd |
47 if start != end: | 49 if start != end: |
48 text = dispatcher.focusedElement.value[start:end] | 50 text = dispatcher.focusedElement.value[start:end] |
51 else: | |
52 text = dispatcher.focusedElement.value | |
49 elif dispatcher.focusedWindow: | 53 elif dispatcher.focusedWindow: |
50 sel = dispatcher.focusedWindow.getSelection() | 54 sel = dispatcher.focusedWindow.getSelection() |
51 if sel.rangeCount >= 1: | 55 if sel.rangeCount >= 1: |
52 text = sel.toString() | 56 text = sel.toString() |
53 | 57 |
54 return {"text" : text} | 58 return {"text" : text, |
59 "dom.element" : dispatcher.focusedElement, | |
60 "dom.window" : dispatcher.focusedWindow} | |
55 | 61 |
56 def installFirefoxSelectionHook(): | 62 def installFirefoxSelectionHook(): |
57 from enso.platform.osx import selection | 63 from enso.platform.osx import selection |
58 | 64 |
59 selection._old_get = selection.get | 65 selection._old_get = selection.get |