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