From 73e35da652dcb6090d7e23128a5771237580ba37 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sun, 5 Apr 2009 12:38:52 +0100 Subject: [PATCH] Make getCurrentWord more sensible. If the selection is at the start of a word it will select the next word not the previous. This is only approximate, as it assumes that words are space-delimited and begin at node boundaries. --- common/content/buffer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index 857953ed..4d204ad6 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -998,17 +998,20 @@ function Buffer() //{{{ getCurrentWord: function () { let selection = window.content.getSelection(); + let range = selection.getRangeAt(0); if (selection.isCollapsed) { let selController = this.selectionController; let caretmode = selController.getCaretEnabled(); selController.setCaretEnabled(true); - selController.wordMove(false, false); + //Only move backwards if the previous character is not a space. + if (range.startOffset > 0 && !/\s/.test(range.startContainer.textContent[range.startOffset - 1])) + selController.wordMove(false, false); + selController.wordMove(true, true); selController.setCaretEnabled(caretmode); return String.match(selection, /\w*/)[0]; } - let range = selection.getRangeAt(0); if (util.computedStyle(range.startContainer).whiteSpace == "pre" && util.computedStyle(range.endContainer).whiteSpace == "pre") return String(range);