diff --git a/chrome/content/vimperator/buffers.js b/chrome/content/vimperator/buffers.js index 5394f72b..951bf3ec 100644 --- a/chrome/content/vimperator/buffers.js +++ b/chrome/content/vimperator/buffers.js @@ -164,6 +164,29 @@ function Buffer() //{{{ return result; } + // in contrast to vim, returns the selection if one is made, + // otherwise tries to guess the current word unter the text cursor + // NOTE: might change the selection + this.getCurrentWord = function() + { + var selection = window.content.getSelection().toString(); + + if (!selection) + { + var selection_controller = getBrowser().docShell + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsISelectionDisplay) + .QueryInterface(Components.interfaces.nsISelectionController); + + selection_controller.setCaretEnabled(true); + selection_controller.wordMove(false, false); + selection_controller.wordMove(true, true); + selection = window.content.getSelection().toString(); + } + + return selection; + } + // TODO: move to v.buffers.list() this.list = function(fullmode) { diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js index 9904ce8d..df15e2c6 100644 --- a/chrome/content/vimperator/mappings.js +++ b/chrome/content/vimperator/mappings.js @@ -1381,7 +1381,7 @@ function Mappings() //{{{ addDefaultMap(new Map([vimperator.modes.NORMAL, vimperator.modes.CARET, vimperator.modes.TEXTAREA], ["*"], function(count) { - vimperator.search.searchSubmitted(vimperator.getCurrentWord(), false); + vimperator.search.searchSubmitted(vimperator.buffer.getCurrentWord(), false); vimperator.search.findAgain(); }, { } @@ -1389,7 +1389,7 @@ function Mappings() //{{{ addDefaultMap(new Map([vimperator.modes.NORMAL, vimperator.modes.CARET, vimperator.modes.TEXTAREA], ["#"], function(count) { - vimperator.search.searchSubmitted(vimperator.getCurrentWord(), true); + vimperator.search.searchSubmitted(vimperator.buffer.getCurrentWord(), true); vimperator.search.findAgain(); }, { } diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index 6bbfd4fe..ed0ba5c5 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -358,28 +358,6 @@ const vimperator = (function() //{{{ return new LocalFile(path, mode, perms, tmp); }, - - // in contrast to vim, returns the selection if one is made, - // otherwise tries to guess the current word unter the text cursor - // NOTE: might change the selection - getCurrentWord: function() - { - var selection = window.content.getSelection().toString(); - if (!selection) - { - var selection_controller = getBrowser().docShell - .QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsISelectionDisplay) - .QueryInterface(Components.interfaces.nsISelectionController); - - selection_controller.setCaretEnabled(true); - selection_controller.wordMove(false, false); - selection_controller.wordMove(true, true); - selection = window.content.getSelection().toString(); - } - return selection; - }, - // logs a message to the javascript error console log: function(msg, level) {