mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 15:57:58 +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:
@@ -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);
|
||||
//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);
|
||||
|
||||
Reference in New Issue
Block a user