From 297ee9576ba39b7d33f6fea74b53320b258c7cbd Mon Sep 17 00:00:00 2001 From: John Foerch Date: Fri, 9 Apr 2010 11:19:34 -0400 Subject: [PATCH] getFocusedSelCtrl moved to buffer.focused_selection_controller --- modules/buffer.js | 23 ++++++++++++++++++++++- modules/caret.js | 4 ++-- modules/find.js | 26 ++------------------------ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/modules/buffer.js b/modules/buffer.js index c274846..4ef0c68 100644 --- a/modules/buffer.js +++ b/modules/buffer.js @@ -245,6 +245,27 @@ buffer.prototype = { return null; }, + get focused_selection_controller () { + var child_docshells = this.doc_shell.getDocShellEnumerator( + Ci.nsIDocShellTreeItem.typeContent, + Ci.nsIDocShell.ENUMERATE_FORWARDS); + while (child_docshells.hasMoreElements()) { + let ds = child_docshells.getNext() + .QueryInterface(Ci.nsIDocShell); + if (ds.hasFocus) { + let display = ds.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsISelectionDisplay); + if (! display) + return null; + return display.QueryInterface(Ci.nsISelectionController); + } + } + return this.doc_shell + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsISelectionDisplay) + .QueryInterface(Ci.nsISelectionController); + }, + do_command: function (command) { function attempt_command (element, command) { var controller; @@ -720,7 +741,7 @@ interactive("shell-command", null, define_buffer_local_hook("unfocus_hook"); function unfocus (window, buffer) { // 1. if there is a selection, clear it. - var selc = getFocusedSelCtrl(buffer); + var selc = buffer.focused_selection_controller; if (selc && selc.getSelection(selc.SELECTION_NORMAL).isCollapsed == false) { clear_selection(buffer); window.minibuffer.message("cleared selection"); diff --git a/modules/caret.js b/modules/caret.js index 478a516..523f492 100644 --- a/modules/caret.js +++ b/modules/caret.js @@ -16,7 +16,7 @@ define_buffer_mode('caret_mode', $display_name = 'CARET', $enable = function (buffer) { buffer.browser.setAttribute('showcaret', 'true'); - var sc = getFocusedSelCtrl(buffer); + var sc = buffer.focused_selection_controller; sc.setCaretEnabled(true); buffer.top_frame.focus(); buffer.modalities.push(caret_modality); @@ -24,7 +24,7 @@ define_buffer_mode('caret_mode', }, $disable = function (buffer) { buffer.browser.setAttribute('showcaret', 'false'); - var sc = getFocusedSelCtrl(buffer); + var sc = buffer.focused_selection_controller; sc.setCaretEnabled(false); buffer.browser.focus(); var i = buffer.modalities.indexOf(caret_modality); diff --git a/modules/find.js b/modules/find.js index 83c4860..8b0799f 100644 --- a/modules/find.js +++ b/modules/find.js @@ -20,31 +20,9 @@ function caret_enabled (buffer) { return buffer.browser.getAttribute(CARET_ATTRIBUTE); } -// turn on the selection in all frames -function getFocusedSelCtrl (buffer) { - var ds = buffer.doc_shell; - var dsEnum = ds.getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeContent, - Ci.nsIDocShell.ENUMERATE_FORWARDS); - while (dsEnum.hasMoreElements()) { - ds = dsEnum.getNext().QueryInterface(Ci.nsIDocShell); - if (ds.hasFocus) { - var display = ds.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsISelectionDisplay); - if (!display) - return null; - return display.QueryInterface(Ci.nsISelectionController); - } - } - - // One last try - return buffer.doc_shell - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsISelectionDisplay) - .QueryInterface(Ci.nsISelectionController); -} function clear_selection (buffer) { - let sel_ctrl = getFocusedSelCtrl(buffer); + let sel_ctrl = buffer.focused_selection_controller; if (sel_ctrl) { let sel = sel_ctrl.getSelection(sel_ctrl.SELECTION_NORMAL); if (caret_enabled(buffer)) { @@ -79,7 +57,7 @@ function isearch_session (window, forward) { this.states = []; this.buffer = window.buffers.current; this.frame = this.buffer.focused_frame; - this.sel_ctrl = getFocusedSelCtrl(this.buffer); + this.sel_ctrl = this.buffer.focused_selection_controller; this.sel_ctrl.setDisplaySelection(Ci.nsISelectionController.SELECTION_ATTENTION); this.sel_ctrl.repaintSelection(Ci.nsISelectionController.SELECTION_NORMAL); this.states.push(new initial_isearch_state(this.buffer, this.frame, forward)); -- 2.11.4.GIT