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

Unified Diff: third_party/WebKit/Source/core/editing/Editor.cpp

Issue 2618613004: Insert a line break when space is inserted at the top of wrapped lines (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/Editor.cpp
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp
index 79d38cb36fe377f0d516a531a5b4fb95d4f2a6f6..1d6608c3f66698dc41aac0aa7e343a6e9ed1e501 100644
--- a/third_party/WebKit/Source/core/editing/Editor.cpp
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp
@@ -201,6 +201,18 @@ EditorClient& Editor::client() const {
return emptyEditorClient();
}
+static bool isCaretAtTopOfWrappedLine(FrameSelection& selection) {
+ if (!selection.isCaret())
+ return false;
+ if (selection.affinity() != TextAffinity::Downstream)
+ return false;
+ // Enable this operation for plaintext only for now.
+ if (selection.isContentRichlyEditable())
+ return false;
+ // TODO(kojii): how to know if a Position is at the top of wrapped line?
yosin_UTC9 2017/01/05 08:36:50 I think "start" is better than "top". We can chec
+ return true;
+}
+
bool Editor::handleTextEvent(TextEvent* event) {
// Default event handling for Drag and Drop will be handled by DragController
// so we leave the event for it.
@@ -237,6 +249,9 @@ bool Editor::handleTextEvent(TextEvent* event) {
return insertParagraphSeparator();
}
+ if (data == " " && isCaretAtTopOfWrappedLine(frame().selection()))
+ insertLineBreak();
+
return insertTextWithoutSendingTextEvent(EditCommandSource::kMenuOrKeyBinding,
data, false, event);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698