Title: [137931] trunk/Source/WebKit/blackberry
- Revision
- 137931
- Author
- [email protected]
- Date
- 2012-12-17 12:30:03 -0800 (Mon, 17 Dec 2012)
Log Message
[BlackBerry] Improve DOMSupport visibleSelectionForClosestActualWordStart for content editable.
https://bugs.webkit.org/show_bug.cgi?id=105198
Reviewed by Rob Buis.
PR 258038.
Improve closest word matching by giving preference to the left when
distances are equal.
Also enforce container matching to avoid selecting the paragraph
marker if a CE div is followed immediately by a CE paragraph.
Minor refactor - don't calculate the distance if the selection
isn't on a word.
Reviewed Internally by Gen Mak and Nima Ghanavatian.
* WebKitSupport/DOMSupport.cpp:
(BlackBerry::WebKit::DOMSupport::visibleSelectionForClosestActualWordStart):
Modified Paths
Diff
Modified: trunk/Source/WebKit/blackberry/ChangeLog (137930 => 137931)
--- trunk/Source/WebKit/blackberry/ChangeLog 2012-12-17 20:07:57 UTC (rev 137930)
+++ trunk/Source/WebKit/blackberry/ChangeLog 2012-12-17 20:30:03 UTC (rev 137931)
@@ -1,3 +1,26 @@
+2012-12-17 Mike Fenton <[email protected]>
+
+ [BlackBerry] Improve DOMSupport visibleSelectionForClosestActualWordStart for content editable.
+ https://bugs.webkit.org/show_bug.cgi?id=105198
+
+ Reviewed by Rob Buis.
+
+ PR 258038.
+
+ Improve closest word matching by giving preference to the left when
+ distances are equal.
+
+ Also enforce container matching to avoid selecting the paragraph
+ marker if a CE div is followed immediately by a CE paragraph.
+
+ Minor refactor - don't calculate the distance if the selection
+ isn't on a word.
+
+ Reviewed Internally by Gen Mak and Nima Ghanavatian.
+
+ * WebKitSupport/DOMSupport.cpp:
+ (BlackBerry::WebKit::DOMSupport::visibleSelectionForClosestActualWordStart):
+
2012-12-17 Jakob Petsovits <[email protected]>
[BlackBerry] Clean up log output in WebKit/blackberry.
Modified: trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp (137930 => 137931)
--- trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp 2012-12-17 20:07:57 UTC (rev 137930)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/DOMSupport.cpp 2012-12-17 20:30:03 UTC (rev 137931)
@@ -467,24 +467,30 @@
// it selects the paragraph marker. As well, if the position is at the end of a word, it will select
// only the space between words. We want to select an actual word so we move the selection to
// the start of the leftmost word if the character after the selection point is whitespace.
+
if (selection.selectionType() != VisibleSelection::RangeSelection) {
+ int leftDistance = 0;
+ int rightDistance = 0;
+
VisibleSelection leftSelection(previousWordPosition(selection.start()));
- bool leftSelectionIsOnWord = !isWhitespace(leftSelection.visibleStart().characterAfter());
+ bool leftSelectionIsOnWord = !isWhitespace(leftSelection.visibleStart().characterAfter()) && leftSelection.start().containerNode() == selection.start().containerNode();
+ if (leftSelectionIsOnWord) {
+ VisibleSelection rangeSelection(endOfWord(leftSelection.start()), selection.visibleStart());
+ leftDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
+ }
- VisibleSelection rangeSelection(endOfWord(leftSelection.start()), selection.visibleStart());
- int leftDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
-
VisibleSelection rightSelection = previousWordPosition(nextWordPosition(selection.start()));
- bool rightSelectionIsOnWord = !isWhitespace(rightSelection.visibleStart().characterAfter());
+ bool rightSelectionIsOnWord = !isWhitespace(rightSelection.visibleStart().characterAfter()) && rightSelection.start().containerNode() == selection.start().containerNode();
+ if (rightSelectionIsOnWord) {
+ VisibleSelection rangeSelection = VisibleSelection(rightSelection.visibleStart(), selection.visibleStart());
+ rightDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
+ }
- rangeSelection = VisibleSelection(rightSelection.visibleStart(), selection.visibleStart());
- int rightDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
-
// Make sure we found an actual word. If not, return the original selection.
if (!leftSelectionIsOnWord && !rightSelectionIsOnWord)
return selection;
- if (!rightSelectionIsOnWord || (leftSelectionIsOnWord && leftDistance < rightDistance)) {
+ if (!rightSelectionIsOnWord || (leftSelectionIsOnWord && leftDistance <= rightDistance)) {
// Left is closer or right is invalid.
return leftSelection;
}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes