Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: Source/core/editing/VisibleSelection.cpp

Issue 988023005: Implementing directional selection strategy in Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Putting GranularityStrategy into separate files. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/VisibleSelection.cpp
diff --git a/Source/core/editing/VisibleSelection.cpp b/Source/core/editing/VisibleSelection.cpp
index a490dbbd042cb4b9b481e79d4f207a8f97a3de04..0616d0949a50a54d5b579eaa6c59736f86053b05 100644
--- a/Source/core/editing/VisibleSelection.cpp
+++ b/Source/core/editing/VisibleSelection.cpp
@@ -30,7 +30,6 @@
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/Range.h"
-#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
#include "core/editing/iterators/CharacterIterator.h"
#include "core/layout/LayoutObject.h"
@@ -350,7 +349,7 @@ void VisibleSelection::setBaseAndExtentToDeepEquivalents()
m_baseIsFirst = comparePositions(m_base, m_extent) <= 0;
}
-void VisibleSelection::setStartRespectingGranularity(TextGranularity granularity)
+void VisibleSelection::setStartRespectingGranularity(TextGranularity granularity, EWordSide wordSide)
{
m_start = m_baseIsFirst ? m_base : m_extent;
@@ -359,13 +358,14 @@ void VisibleSelection::setStartRespectingGranularity(TextGranularity granularity
// Don't do any expansion.
break;
case WordGranularity: {
- // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
+ // General case: Select the word the caret is positioned inside of.
+ // If the caret is on the word boundary, select the word according to |wordSide|.
// Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
// the document, select that last word (LeftWordIfOnBoundary).
// Edge case: If the caret is after the last word in a paragraph, select from the the end of the
// last word to the line break (also RightWordIfOnBoundary);
VisiblePosition visibleStart = VisiblePosition(m_start, m_affinity);
- EWordSide side = RightWordIfOnBoundary;
+ EWordSide side = wordSide;
if (isEndOfEditableOrNonEditableContent(visibleStart) || (isEndOfLine(visibleStart) && !isStartOfLine(visibleStart) && !isEndOfParagraph(visibleStart)))
side = LeftWordIfOnBoundary;
m_start = startOfWord(visibleStart, side).deepEquivalent();
@@ -405,7 +405,7 @@ void VisibleSelection::setStartRespectingGranularity(TextGranularity granularity
m_start = m_end;
}
-void VisibleSelection::setEndRespectingGranularity(TextGranularity granularity)
+void VisibleSelection::setEndRespectingGranularity(TextGranularity granularity, EWordSide wordSide)
{
m_end = m_baseIsFirst ? m_extent : m_base;
@@ -414,13 +414,14 @@ void VisibleSelection::setEndRespectingGranularity(TextGranularity granularity)
// Don't do any expansion.
break;
case WordGranularity: {
- // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
+ // General case: Select the word the caret is positioned inside of.
+ // If the caret is on the word boundary, select the word according to |wordSide|.
// Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
// the document, select that last word (LeftWordIfOnBoundary).
// Edge case: If the caret is after the last word in a paragraph, select from the the end of the
// last word to the line break (also RightWordIfOnBoundary);
VisiblePosition originalEnd(m_end, m_affinity);
- EWordSide side = RightWordIfOnBoundary;
+ EWordSide side = wordSide;
if (isEndOfEditableOrNonEditableContent(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
side = LeftWordIfOnBoundary;

Powered by Google App Engine
This is Rietveld 408576698