1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 18:57:59 +01:00

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.
This commit is contained in:
Conrad Irwin
2009-04-05 12:38:52 +01:00
parent 77b11adbdb
commit 73e35da652

View File

@@ -998,17 +998,20 @@ function Buffer() //{{{
getCurrentWord: function () getCurrentWord: function ()
{ {
let selection = window.content.getSelection(); let selection = window.content.getSelection();
let range = selection.getRangeAt(0);
if (selection.isCollapsed) if (selection.isCollapsed)
{ {
let selController = this.selectionController; let selController = this.selectionController;
let caretmode = selController.getCaretEnabled(); let caretmode = selController.getCaretEnabled();
selController.setCaretEnabled(true); 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.wordMove(true, true);
selController.setCaretEnabled(caretmode); selController.setCaretEnabled(caretmode);
return String.match(selection, /\w*/)[0]; return String.match(selection, /\w*/)[0];
} }
let range = selection.getRangeAt(0);
if (util.computedStyle(range.startContainer).whiteSpace == "pre" if (util.computedStyle(range.startContainer).whiteSpace == "pre"
&& util.computedStyle(range.endContainer).whiteSpace == "pre") && util.computedStyle(range.endContainer).whiteSpace == "pre")
return String(range); return String(range);